Add /boot. Redo help. Replaced --commit/--branch with --version. Added --url to easly switch to other fork for testing
This commit is contained in:
parent
a495ffb136
commit
cd5be9c4cd
@ -1,77 +1,82 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Default variables
|
# Default variables
|
||||||
folder="/tmp/pwnagotchi"
|
git_folder="/tmp/pwnagotchi"
|
||||||
|
git_url="https://github.com/evilsocket/pwnagotchi/"
|
||||||
version="master"
|
version="master"
|
||||||
commit=0
|
|
||||||
backupconfig=0
|
backupconfig=0
|
||||||
restoreconfig=0
|
restoreconfig=0
|
||||||
|
|
||||||
# functions
|
# Functions
|
||||||
function display_help {
|
function usage() {
|
||||||
echo "Usage: $0 [-m | --master] [-c | --commit | --branch] [-bc | --backupconfig] [-rc | --restoreconfig] [-h | --help]" >&2
|
cat <<EOF
|
||||||
echo
|
|
||||||
echo " -m, --master Update to the master branch. Used by default."
|
usage: $0 [OPTIONS]
|
||||||
echo " -c, --commit, --branch Update to the specific commit/branch."
|
|
||||||
echo " -bc, --backupconfig Backup the current pwnagotchi config."
|
Options:
|
||||||
echo " -rc, --restoreconfig Restore the current pwnagotchi config. -bc will be enabled."
|
-v, --version # Version to update to, can be a branch or commit. (default: master)
|
||||||
echo " -h, --help Shows this help."
|
-u, --url # Url to clone from. (default: https://github.com/evilsocket/pwnagotchi)
|
||||||
echo ""
|
-bc, --backupconfig # Backup the current pwnagotchi config.
|
||||||
echo
|
-rc, --restoreconfig # Restore the current pwnagotchi config. -bc will be enabled.
|
||||||
exit 1
|
-h, --help # Shows this help.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
function test_root {
|
|
||||||
# Check if we are running as root.
|
function test_root() {
|
||||||
if ! [ $(id -u) = 0 ]; then
|
if ! [ $(id -u) = 0 ]; then
|
||||||
echo " [!] This script must be run as root."
|
echo "[!] This script must be run as root."
|
||||||
exit 3
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
function test_github {
|
|
||||||
wget -q --spider https://github.com/evilsocket/pwnagotchi/
|
function test_github() {
|
||||||
|
wget -q --spider $git_url
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo " [!] Cannot reach github. This script requires internet access, ensure connection sharing is working."
|
echo "[!] Cannot reach github. This script requires internet access, ensure connection sharing is working."
|
||||||
exit 4
|
exit 2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Commandline arguments
|
# Commandline arguments
|
||||||
while [[ "$#" -gt 0 ]]; do case $1 in
|
while [[ "$#" -gt 0 ]]; do case $1 in
|
||||||
-m|--master) version="master"; shift;;
|
-v|--version) version="$2"; shift;;
|
||||||
-c|--commit|---branch) commit="$2" version="other"; shift;;
|
-u|--url) git_url="$2"; shift;;
|
||||||
-bc|--backupconfig) backupconfig=1; shift;;
|
-bc|--backupconfig) backupconfig=1; shift;;
|
||||||
-rc|--restoreconfig) backupconfig=1 restoreconfig=1; shift;;
|
-rc|--restoreconfig) backupconfig=1 restoreconfig=1; shift;;
|
||||||
-h|--help) display_help;;
|
-h|--help) usage;;
|
||||||
*) echo "Unknown parameter passed: $1"; exit 2;;
|
*) echo "Unknown parameter passed: $1"; exit 3;;
|
||||||
esac; shift; done
|
esac; shift; done
|
||||||
|
|
||||||
echo " [+] Checking prerequisites."
|
echo "[+] Checking prerequisites."
|
||||||
test_root
|
test_root
|
||||||
test_github
|
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 $folder..."
|
echo "[+] Cloning to $git_folder..."
|
||||||
rm $folder -rf
|
rm $git_folder -rf
|
||||||
git clone https://github.com/evilsocket/pwnagotchi $folder -q
|
git clone $git_url $git_folder -q
|
||||||
cd $folder
|
cd $git_folder
|
||||||
if [ $version == "other" ]; then
|
if [ $version != "master" ]; then
|
||||||
git checkout $commit -q
|
git checkout $version -q
|
||||||
fi
|
fi
|
||||||
echo " [+] Installing $(git log -1 --format="%h")"
|
echo "[+] Installing $(git log -1 --format="%h")"
|
||||||
|
|
||||||
echo " [+] Updating..."
|
echo "[+] Updating..."
|
||||||
if [ $backupconfig -eq 1 ]; then
|
if [ $backupconfig -eq 1 ]; then
|
||||||
echo " [+] Creating backup of config.yml"
|
echo "[+] Creating backup of config.yml"
|
||||||
mv /root/pwnagotchi/config.yml ~/config.yml.bak -f
|
mv /root/pwnagotchi/config.yml /root/config.yml.bak -f
|
||||||
fi
|
fi
|
||||||
rm /root/pwnagotchi -rf
|
rm /root/pwnagotchi -rf # ensures old files are removed
|
||||||
rsync -aPq $folder/sdcard/rootfs/* /
|
rsync -aPq $git_folder/sdcard/boot/* /boot/
|
||||||
|
rsync -aPq $git_folder/sdcard/rootfs/* /
|
||||||
cd /tmp
|
cd /tmp
|
||||||
rm $folder -rf
|
rm $git_folder -rf
|
||||||
if [ $restoreconfig -eq 1 ]; then
|
if [ $restoreconfig -eq 1 ]; then
|
||||||
echo " [+] Restoring backup of config.yml"
|
echo "[+] Restoring backup of config.yml"
|
||||||
mv ~/config.yml.bak /root/pwnagotchi/config.yml -f
|
mv /root/config.yml.bak /root/pwnagotchi/config.yml -f
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo " [+] Restarting pwnagotchi in auto mode. $( screen -X -S pwnagotchi quit)"
|
echo "[+] Restarting pwnagotchi in auto mode. $( screen -X -S pwnagotchi quit)"
|
||||||
sudo -H -u root /usr/bin/screen -dmS pwnagotchi -c /root/pwnagotchi/data/screenrc.auto
|
sudo -H -u root /usr/bin/screen -dmS pwnagotchi -c /root/pwnagotchi/data/screenrc.auto
|
||||||
echo " [+] Finished"
|
echo "[+] Finished"
|
Loading…
x
Reference in New Issue
Block a user