From 33d0ce8627f0212fbf2a15944b6a57561d889301 Mon Sep 17 00:00:00 2001 From: Dmitri Popov Date: Thu, 22 Mar 2018 11:25:58 +0100 Subject: [PATCH] Add templating. Free disk space --- install-little-backup-box.sh | 6 +-- rc.py | 73 ------------------------------------ rc/rc.py | 32 ++++++++++++++++ rc/rc.tpl | 50 ++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 76 deletions(-) delete mode 100755 rc.py create mode 100755 rc/rc.py create mode 100644 rc/rc.tpl diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh index 960f914..1350fcf 100755 --- a/install-little-backup-box.sh +++ b/install-little-backup-box.sh @@ -51,17 +51,17 @@ case $CHOICE in 1) crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc.py"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; 2) crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc.py"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; 3) crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/card-backup.sh"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/pi/little-backup-box/camera-backup.sh"; } | crontab - crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/rc.py"; } | crontab + crontab -l | { cat; echo "@reboot sudo /home/pi/little-backup-box/rc/rc.py"; } | crontab ;; esac diff --git a/rc.py b/rc.py deleted file mode 100755 index 7c7152c..0000000 --- a/rc.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -from bottle import post, route, request, run -import os - -@route('/') -@route('/', method='POST') -def remote_control(): - if (request.POST.get("cardbackup")): - os.system("sudo /home/pi/little-backup-box/card-backup.sh") - if (request.POST.get("camerabackup")): - os.system("sudo /home/pi/little-backup-box/camera-backup.sh") - if (request.POST.get("shutdown")): - os.system("sudo shutdown -h now") - return """ - Little Backup Box - -
-

-

Back up a storage card connected via a card reader

-

-

Transfer files directly from the connected camera

-

-

Shut down the Little Backup Box

- - - """ -run(host="0.0.0.0", port=8080, debug=True, reloader=True) diff --git a/rc/rc.py b/rc/rc.py new file mode 100755 index 0000000..245906a --- /dev/null +++ b/rc/rc.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from bottle import post, route, request, template, run +import os + +@route('/') +@route('/', method='POST') +def remote_control(): + #dh = os.system("df -h | grep '/dev/sda' | awk '{print $4}'") + st = os.statvfs("/home/dmpop") + free = "%.2f" % float((st.f_bavail * st.f_frsize)/1.073741824e9) + if (request.POST.get("cardbackup")): + os.system("sudo /home/pi/little-backup-box/card-backup.sh") + if (request.POST.get("camerabackup")): + os.system("sudo /home/pi/little-backup-box/camera-backup.sh") + if (request.POST.get("shutdown")): + os.system("sudo shutdown -h now") + return template('rc.tpl', freespace=free) +run(host="0.0.0.0", port=8080, debug=True, reloader=True) diff --git a/rc/rc.tpl b/rc/rc.tpl new file mode 100644 index 0000000..475d228 --- /dev/null +++ b/rc/rc.tpl @@ -0,0 +1,50 @@ + + + + + +Little Backup Box + +
+
+

Free disk space: {{freespace}} GB

+

+

Back up a storage card connected via a card reader

+

+

Transfer files directly from the connected camera

+

+

Shut down the Little Backup Box

+
+