From 8505a5246e9ac012f2bb4c1ba3e0ba718f8a1a3f Mon Sep 17 00:00:00 2001 From: Dmitri Popov Date: Mon, 11 Feb 2019 11:27:04 +0100 Subject: [PATCH] Switch to PHP --- install-little-backup-box.sh | 9 ++- rc/exit.tpl | 41 ------------ rc/rc.py | 43 ------------ rc/rc.tpl | 59 ----------------- {rc/static => scripts}/ichigo.svg | 0 scripts/index.php | 104 ++++++++++++++++++++++++++++++ scripts/{rc.sh => php.sh} | 6 +- 7 files changed, 111 insertions(+), 151 deletions(-) delete mode 100644 rc/exit.tpl delete mode 100755 rc/rc.py delete mode 100644 rc/rc.tpl rename {rc/static => scripts}/ichigo.svg (100%) create mode 100644 scripts/index.php rename scripts/{rc.sh => php.sh} (86%) mode change 100755 => 100644 diff --git a/install-little-backup-box.sh b/install-little-backup-box.sh index ae11a48..de512f7 100755 --- a/install-little-backup-box.sh +++ b/install-little-backup-box.sh @@ -16,8 +16,7 @@ sudo apt update sudo apt dist-upgrade -y sudo apt update -sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g gphoto2 libimage-exiftool-perl dialog python3-pip minidlna -y -sudo pip3 install bottle +sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g gphoto2 libimage-exiftool-perl dialog php7.1 minidlna -y echo "------------------------------------" echo "Creating the required directories..." @@ -70,17 +69,17 @@ case $CHOICE in 1) crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab - crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab + crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab ;; 2) crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab ;; 3) crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab - crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab + crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab ;; esac diff --git a/rc/exit.tpl b/rc/exit.tpl deleted file mode 100644 index be182f5..0000000 --- a/rc/exit.tpl +++ /dev/null @@ -1,41 +0,0 @@ - - - - -Little Backup Box - -
-
Command sent. You can close this page.
-
diff --git a/rc/rc.py b/rc/rc.py deleted file mode 100755 index 5b5e99a..0000000 --- a/rc/rc.py +++ /dev/null @@ -1,43 +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, template, static_file, run -import os, subprocess - -@route('/') -@route('/', method='POST') -def remote_control(): - st_home = os.statvfs("/home") - free_home = "%.2f" % float((st_home.f_bavail * st_home.f_frsize)/1.073741824e9) - - if (request.POST.get("cardbackup")): - process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/card-backup.sh", shell=True) - return template('exit.tpl') - if (request.POST.get("camerabackup")): - process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/camera-backup.sh", shell=True) - return template('exit.tpl') - if (request.POST.get("devicebackup")): - process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/device-backup.sh", shell=True) - return template('exit.tpl') - if (request.POST.get("shutdown")): - process = subprocess.Popen("sudo shutdown -h now", shell=True) - return template('exit.tpl') - return template('rc.tpl', freespace_home=free_home) - -@route('/static/:path#.+#', name='static') -def static(path): - return static_file(path, root='static') - -run(host="0.0.0.0", port=8080, debug=True, reloader=True) diff --git a/rc/rc.tpl b/rc/rc.tpl deleted file mode 100644 index 0c3be87..0000000 --- a/rc/rc.tpl +++ /dev/null @@ -1,59 +0,0 @@ - - - - -Little Backup Box - -
-
- -

Free disk space on /home: {{freespace_home}} GB

-
-

Back up a storage card connected via a card reader

-

-

Transfer files directly from the connected camera

-

-

Back up files from the internal storage to an external storage device

-

-

Shut down the Little Backup Box

-

-
diff --git a/rc/static/ichigo.svg b/scripts/ichigo.svg similarity index 100% rename from rc/static/ichigo.svg rename to scripts/ichigo.svg diff --git a/scripts/index.php b/scripts/index.php new file mode 100644 index 0000000..2267d10 --- /dev/null +++ b/scripts/index.php @@ -0,0 +1,104 @@ + + + + + + + + + + + + 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

+

+

+ +
+

+
+ + + + + diff --git a/scripts/rc.sh b/scripts/php.sh old mode 100755 new mode 100644 similarity index 86% rename from scripts/rc.sh rename to scripts/php.sh index ecaa671..bef2593 --- a/scripts/rc.sh +++ b/scripts/php.sh @@ -17,8 +17,8 @@ while : do - if [[ ! $(pgrep -f rc.py) ]]; then - cd /home/pi/little-backup-box/rc/ - sudo python3 rc.py + if [[ ! $(pgrep php) ]]; then + cd /home/$USER/little-backup-box/script/ + php -S localhost:8000 fi done