This commit is contained in:
Simone Margaritelli 2019-10-03 14:30:25 +02:00
commit a28d525530

32
scripts/update_pwnagotchi.sh Normal file → Executable file
View File

@ -13,13 +13,14 @@ function usage() {
cat <<EOF cat <<EOF
usage: $0 [OPTIONS] usage: $0 [OPTIONS]
Note: This should be run from the pwnagotchi itself!
Options: Options:
-v # Version to update to, can be a branch or commit. (default: master) -v # Version to update to, can be a branch or commit. (default: master)
-u # Url to clone from. (default: https://github.com/evilsocket/pwnagotchi) -u # Url to clone from. (default: https://github.com/evilsocket/pwnagotchi)
-m # Mode to restart to. (Supported: ${SUPPORTED_RESTART_MODES[*]}; default: auto) -m # Mode to restart to. (Supported: ${SUPPORTED_RESTART_MODES[*]}; default: auto)
-b # Backup the current pwnagotchi config and hostname references. -b # Backup the current pwnagotchi config and hostname references, then overwrite with defaults.
-r # Restore the current pwnagotchi config and hostname references. (-b will be enabled.) -r # Restore the current pwnagotchi config and hostname references after upgrade. (-b will be enabled.)
-h # Shows this help. -h # Shows this help.
EOF EOF
@ -41,11 +42,7 @@ function test_github() {
fi fi
} }
echo "[+] Checking prerequisites." while getopts "v:u:m:brh" o; do
test_root
test_github
while getopts ":v:u:m:b:r:h" o; do
case "${o}" in case "${o}" in
v) v)
VERSION="${OPTARG}" VERSION="${OPTARG}"
@ -58,15 +55,15 @@ while getopts ":v:u:m:b:r:h" o; do
MODE="${OPTARG}" MODE="${OPTARG}"
else else
usage usage
fi fi
;; ;;
b) b)
BACKUPCONFIG=1 BACKUPCONFIG=1
;; ;;
r) r)
BACKUPCONFIG=1 BACKUPCONFIG=1
RESTORECONFIG=1 RESTORECONFIG=1
;; ;;
h) h)
usage usage
;; ;;
@ -77,6 +74,10 @@ while getopts ":v:u:m:b:r:h" o; do
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
echo "[+] Checking prerequisites."
test_root
test_github
# clean up old files, clone master, set checkout to commit if needed. # clean up old files, clone master, set checkout to commit if needed.
echo "[+] Cloning to $GIT_FOLDER..." echo "[+] Cloning to $GIT_FOLDER..."
rm $GIT_FOLDER -rf rm $GIT_FOLDER -rf
@ -85,27 +86,30 @@ cd $GIT_FOLDER
if [ $VERSION != "master" ]; then if [ $VERSION != "master" ]; then
git checkout $VERSION -q git checkout $VERSION -q
fi fi
echo "[+] Installing $(git log -1 --format="%h")"
echo "[+] Updating..."
if [ $BACKUPCONFIG -eq 1 ]; then if [ $BACKUPCONFIG -eq 1 ]; then
echo "[+] Creating backup of config.yml and hostname references" echo "[+] Creating backup of config.yml and hostname references"
mv /root/pwnagotchi/config.yml /root/config.bak -f mv /root/pwnagotchi/config.yml /root/config.bak -f
mv /etc/hosts /root/hosts.bak -f mv /etc/hosts /root/hosts.bak -f
mv /etc/hostname /root/hostname.bak -f mv /etc/hostname /root/hostname.bak -f
mv /etc/motd /etc/motd.bak -f
mv /etc/network/interfaces /root/interfaces.bak -f mv /etc/network/interfaces /root/interfaces.bak -f
fi fi
echo "[+] Installing $(git log -1 --format="%h")"
rm /root/pwnagotchi -rf # ensures old files are removed rm /root/pwnagotchi -rf # ensures old files are removed
rsync -aPq $GIT_FOLDER/sdcard/boot/* /boot/ rsync -aPq $GIT_FOLDER/sdcard/boot/* /boot/
rsync -aPq $GIT_FOLDER/sdcard/rootfs/* / rsync -aPq $GIT_FOLDER/sdcard/rootfs/* /
cd /tmp cd /tmp
rm $GIT_FOLDER -rf rm $GIT_FOLDER -rf
if [ $RESTORECONFIG -eq 1 ]; then if [ $RESTORECONFIG -eq 1 ]; then
echo "[+] Restoring backup of config.yml and hostname references" echo "[+] Restoring backup of config.yml and hostname references"
mv /root/config.yml.bak /root/pwnagotchi/config.yml -f mv /root/config.yml.bak /root/pwnagotchi/config.yml -f
mv /root/hosts.bak /etc/hosts -f mv /root/hosts.bak /etc/hosts -f
mv /root/hostname.bak /etc/hostname -f mv /root/hostname.bak /etc/hostname -f
mv /root/interfaces.bak /etc/network/interfaces -f mv /root/interfaces.bak /etc/network/interfaces -f
mv /etc/motd.bak /etc/motd -f
fi fi
echo "[+] Restarting pwnagotchi in $MODE mode. $( screen -X -S pwnagotchi quit)" echo "[+] Restarting pwnagotchi in $MODE mode. $( screen -X -S pwnagotchi quit)"