Merge pull request #147 from dadav/fix/autobackup

Fix split-bug in script
This commit is contained in:
evilsocket 2019-10-05 18:35:12 +02:00 committed by GitHub
commit ed9cbfec8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -15,7 +15,7 @@ main:
files:
- /root/brain.nn
- /root/brain.json
- /root/custom.yaml
- /root/custom.yml
- /root/handshakes
- /etc/ssh
- /etc/hostname
@ -24,7 +24,7 @@ main:
- /var/log/pwnagotchi.log
commands:
- 'tar czf /tmp/backup.tar.gz {files}'
- 'scp /tmp/backup.tar.gz pwnagotchi@10.0.0.1:/home/pwnagotchi/backups/backup-$(date).tar.gz'
- 'scp /tmp/backup.tar.gz pwnagotchi@10.0.0.1:/home/pwnagotchi/backups/backup-$(date +%s).tar.gz'
gps:
enabled: false
twitter:

View File

@ -30,6 +30,7 @@ def on_loaded():
return
READY = True
logging.info("AUTO-BACKUP: Successfuly loaded.")
def on_internet_available(display, config, log):
@ -41,11 +42,17 @@ def on_internet_available(display, config, log):
files_to_backup = " ".join(OPTIONS['files'])
try:
logging.info("AUTO-BACKUP: Backing up ...")
display.set('status', 'Backing up ...')
display.update()
for cmd in OPTIONS['commands']:
subprocess.call(cmd.format(files=files_to_backup).split(), stdout=open(os.devnull, 'wb'))
logging.info(f"AUTO-BACKUP: Running {cmd.format(files=files_to_backup)}")
process = subprocess.Popen(cmd.format(files=files_to_backup), shell=True, stdin=None,
stdout=open("/dev/null", "w"), stderr=None, executable="/bin/bash")
process.wait()
if process.returncode > 0:
raise OSError(f"Command failed (rc: {process.returncode})")
logging.info("AUTO-BACKUP: backup done")
STATUS.update()