pwnagotchi/scripts/update_pwnagotchi.sh

82 lines
2.5 KiB
Bash
Raw Normal View History

2019-10-02 00:29:14 +02:00
#!/bin/bash
# Default variables
git_folder="/tmp/pwnagotchi"
git_url="https://github.com/evilsocket/pwnagotchi/"
2019-10-02 00:29:14 +02:00
version="master"
backupconfig=0
restoreconfig=0
# Functions
function usage() {
cat <<EOF
usage: $0 [OPTIONS]
Options:
-v, --version # Version to update to, can be a branch or commit. (default: master)
-u, --url # Url to clone from. (default: https://github.com/evilsocket/pwnagotchi)
-bc, --backupconfig # Backup the current pwnagotchi config.
-rc, --restoreconfig # Restore the current pwnagotchi config. -bc will be enabled.
-h, --help # Shows this help.
EOF
exit 0
2019-10-02 00:29:14 +02:00
}
function test_root() {
2019-10-02 00:29:14 +02:00
if ! [ $(id -u) = 0 ]; then
echo "[!] This script must be run as root."
exit 1
2019-10-02 00:29:14 +02:00
fi
}
function test_github() {
wget -q --spider $git_url
2019-10-02 00:29:14 +02:00
if [ $? -ne 0 ]; then
echo "[!] Cannot reach github. This script requires internet access, ensure connection sharing is working."
exit 2
2019-10-02 00:29:14 +02:00
fi
}
# Commandline arguments
while [[ "$#" -gt 0 ]]; do case $1 in
-v|--version) version="$2"; shift;;
-u|--url) git_url="$2"; shift;;
2019-10-02 00:29:14 +02:00
-bc|--backupconfig) backupconfig=1; shift;;
-rc|--restoreconfig) backupconfig=1 restoreconfig=1; shift;;
-h|--help) usage;;
*) echo "Unknown parameter passed: $1"; exit 3;;
2019-10-02 00:29:14 +02:00
esac; shift; done
echo "[+] Checking prerequisites."
2019-10-02 00:29:14 +02:00
test_root
test_github
# clean up old files, clone master, set checkout to commit if needed.
echo "[+] Cloning to $git_folder..."
rm $git_folder -rf
git clone $git_url $git_folder -q
cd $git_folder
if [ $version != "master" ]; then
git checkout $version -q
2019-10-02 00:29:14 +02:00
fi
echo "[+] Installing $(git log -1 --format="%h")"
2019-10-02 00:29:14 +02:00
echo "[+] Updating..."
2019-10-02 00:29:14 +02:00
if [ $backupconfig -eq 1 ]; then
echo "[+] Creating backup of config.yml"
mv /root/pwnagotchi/config.yml /root/config.yml.bak -f
2019-10-02 00:29:14 +02:00
fi
rm /root/pwnagotchi -rf # ensures old files are removed
rsync -aPq $git_folder/sdcard/boot/* /boot/
rsync -aPq $git_folder/sdcard/rootfs/* /
2019-10-02 00:29:14 +02:00
cd /tmp
rm $git_folder -rf
2019-10-02 00:29:14 +02:00
if [ $restoreconfig -eq 1 ]; then
echo "[+] Restoring backup of config.yml"
mv /root/config.yml.bak /root/pwnagotchi/config.yml -f
2019-10-02 00:29:14 +02:00
fi
echo "[+] Restarting pwnagotchi in auto mode. $( screen -X -S pwnagotchi quit)"
2019-10-02 00:29:14 +02:00
sudo -H -u root /usr/bin/screen -dmS pwnagotchi -c /root/pwnagotchi/data/screenrc.auto
echo "[+] Finished"