From 8b1f055cd1568fef7bc2eb46152af6001c73d401 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 28 Apr 2023 02:26:16 -0700 Subject: [PATCH] auto update --- examples/install.sh | 4 ++-- lib/axe.js | 42 +--------------------------------------- lib/service.js | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 lib/service.js diff --git a/examples/install.sh b/examples/install.sh index 2dc44bef..85c7524e 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -36,13 +36,13 @@ git clone https://github.com/isaacs/nave.git mkdir node_modules git clone https://github.com/amark/gun.git cd gun +git checkout . git pull git checkout master git checkout $VERSION git pull npm install . -service relay stop cp ./examples/relay.service /lib/systemd/system/relay.service echo $PWD >> /lib/systemd/system/relay.service echo "fs.file-max = 999999" >> /etc/sysctl.conf @@ -50,4 +50,4 @@ ulimit -u unlimited sysctl -p /etc/sysctl.conf systemctl daemon-reload systemctl enable relay -service relay start \ No newline at end of file +systemctl restart relay \ No newline at end of file diff --git a/lib/axe.js b/lib/axe.js index 2456460e..a6869dbc 100644 --- a/lib/axe.js +++ b/lib/axe.js @@ -205,47 +205,7 @@ function start(root){ },1000); }()); - ;(function(){ - var cmd = {}; - mesh.hear['service'] = function(msg, peer){ - if(!require('fs').existsSync('/lib/systemd/system/relay.service')){ - mesh.say({dam: '!', err: "Not serviced."}); - return; - } - try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } - } - cmd.https = function(msg, peer){ var run, log; - if(!(run = require('child_process').exec)){ return } - if(!msg.email || !msg.domain){ - mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); - return; - } - if(require('fs').existsSync(require('os').homedir()+'/cert.pem')){ - mesh.say({dam: '!', err: 'Cert already exists.'}); - return; - } - var path = require('path').resolve(__dirname, '../examples'); - require('fs').writeFileSync(path+'/../email', msg.email); - run("bash "+path+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': path, 'DOMAIN': msg.domain}}, function(e, out, err){ - log = "|"+e+"|"+out+"|"+err; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); - } - cmd.update = function(msg, peer){ var run, log, pass; - try{ pass = (''+require('fs').readFileSync(require('os').homedir()+'/pass')).trim() }catch(e){} - if(!pass || (msg.pass||'').trim() != pass){ return } - if(!(run = require('child_process').exec)){ return } - var path = require('path').resolve(__dirname, '../examples'); - run("bash "+path+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ - log = e+"|"+out+"|"+err; - mesh.say({dam: '!', log: ''+log}, peer); - setTimeout(function(){ process.exit() },999); - }); - } - - cmd.any = function(){}; - }()); + setTimeout(function(){ require('./service')(root) },9); ;(function(){ // THIS IS THE MOB MODULE; //return; // WORK IN PROGRESS, TEST FINALIZED, NEED TO MAKE STABLE. diff --git a/lib/service.js b/lib/service.js new file mode 100644 index 00000000..17e0db21 --- /dev/null +++ b/lib/service.js @@ -0,0 +1,47 @@ +module.exports = function(root){ + var mesh = root.opt.mesh, cmd = {}, run = require('child_process').exec, fs = require('fs'), home = require('os').homedir(), examp = require('path').resolve(__dirname, '../examples'); + mesh.hear['service'] = function(msg, peer){ + if(!fs.existsSync('/lib/systemd/system/relay.service')){ + mesh.say({dam: '!', err: "Not serviced."}); + return; + } + try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } + } + cmd.https = function(msg, peer){ var run, log; + if(!msg.email || !msg.domain){ + mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); + return; + } + if(fs.existsSync(home+'/cert.pem')){ + mesh.say({dam: '!', err: 'Cert already exists.'}); + return; + } + fs.writeFile(examp+'/../email', msg.email, function(){}); + run("bash "+examp+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': examp, 'DOMAIN': msg.domain}}, function(e, out, err){ + log = "|"+e+"|"+out+"|"+err; + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); + } + cmd.update = function(msg, peer){ var run, log, pass; + try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} + if(!pass || (msg.pass||'').trim() != pass){ return } + fs.writeFile(examp+'/../updated', +new Date+'', function(){}); + run("bash "+examp+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ + log = e+"|"+out+"|"+err; + mesh.say({dam: '!', log: ''+log}, peer); + setTimeout(function(){ process.exit() },999); + }); + } + ;(function update(){ var last; + if(!fs.existsSync(home+'/cert.pem')){ return } + setTimeout(update, 1000*60*60*24); + last = root.stats.stay.updated || 0; + if(+new Date - last < 1000*60*60*24*15){ return } + root.stats.stay.updated = +new Date; + run("bash "+examp+"/install.sh", {}, function(){}); + }()); + + cmd.any = function(){}; + +}; \ No newline at end of file