From 815d8997ae55a8ae6768f81fc5156b12b46d560d Mon Sep 17 00:00:00 2001
From: Jan-Tarek Butt <buttjantarek@googlemail.com>
Date: Fri, 8 May 2015 17:17:16 +0200
Subject: [PATCH] add vpn check and set countdown

---
 .../lib/ffnw/autoupdater-mod/autoupdater      | 30 ++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/autoupdater-mod/files/lib/ffnw/autoupdater-mod/autoupdater b/autoupdater-mod/files/lib/ffnw/autoupdater-mod/autoupdater
index d54e94a..6e31dc2 100755
--- a/autoupdater-mod/files/lib/ffnw/autoupdater-mod/autoupdater
+++ b/autoupdater-mod/files/lib/ffnw/autoupdater-mod/autoupdater
@@ -9,6 +9,7 @@ local util = require('luci.util')
 local autoupdater_util = require('autoupdater.util')
 local autoupdater_version = require('autoupdater.version')
 local pidPath="/var/run/autoupdater.pid"
+local direct_vpn= false
 
 if io.open(pidPath, "r") ~=nil then
 	io.stderr:write("The autoupdater is still running.\n")
@@ -25,6 +26,23 @@ function pid_clean()
 	return 0
 end
 
+function wait(seconds)
+	local start = os.time()
+	repeat until os.time() > start + seconds
+end
+
+local foreach_count=1
+for originator in io.popen(string.format("cat /sys/kernel/debug/batman_adv/bat0/originators"), 'r'):lines() do
+	if foreach_count > 2  then
+		local vpn=0
+		vpn = string.find(originator, "vpn", vpn+1)
+		if vpn ~= nil then
+			direct_vpn= true
+		end
+	end
+	foreach_count = foreach_count + 1
+end
+
 if not platform_info.get_image_name() then
   io.stderr:write("The autoupdater doesn't support this hardware model.\n")
   pid_clean()
@@ -240,13 +258,17 @@ local function autoupdate(mirror)
 
   io.stderr:write('New version available.\n')
 
+--  if not force and math.random() >= get_probability(manifest.date, manifest.priority) then
+--    io.stderr:write('No autoupdate this time. Use -f to override.\n')
+--    return true
+--  end
 
-  if not force and math.random() >= get_probability(manifest.date, manifest.priority) then
-    io.stderr:write('No autoupdate this time. Use -f to override.\n')
-    return true
+  if direct_vpn == true then
+	wait(28800) -- Wait for 8h
+  else
+	wait(14400) -- Wait for 4h
   end
 
-
   os.execute('sync; sysctl -w vm.drop_caches=3')
   collectgarbage()
 
-- 
GitLab