Ver código fonte

added udpates

Tobias Simetsreiter 4 anos atrás
pai
commit
b34ce8e33b
4 arquivos alterados com 44 adições e 22 exclusões
  1. 1 0
      src/autostart.cron
  2. 41 1
      src/bootstrap_captive/install.py
  3. 1 21
      src/http/portal.js
  4. 1 0
      src/main.py

+ 1 - 0
src/autostart.cron

@@ -1,2 +1,3 @@
 
 @reboot root /usr/local/bin/bootstrap_captive autostart
+@daily root /usr/local/bin/bootstrap_captive update

+ 41 - 1
src/bootstrap_captive/install.py

@@ -1,6 +1,46 @@
 
 def com_update(args):
-    pass
+    from urllib.request import urlopen
+    import shutil
+    import tempfile
+    import os
+    import time
+    from subprocess import run
+    update_url = "https://tsimnet.eu/releases/bootstrap_captive/build/bootstrap_captive"
+    checksum_url = update_url + ".sha256"
+    checksum_path = os.path.join(args.install_dir, "checksum.sha256")
+    tries = 0
+    checkfile = b""
+    while (args.tries <= 0) or args.tries > tries:
+        try:
+            print("Trying to connect...", checksum_url)
+            with urlopen(checksum_url) as res:
+                checksum = res.read()
+            print("Checksum:", checksum.decode())
+            if os.path.isfile(checksum_path):
+                with open(checksum_path, "rb") as fd:
+                    checkfile = fd.read()
+            print("Checksum File:", checkfile.decode())
+            if checkfile != checksum:
+                print("Downloading Update...", update_url)
+                with tempfile.NamedTemporaryFile(delete=False) as tmp:
+                    with urlopen(update_url) as res:
+                        shutil.copyfileobj(res, tmp)
+                run(["chmod", "+x", tmp.name], check=True)
+                print("Installing Update from", tmp.name)
+                run([tmp.name, "install"], check=True)
+                run(["rm", tmp.name])
+                with open(checksum_path, "wb") as fd:
+                    fd.write(checksum)
+                return 0
+            else:
+                print("Version is current.")
+                return 0
+        except Exception as ex:
+            print("Update Error:", ex)
+        tries += 1
+        print("Sleeping 10s....",tries)
+        time.sleep(10)
 
 def com_unpack(args):
     import os

+ 1 - 21
src/http/portal.js

@@ -64,16 +64,6 @@ portal = new function(){
     function getId(id){
         return document.getElementById(id);
     }
-    function validate_input(){
-        if (
-            getId("input_ssid").value == "" ||
-            getId("input_pw").value == ""
-        ){
-            getId("save_button").disabled = true;
-        } else {
-            getId("save_button").disabled = false;
-        }
-    }
     window.addEventListener("load",async ()=>{
         const resp_form = await postData("", {
             "get_form":true
@@ -105,6 +95,7 @@ portal = new function(){
                         };
                         data.submit_form["name"] = full_form.name;
                         var resp = await postData("", data);
+                        console.log(resp);
                         if (resp.ok){
                             getId("error_box").innerText = resp.out;
                         } else {
@@ -134,16 +125,5 @@ portal = new function(){
             form_collapse.appendChild(form_dom);
             getId("form_div").appendChild(form_collapse);
         });
-        /*
-        getId("input_ssid").addEventListener("input",validate_input)
-        getId("input_pw").addEventListener("input",validate_input);
-        validate_input();
-        const resp = await postData("", {
-            "get_data":true
-        })
-        $('form').jsonForm(resp);
-        getId("input_ssid").value = resp["ssid"];
-        getId("input_pw").value   = resp["pw"];
-        */
     });
 }();

+ 1 - 0
src/main.py

@@ -39,6 +39,7 @@ def parser():
 
     p_update = sub.add_parser("update")
     p_update.set_defaults(func=com_update)
+    p_update.add_argument("-t", "--tries", type=int,  default=10)
     p_update.add_argument("-i", "--install_dir", default="/opt/eu.tsimnet.git/dasimmet/bootstrap_captive")
 
     p_start = sub.add_parser("start")