Skip to content
Snippets Groups Projects
Select Git revision
  • 4249d65af73ee9228d827af913b7caf2aac00809
  • experimental
  • master
  • v2021.1.2-ffs
  • v2021.1.1-ffs
  • nrb/gluon-master-cpe510
  • v2021.1-ffs
  • v2020.2.3-ffs
  • nrbffs/fastd-remove-delay
  • v2020.2.2-ffs
  • v2020.2.1-ffs
  • v2020.2-ffs
  • v2020.2.x
  • v2020.1.3-ffs
  • v2020.1.1-ffs
  • v2020.1-ffs
  • v2019.1.2-ffs
  • v2019.1.1-ffs
  • nrb/test-radv-filter
  • v2019.1-ffs
  • nrbffs/netgear-ex6120
  • v2021.1.2-ffs0.2
  • v2021.1.2-ffs0.1
  • v2021.1.1-ffs0.4
  • v2021.1.1-ffs0.3
  • v2021.1.1-ffs0.2
  • v2021.1.1-ffs0.1
  • v2021.1-ffs0.1
  • v2020.2.3-ffs0.3
  • v2020.2.3-ffs0.2
  • v2020.2.3-ffs0.1
  • v2020.2.2-ffs0.1
  • v2020.2.1-ffs0.1
  • v2020.2-ffs0.1
  • v2020.2
  • v2020.2.x-ffs0.1
  • v2020.1.3-ffs0.1
  • v2020.1.1-ffs0.1
  • v2020.1-ffs0.1
  • v2019.1.2-ffs0.1
  • v2019.1.1-ffs0.1
41 results

gluon-switch-domain

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    gluon-switch-domain 1.66 KiB
    #!/usr/bin/lua
    
    local uci = require('simple-uci').cursor()
    local unistd = require 'posix.unistd'
    local util = require 'gluon.util'
    local site = require 'gluon.site'
    
    -- Returns true if node was offline long enough to perform domain switch
    local function switch_after_min_reached()
    	if not unistd.access("/tmp/gluon_offline") then
    		return false
    	end
    
    	local switch_after_sec = site.domain_switch.switch_after_offline_mins() * 60
    
    	local current_uptime = util.get_uptime()
    	if current_uptime == nil then
    		return false
    	end
    
    	local f = util.readfile("/tmp/gluon_offline")
    	if f == nil then
    		return false
    	end
    	local offline_since = tonumber(f)
    
    	local offline_time_sec = current_uptime - offline_since
    
    	if offline_time_sec > switch_after_sec then
    		return true
    	end
    	return false
    end
    
    -- Returns true in case switch time has passed
    local function switch_time_passed()
    	local current_time = os.time()
    	local switch_time = site.domain_switch.switch_time()
    
    	return switch_time < current_time
    end
    
    if site.domain_switch() == nil then
    	-- Switch not applicable for current domain
    	print("No domain switch defined for the current domain.")
    	os.exit(0)
    end
    
    local current_domain = uci:get("gluon", "core", "domain")
    local target_domain = site.domain_switch.target_domain()
    
    if target_domain == current_domain then
    	-- Current and target domain are equal
    	print("Domain '" .. target_domain .. "' equals current domain.")
    	os.exit(1)
    end
    
    if not switch_after_min_reached() and not switch_time_passed() then
    	-- Neither switch-time passed nor switch_after_min reached
    	os.exit(0)
    end
    
    uci:set("gluon", "core", "domain", target_domain)
    uci:commit("gluon")
    
    os.execute("gluon-reconfigure")
    os.execute("reboot")