2019-10-02 00:29:14 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Default variables
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
|
|
|
|
2019-10-02 10:14:26 +02:00
|
|
|
# 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
|
|
|
}
|
2019-10-02 10:14:26 +02:00
|
|
|
|
|
|
|
function test_root() {
|
2019-10-02 00:29:14 +02:00
|
|
|
if ! [ $(id -u) = 0 ]; then
|
2019-10-02 10:14:26 +02:00
|
|
|
echo "[!] This script must be run as root."
|
|
|
|
exit 1
|
2019-10-02 00:29:14 +02:00
|
|
|
fi
|
|
|
|
}
|
2019-10-02 10:14:26 +02:00
|
|
|
|
|
|
|
function test_github() {
|
|
|
|
wget -q --spider $git_url
|
2019-10-02 00:29:14 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
2019-10-02 10:14:26 +02:00
|
|
|
-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;;
|
2019-10-02 10:14:26 +02:00
|
|
|
-h|--help) usage;;
|
|
|
|
*) echo "Unknown parameter passed: $1"; exit 3;;
|
2019-10-02 00:29:14 +02:00
|
|
|
esac; shift; done
|
|
|
|
|
2019-10-02 10:14:26 +02:00
|
|
|
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.
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
2019-10-02 10:14:26 +02:00
|
|
|
echo "[+] Installing $(git log -1 --format="%h")"
|
2019-10-02 00:29:14 +02:00
|
|
|
|
2019-10-02 10:14:26 +02:00
|
|
|
echo "[+] Updating..."
|
2019-10-02 00:29:14 +02:00
|
|
|
if [ $backupconfig -eq 1 ]; then
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
2019-10-02 10:14:26 +02:00
|
|
|
rm $git_folder -rf
|
2019-10-02 00:29:14 +02:00
|
|
|
if [ $restoreconfig -eq 1 ]; then
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
|
|
|
|
2019-10-02 10:14:26 +02:00
|
|
|
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
|
2019-10-02 10:14:26 +02:00
|
|
|
echo "[+] Finished"
|