From 6d2af3720335c3f3ca4a56672150e48aa20c58f8 Mon Sep 17 00:00:00 2001 From: sp3nx0r Date: Wed, 2 Oct 2019 14:05:22 -0500 Subject: [PATCH 1/4] fixing getopts, adding host specific files to backup, refactoring --- scripts/update_pwnagotchi.sh | 58 +++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/scripts/update_pwnagotchi.sh b/scripts/update_pwnagotchi.sh index 0039e7b..f68d925 100644 --- a/scripts/update_pwnagotchi.sh +++ b/scripts/update_pwnagotchi.sh @@ -13,13 +13,14 @@ function usage() { cat < Date: Wed, 2 Oct 2019 16:11:51 -0500 Subject: [PATCH 2/4] fixing perms on script and uncommenting line from debugging --- scripts/update_pwnagotchi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/update_pwnagotchi.sh diff --git a/scripts/update_pwnagotchi.sh b/scripts/update_pwnagotchi.sh old mode 100644 new mode 100755 index f68d925..eaca8a5 --- a/scripts/update_pwnagotchi.sh +++ b/scripts/update_pwnagotchi.sh @@ -79,7 +79,7 @@ test_github # clean up old files, clone master, set checkout to commit if needed. echo "[+] Cloning to $GIT_FOLDER..." -#rm $GIT_FOLDER -rf +rm $GIT_FOLDER -rf git clone $GIT_URL $GIT_FOLDER -q cd $GIT_FOLDER if [ $VERSION != "master" ]; then From 690f59a846a7e38a20a093106f501deeb7c7d854 Mon Sep 17 00:00:00 2001 From: sp3nx0r Date: Wed, 2 Oct 2019 16:16:43 -0500 Subject: [PATCH 3/4] adding /etc/network/interfaces from PR#71 --- scripts/update_pwnagotchi.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/update_pwnagotchi.sh b/scripts/update_pwnagotchi.sh index eaca8a5..b7bce08 100755 --- a/scripts/update_pwnagotchi.sh +++ b/scripts/update_pwnagotchi.sh @@ -94,6 +94,7 @@ if [ $BACKUPCONFIG -eq 1 ]; then mv /etc/hosts /etc/hosts.bak -f mv /etc/hostname /etc/hostname.bak -f mv /etc/motd /etc/motd.bak -f + mv /etc/network/interfaces /etc/network/interfaces.bak -f fi echo "[+] Installing $(git log -1 --format="%h")" @@ -110,6 +111,7 @@ if [ $RESTORECONFIG -eq 1 ]; then mv /etc/hosts.bak /etc/hosts -f mv /etc/hostname.bak /etc/hostname -f mv /etc/motd.bak /etc/motd -f + mv /etc/network/interfaces.bak /etc/network/interfaces -f fi echo "[+] Restarting pwnagotchi in $MODE mode. $( screen -X -S pwnagotchi quit)" From 540eb69eada91cdb18ca54c7e2af333b2a345c67 Mon Sep 17 00:00:00 2001 From: sp3nx0r Date: Thu, 3 Oct 2019 06:49:18 -0500 Subject: [PATCH 4/4] resolve conflict, adjust getopts args, add /etc/motd to backup --- scripts/update_pwnagotchi.sh | 42 +++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/scripts/update_pwnagotchi.sh b/scripts/update_pwnagotchi.sh index b7bce08..734ed4c 100755 --- a/scripts/update_pwnagotchi.sh +++ b/scripts/update_pwnagotchi.sh @@ -19,8 +19,8 @@ function usage() { -v # Version to update to, can be a branch or commit. (default: master) -u # Url to clone from. (default: https://github.com/evilsocket/pwnagotchi) -m # Mode to restart to. (Supported: ${SUPPORTED_RESTART_MODES[*]}; default: auto) - -b # Backup the current pwnagotchi config, then overwrite with defaults. - -r # Restore the current pwnagotchi config after upgrade. (-b will be enabled.) + -b # Backup the current pwnagotchi config and hostname references, then overwrite with defaults. + -r # Restore the current pwnagotchi config and hostname references after upgrade. (-b will be enabled.) -h # Shows this help. EOF @@ -37,10 +37,11 @@ function test_root() { function test_github() { wget -q --spider $GIT_URL if [ $? -ne 0 ]; then - echo "[!] Cannot reach github. This script requires internet access and DNS resolution, ensure connection sharing is working and valid DNS server in /etc/resolv.conf." + echo "[!] Cannot reach github. This script requires internet access, ensure connection sharing is working." exit 2 fi } + while getopts "v:u:m:brh" o; do case "${o}" in v) @@ -49,6 +50,13 @@ while getopts "v:u:m:brh" o; do u) GIT_URL="${OPTARG}" ;; + m) + if [[ "${SUPPORTED_RESTART_MODES[*]}" =~ ${OPTARG} ]]; then + MODE="${OPTARG}" + else + usage + fi + ;; b) BACKUPCONFIG=1 ;; @@ -59,13 +67,6 @@ while getopts "v:u:m:brh" o; do h) usage ;; - m) - if [[ "${SUPPORTED_RESTART_MODES[*]}" =~ ${OPTARG} ]]; then - MODE="${OPTARG}" - else - usage - fi - ;; *) usage ;; @@ -86,15 +87,13 @@ if [ $VERSION != "master" ]; then git checkout $VERSION -q fi -echo "[+] Updating..." if [ $BACKUPCONFIG -eq 1 ]; then - echo "[+] Creating backup of config.yml" - mv /root/pwnagotchi/config.yml /root/config.yml.bak -f - echo "[+] Creating backup of host files" - mv /etc/hosts /etc/hosts.bak -f - mv /etc/hostname /etc/hostname.bak -f + echo "[+] Creating backup of config.yml and hostname references" + mv /root/pwnagotchi/config.yml /root/config.bak -f + mv /etc/hosts /root/hosts.bak -f + mv /etc/hostname /root/hostname.bak -f mv /etc/motd /etc/motd.bak -f - mv /etc/network/interfaces /etc/network/interfaces.bak -f + mv /etc/network/interfaces /root/interfaces.bak -f fi echo "[+] Installing $(git log -1 --format="%h")" @@ -105,13 +104,12 @@ cd /tmp rm $GIT_FOLDER -rf if [ $RESTORECONFIG -eq 1 ]; then - echo "[+] Restoring backup of config.yml" + echo "[+] Restoring backup of config.yml and hostname references" mv /root/config.yml.bak /root/pwnagotchi/config.yml -f - echo "[+] Restoring backup of host files" - mv /etc/hosts.bak /etc/hosts -f - mv /etc/hostname.bak /etc/hostname -f + mv /root/hosts.bak /etc/hosts -f + mv /root/hostname.bak /etc/hostname -f + mv /root/interfaces.bak /etc/network/interfaces -f mv /etc/motd.bak /etc/motd -f - mv /etc/network/interfaces.bak /etc/network/interfaces -f fi echo "[+] Restarting pwnagotchi in $MODE mode. $( screen -X -S pwnagotchi quit)"