gluon-hoodselector: fix language syntax and use autoupdate lock mechanism.
This commit is contained in:
parent
3190011e27
commit
64b64cb415
@ -161,7 +161,7 @@ function M.set_hoodconfig(geoHood)
|
|||||||
if uci:get('gluon', 'core', 'domain') ~= geoHood.domain_code then
|
if uci:get('gluon', 'core', 'domain') ~= geoHood.domain_code then
|
||||||
uci:set('gluon', 'core', 'domain', geoHood.domain_code)
|
uci:set('gluon', 'core', 'domain', geoHood.domain_code)
|
||||||
uci:save('gluon')
|
uci:save('gluon')
|
||||||
uci:commit('gluon') -- necessary?
|
uci:commit('gluon')
|
||||||
os.execute('gluon-reconfigure')
|
os.execute('gluon-reconfigure')
|
||||||
io.stdout:write("Set hood \""..geoHood.domain.domain_names[geoHood.domain_code].."\"\n")
|
io.stdout:write("Set hood \""..geoHood.domain.domain_names[geoHood.domain_code].."\"\n")
|
||||||
return true
|
return true
|
||||||
|
@ -1,27 +1,19 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
-- PID file to ensure the hoodselector isn't running parallel
|
local nixio = require('nixio')
|
||||||
local pidPath="/var/run/hoodselector.pid"
|
|
||||||
|
|
||||||
local uci = require('simple-uci').cursor()
|
local uci = require('simple-uci').cursor()
|
||||||
local hoodutil = require("hoodselector.util")
|
local hoodutil = require("hoodselector.util")
|
||||||
|
|
||||||
if io.open(pidPath, "r") ~=nil then
|
-- PID file to ensure the hoodselector isn't running parallel
|
||||||
hoodutil.log("The hoodselector is still running.")
|
local lockfile = '/var/lock/hoodselector.lock'
|
||||||
os.exit(1)
|
local lockfd = nixio.open(lockfile, 'w', 'rw-------')
|
||||||
else
|
|
||||||
if io.open(pidPath, "w") ==nil then
|
|
||||||
hoodutil.log("Can`t create pid file on "..pidPath)
|
|
||||||
os.exit(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Program terminating function including removing of PID file
|
if not lockfd:lock('tlock') then
|
||||||
local function exit(exc)
|
io.stderr:write(string.format(
|
||||||
if io.open(pidPath, "r") ~=nil then
|
"Unable to lock file %s. Make sure there is no other instance of the hoodselector running.\n",
|
||||||
os.remove(pidPath)
|
lockfile
|
||||||
end
|
))
|
||||||
os.exit(tonumber(exc))
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- initialization done
|
-- initialization done
|
||||||
@ -35,7 +27,7 @@ local function get_mesh_vpn_interface()
|
|||||||
table.insert(ret,vpnifac)
|
table.insert(ret,vpnifac)
|
||||||
else
|
else
|
||||||
hoodutil.log("fastd uci config broken! abort...")
|
hoodutil.log("fastd uci config broken! abort...")
|
||||||
exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if hoodutil.tunneldigger_installed() then
|
if hoodutil.tunneldigger_installed() then
|
||||||
@ -44,7 +36,7 @@ local function get_mesh_vpn_interface()
|
|||||||
table.insert(ret,vpnifac)
|
table.insert(ret,vpnifac)
|
||||||
else
|
else
|
||||||
hoodutil.log("tunneldigger uci config broken! abort...")
|
hoodutil.log("tunneldigger uci config broken! abort...")
|
||||||
exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
@ -54,11 +46,11 @@ end
|
|||||||
-- read hoodfile...
|
-- read hoodfile...
|
||||||
local jhood = hoodutil.get_domains()
|
local jhood = hoodutil.get_domains()
|
||||||
|
|
||||||
-- get defaul hood
|
-- get default hood
|
||||||
local defaultHood = hoodutil.getDefaultHood(jhood)
|
local defaultHood = hoodutil.getDefaultHood(jhood)
|
||||||
|
|
||||||
-- VPN MODE
|
-- VPN MODE
|
||||||
-- If we have a VPN connection then we will try to get the routers location and
|
-- If we have a VPN connection we will try to get the router's location and
|
||||||
-- select the hood coresponding to our location.
|
-- select the hood coresponding to our location.
|
||||||
-- If no hood for the location has been defined, we will select
|
-- If no hood for the location has been defined, we will select
|
||||||
-- the default hood.
|
-- the default hood.
|
||||||
@ -74,14 +66,14 @@ if hoodutil.directVPN(get_mesh_vpn_interface()) then
|
|||||||
hoodutil.restart_services() -- temporary solution
|
hoodutil.restart_services() -- temporary solution
|
||||||
io.stdout:write('Hood set by VPN mode.\n')
|
io.stdout:write('Hood set by VPN mode.\n')
|
||||||
end
|
end
|
||||||
exit(0)
|
os.exit(0)
|
||||||
end
|
end
|
||||||
io.stdout:write('No hood has been defined for the current position.\n')
|
io.stdout:write('No hood has been defined for the current position.\n')
|
||||||
if hoodutil.set_hoodconfig(defaultHood) then
|
if hoodutil.set_hoodconfig(defaultHood) then
|
||||||
hoodutil.restart_services() -- TMP solution
|
hoodutil.restart_services() -- TMP solution
|
||||||
io.stdout:write('Hood set by VPN mode.\n')
|
io.stdout:write('Hood set by VPN mode.\n')
|
||||||
end
|
end
|
||||||
exit(0)
|
os.exit(0)
|
||||||
else
|
else
|
||||||
-- The hoodselector should continue with the next states because there can be other
|
-- The hoodselector should continue with the next states because there can be other
|
||||||
-- VPN routers in the local mesh network which provide a position and therefore
|
-- VPN routers in the local mesh network which provide a position and therefore
|
||||||
@ -92,4 +84,4 @@ else
|
|||||||
io.stdout:write('No VPN connection found\n')
|
io.stdout:write('No VPN connection found\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
exit(0)
|
os.exit(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user