Skip to content
Snippets Groups Projects
Select Git revision
  • a4d5955c757de409241aa1a041a0fe1d4dcebc25
  • experimental default protected
  • v2023.2.5-ffs
  • nrb/ex400-remove-wps
  • nrb/airmax-test
  • v2023.2.4-ffs
  • nrb/ar9344-reset-sequence
  • autinerd/experimental-openwrt-24.10
  • v2023.2.3-ffs
  • v2023.2.2-ffs
  • v2023.2-ffs
  • v2023.1-ffs
  • v2022.1.4-ffs
  • feature/addMikrotikwAP
  • v2022.1.3-ffs
  • v2021.1.2-ffs
  • v2022.1.1-ffs
  • master protected
  • v2021.1.1-ffs
  • nrb/gluon-master-cpe510
  • v2021.1-ffs
  • experimental-2025-07-12
  • experimental-2025-07-12-base
  • experimental-2025-07-04
  • experimental-2025-07-04-base
  • experimental-2025-07-01
  • experimental-2025-07-01-base
  • experimental-2025-06-25
  • experimental-2025-06-25-base
  • experimental-2025-06-24
  • experimental-2025-06-24-base
  • experimental-2025-06-22
  • experimental-2025-06-22-base
  • v2023.2.5-ffs0.1
  • experimental-2025-06-08
  • experimental-2025-06-08-base
  • experimental-2025-06-06
  • experimental-2025-06-06-base
  • experimental-2025-05-27
  • experimental-2025-05-27-base
  • experimental-2025-05-18
41 results

hoodselector

Blame
  • 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()))