Skip to content
Snippets Groups Projects
Select Git revision
  • fdf823a3a2264cdfcb9057fe18f8ed4905209b68
  • v2018.2.x default protected
  • 0x4A6F-rpi4
  • 0x4A6F-master
  • master
  • v2018.2.2-ffs
  • v2016.2.4-batmanbug
  • radv-filterd
  • v2016.2.x
  • hoodselector
  • v2016.1.x
  • babel
  • v2015.1.x
  • 2014.4.x
  • 2014.3.x
  • v2018.2.2-ffs0.1
  • v2018.2.1-ffs0.1
  • v2018.2.1
  • v2018.2-ffs0.1
  • v2018.2
  • v2018.1.4
  • v2018.1.3
  • v2018.1.2
  • v2018.1.1
  • v2018.1
  • v2017.1.8
  • v2017.1.7
  • v2017.1.6
  • v2017.1.5
  • v2017.1.4
  • v2017.1.3
  • v2017.1.2
  • v2016.2.7
  • v2017.1.1
  • v2017.1
35 results

70gluon-status-page

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    hoodselector 1.72 KiB
    #!/usr/bin/lua
    
    local bit = require('bit32')
    local util = require ('gluon.util')
    local unistd = require('posix.unistd')
    local fcntl = require('posix.fcntl')
    local hoodutil = require('hoodselector.util')
    
    -- PID file to ensure the hoodselector isn't running parallel
    local lockfile = '/var/lock/hoodselector.lock'
    local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600
    
    if not lockfd then
    	util.log(err, true)
    	os.exit(1)
    end
    
    local ok, _ = fcntl.fcntl(lockfd, fcntl.F_SETLK, {
    	l_start = 0,
    	l_len = 0,
    	l_type = fcntl.F_WRLCK,
    	l_whence = unistd.SEEK_SET,
    })
    
    if not ok then
    	io.stderr:write(string.format(
    		"Unable to lock file %s. Make sure there is no other instance of the hoodselector running.\n",
    		lockfile
    	))
    	os.exit(1)
    end
    
    -- geolocation mode
    -- If we have a location we will try to select the domain corresponding to this location.
    -- If no domain for the location has been defined or if we can't determine the node's location,
    -- we will select the default domain as last fallback instance.
    local geo = hoodutil.get_geolocation()
    if geo.lat ~= nil and geo.lon ~= nil then
    	io.stdout:write('Position found. Enter "geolocation mode" ...\n')
    	local jdomains = hoodutil.get_domains()
    	local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo)
    	if geo_base_domain ~= nil then
    		if hoodutil.set_domain_config(geo_base_domain) then
    			util.log('Domain set by geolocation mode.', true)
    		end
    		return
    	end
    	io.stdout:write('No domain has been defined for the current position. Continue with default domain mode\n')
    else
    	io.stdout:write('No position found. Continue with default domain mode\n')
    end
    
    -- default domain mode
    hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains()))