From 669141e3d1360f9d52ca052886c7cffddd9245a7 Mon Sep 17 00:00:00 2001 From: Matt Gates Date: Sun, 24 Nov 2019 08:49:24 -0500 Subject: [PATCH] Format everything --- src/config.sh | 38 +-- src/install.sh | 80 +++---- src/save-tokens.php | 35 +-- src/scripts/everyBoot/freedomevstart.sh | 96 ++++---- src/scripts/everyBoot/listen-for-code.sh | 222 ++++++++--------- src/scripts/everyBoot/memory-logs.sh | 24 +- src/scripts/everyBoot/open-diag-port.sh | 6 +- src/scripts/everyBoot/reverse-tunnel.sh | 6 +- src/scripts/everyBoot/vpn-over-cell.sh | 28 +-- src/scripts/everyFiveMinutes/eggwot.sh | 8 +- src/scripts/everyFiveMinutes/open-wifi.sh | 24 +- src/scripts/everyFiveMinutes/startstopvpn.sh | 10 +- src/scripts/everyFiveMinutes/tokens-to-php.sh | 2 +- src/scripts/misc/email-screenshots.sh | 32 +-- src/scripts/misc/get-versions.sh | 14 +- src/scripts/misc/imgur.sh | 179 ++++++++------ src/scripts/misc/save-ap-footage.sh | 18 +- src/scripts/misc/save-kernel.sh | 6 +- src/scripts/misc/save-update.sh | 224 +++++++++--------- .../misc/sync-screenshots-with-dropbox.sh | 16 +- src/scripts/misc/upload-screenshots.sh | 16 +- src/scripts/on-reboot.sh | 48 ++-- 22 files changed, 571 insertions(+), 561 deletions(-) diff --git a/src/config.sh b/src/config.sh index 32fb756..53f6f93 100644 --- a/src/config.sh +++ b/src/config.sh @@ -30,27 +30,27 @@ export accountUserToSaveToCar="yourUsername" export accountPassToSaveToCar="myCarIsRooted" scheduledScripts=( - "$homeOfLunars/scripts/everyBoot/memory-logs.sh" - "$homeOfLunars/scripts/everyBoot/mount-modfiles.sh" - "$homeOfLunars/scripts/everyBoot/open-diag-port.sh" - "$homeOfLunars/scripts/everyBoot/create-accounts.sh" -# "$homeOfLunars/scripts/everyBoot/block-tesla-ssh.sh" -# "$homeOfLunars/scripts/everyBoot/freedomevstart.sh" -# "$homeOfLunars/scripts/everyBoot/wake-bench.sh" -# "$homeOfLunars/scripts/everyBoot/listen-for-code.sh" -# "$homeOfLunars/scripts/everyBoot/reverse-tunnel.sh" -# "$homeOfLunars/scripts/everyBoot/vpn-over-cell.sh" + "$homeOfLunars/scripts/everyBoot/memory-logs.sh" + "$homeOfLunars/scripts/everyBoot/mount-modfiles.sh" + "$homeOfLunars/scripts/everyBoot/open-diag-port.sh" + "$homeOfLunars/scripts/everyBoot/create-accounts.sh" + # "$homeOfLunars/scripts/everyBoot/block-tesla-ssh.sh" + # "$homeOfLunars/scripts/everyBoot/freedomevstart.sh" + # "$homeOfLunars/scripts/everyBoot/wake-bench.sh" + # "$homeOfLunars/scripts/everyBoot/listen-for-code.sh" + # "$homeOfLunars/scripts/everyBoot/reverse-tunnel.sh" + # "$homeOfLunars/scripts/everyBoot/vpn-over-cell.sh" ) everyFiveMinuteScripts=( - "$homeOfLunars/scripts/everyFiveMinutes/open-wifi.sh" - "$homeOfLunars/scripts/everyFiveMinutes/startstopvpn.sh" - "$homeOfLunars/scripts/everyFiveMinutes/tokens-to-php.sh" - "$homeOfLunars/scripts/everyFiveMinutes/vitals-to-php.sh" + "$homeOfLunars/scripts/everyFiveMinutes/open-wifi.sh" + "$homeOfLunars/scripts/everyFiveMinutes/startstopvpn.sh" + "$homeOfLunars/scripts/everyFiveMinutes/tokens-to-php.sh" + "$homeOfLunars/scripts/everyFiveMinutes/vitals-to-php.sh" -# "$homeOfLunars/scripts/everyFiveMinutes/add-swblock.sh" -# "$homeOfLunars/scripts/everyFiveMinutes/copy-tokens-to-ic.sh" -# "$homeOfLunars/scripts/everyFiveMinutes/eggwot.sh" -# "$homeOfLunars/scripts/everyFiveMinutes/save-key-over-ssh.sh" + # "$homeOfLunars/scripts/everyFiveMinutes/add-swblock.sh" + # "$homeOfLunars/scripts/everyFiveMinutes/copy-tokens-to-ic.sh" + # "$homeOfLunars/scripts/everyFiveMinutes/eggwot.sh" + # "$homeOfLunars/scripts/everyFiveMinutes/save-key-over-ssh.sh" -) \ No newline at end of file +) diff --git a/src/install.sh b/src/install.sh index 14eecf6..b809bb4 100644 --- a/src/install.sh +++ b/src/install.sh @@ -12,8 +12,8 @@ echo "Installing Lunars to $homeOfLunars" # Detect if we are running chrooted by checking if the root of the init process is the same as the root of this process if [[ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]]; then - echo "[FAIL] Not running chrooted" - exit 2 + echo "[FAIL] Not running chrooted" + exit 2 fi echo "[OK] Not running chrooted" @@ -23,61 +23,61 @@ onRebootFile="$homeOfLunars/scripts/$rebootScript" startScript="/sbin/start-stop-daemon --start --quiet --make-pidfile --oknodo --background --pidfile /var/run/lunars-main.pid --exec /bin/bash $onRebootFile" function downloadLunars() { - echo "Downloading lunars source from Github..." - - mkdir -p "$homeOfLunars" - curl -s -L https://github.com/Lunars/tesla/tarball/master | tar --wildcards -zx -C "$homeOfLunars" "Lunars-tesla-*/src" - mv "$homeOfLunars"/*/src/* "$homeOfLunars" - rm -rf "$homeOfLunars"/Lunars-tesla-* - - echo "[OK] Lunars source downloaded" - - if [[ -f /tmp/config.sh ]]; then - # Restore config from tmp - mv /tmp/overwrite-files "$homeOfLunars" - mv /tmp/config.sh "$homeOfLunars" - mv /tmp/tesla.ovpn "$homeOfLunars" - echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files restored" - fi + echo "Downloading lunars source from Github..." + + mkdir -p "$homeOfLunars" + curl -s -L https://github.com/Lunars/tesla/tarball/master | tar --wildcards -zx -C "$homeOfLunars" "Lunars-tesla-*/src" + mv "$homeOfLunars"/*/src/* "$homeOfLunars" + rm -rf "$homeOfLunars"/Lunars-tesla-* + + echo "[OK] Lunars source downloaded" + + if [[ -f /tmp/config.sh ]]; then + # Restore config from tmp + mv /tmp/overwrite-files "$homeOfLunars" + mv /tmp/config.sh "$homeOfLunars" + mv /tmp/tesla.ovpn "$homeOfLunars" + echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files restored" + fi } if [[ -f "$onRebootFile" ]]; then - # Save config to tmp - mv "$homeOfLunars"/overwrite-files /tmp - mv "$homeOfLunars"/config.sh /tmp - mv "$homeOfLunars"/tesla.ovpn /tmp - echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files saved" - - rm -rf "$homeOfLunars" - downloadLunars + # Save config to tmp + mv "$homeOfLunars"/overwrite-files /tmp + mv "$homeOfLunars"/config.sh /tmp + mv "$homeOfLunars"/tesla.ovpn /tmp + echo "[OK] Lunars config.sh, tesla.ovpn, and overwrite-files saved" + + rm -rf "$homeOfLunars" + downloadLunars else - downloadLunars + downloadLunars - # In case a custom install path was given, replace it in config.sh too - [ -n "$search" ] && sed -i "s~$search~$homeOfLunars~g" "$homeOfLunars/config.sh" + # In case a custom install path was given, replace it in config.sh too + [ -n "$search" ] && sed -i "s~$search~$homeOfLunars~g" "$homeOfLunars/config.sh" fi # Installing crontab alreadyInstalled=$(crontab -l | grep "$rebootScript") if [[ "$alreadyInstalled" != "" ]]; then - echo "[SKIP] Lunars cron already installed" + echo "[SKIP] Lunars cron already installed" else - # Just in case this file already exists - rm /tmp/crontab 2>/dev/null - crontab -l >/tmp/crontab - echo "@reboot $startScript" >>/tmp/crontab - crontab /dev/null + crontab -l >/tmp/crontab + echo "@reboot $startScript" >>/tmp/crontab + crontab filename)) - { + if (!file_exists($this->filename)) { $fh = fopen($this->filename, 'w') or die("Can't create file"); } - if (empty($_GET['s1']) || empty($_GET['s2'])) - { + if (empty($_GET['s1']) || empty($_GET['s2'])) { $this->showLastKey(); - } - else - { + } else { $this->saveKeys(); } } @@ -25,19 +23,15 @@ function showLastKey() { $str_data = file_get_contents($this->filename); $decoded = json_decode($str_data); - if (!empty($_GET['car'])) - { - $decoded->tokens = array_filter((array)$decoded->tokens, function ($v) - { + if (!empty($_GET['car'])) { + $decoded->tokens = array_filter((array)$decoded->tokens, function ($v) { return $v->car === $_GET['car']; }); } - if (!empty($decoded)) - { + if (!empty($decoded)) { $last = end($decoded->tokens); - if ($last) - { + if ($last) { $last->saved_date = date('Y-m-d G:i', $last->saved_date); } @@ -55,17 +49,14 @@ function saveKeys() if (empty($decoded['tokens'])) $decoded['tokens'] = []; // Remove duplicate tokens, in case the cron runs often - $decoded['tokens'] = array_filter($decoded['tokens'], function ($v) - { + $decoded['tokens'] = array_filter($decoded['tokens'], function ($v) { return $v['tesla1'] != $_GET['s1'] && $v['tesla2'] != $_GET['s2']; }); - $newTokens = ['tesla1' => $_GET['s1'], 'tesla2' => $_GET['s2'], 'saved_date' => strtotime('now') ]; - if (!empty($_GET['car'])) - { + $newTokens = ['tesla1' => $_GET['s1'], 'tesla2' => $_GET['s2'], 'saved_date' => strtotime('now')]; + if (!empty($_GET['car'])) { $newTokens['car'] = $_GET['car']; } - if (!empty($_GET['unlock_token'])) - { + if (!empty($_GET['unlock_token'])) { $newTokens['unlock_token'] = $_GET['unlock_token']; } diff --git a/src/scripts/everyBoot/freedomevstart.sh b/src/scripts/everyBoot/freedomevstart.sh index d46d9d5..d3394b5 100644 --- a/src/scripts/everyBoot/freedomevstart.sh +++ b/src/scripts/everyBoot/freedomevstart.sh @@ -12,87 +12,87 @@ #check if freedomev was already detected if [[ -f /tmp/freedomevmountpoint ]]; then - freedomevstarted=true - usbmountpoint=$(cat /tmp/freedomevmountpoint) + freedomevstarted=true + usbmountpoint=$(cat /tmp/freedomevmountpoint) else - freedomevstarted=false + freedomevstarted=false fi #possibly check if there are no double mounts or dangling mountpoints #function to kill remaining freedomev chrooted processes and umount function killandumount() { - #run all deactivation scripts - for deactivationscript in /tmp/freedomev/*; do - bash ${deactivationscript} && rm ${deactivationscript} - done - #umount filesystems - umount ${usbmountpoint}/proc/ - umount ${usbmountpoint}/sys - umount ${usbmountpoint}/dev - umount ${usbmountpoint}/tmp - umount ${usbmountpoint}/dev/pts - umount -f ${usbmountpoint} - rm /tmp/freedomevmountpoint - #check if no mount points are dangling + #run all deactivation scripts + for deactivationscript in /tmp/freedomev/*; do + bash ${deactivationscript} && rm ${deactivationscript} + done + #umount filesystems + umount ${usbmountpoint}/proc/ + umount ${usbmountpoint}/sys + umount ${usbmountpoint}/dev + umount ${usbmountpoint}/tmp + umount ${usbmountpoint}/dev/pts + umount -f ${usbmountpoint} + rm /tmp/freedomevmountpoint + #check if no mount points are dangling } #check if the USB stick is present usbstickpresent=$(cat /proc/partitions | grep sd[a-z]1$) if [[ ${usbstickpresent} == "" ]]; then - if ! ${freedomevstarted}; then - #we want to end as quickly as possible if we don't need to do anything - #possibly we need to check if we need to kill some processes or umount bind mounted stuff - #for now, one can also reboot after removing the stick - exit 0 - else - #we need to kill all possible processes who run on the removed rootfs from the USB stick and possibly umount - killandumount - fi + if ! ${freedomevstarted}; then + #we want to end as quickly as possible if we don't need to do anything + #possibly we need to check if we need to kill some processes or umount bind mounted stuff + #for now, one can also reboot after removing the stick + exit 0 + else + #we need to kill all possible processes who run on the removed rootfs from the USB stick and possibly umount + killandumount + fi fi #determine mountpoint - should not be emty usbmountpoint=$(mount | grep '^/dev/sd' | awk '{ print $3 }' | head -n 1) if [[ ${usbmountpoint} == "" ]]; then - exit 3 + exit 3 else - echo ${usbmountpoint} >/tmp/freedomevmountpoint + echo ${usbmountpoint} >/tmp/freedomevmountpoint fi #check if it's mounted read-only, possibly remount - otherwise exit, maybe still busy mounting, will try again next run usbstickmounted=$(mount | grep '^/dev/sd.1.*(ro,noexec,nodev,noatime)$') if [[ ${usbstickmounted} != "" ]]; then - mount -o remount,rw,exec,dev /dev/sd?1 || exit 2 + mount -o remount,rw,exec,dev /dev/sd?1 || exit 2 fi #check if it contains the correct content and determine the version freedomevversion=$(cat ${usbmountpoint}/etc/freedomevversion) if [[ ${freedomevversion} == "" ]]; then - echo no ${usbmountpoint}/etc/freedomevversion - if ${freedomevstarted}; then - killandumount - fi - exit 4 + echo no ${usbmountpoint}/etc/freedomevversion + if ${freedomevstarted}; then + killandumount + fi + exit 4 fi echo freedomevstarted=${freedomevstarted} #initial start if ! ${freedomevstarted}; then - echo ${usbmountpoint} >/tmp/freedomevmountpoint - mount -t proc archproc ${usbmountpoint}/proc/ - mount -t sysfs archsys ${usbmountpoint}/sys - mount -o bind /dev ${usbmountpoint}/dev - mount -o bind /tmp ${usbmountpoint}/tmp - mount -t devpts archdevpts ${usbmountpoint}/dev/pts - #I prefer not to put the key in the public git so we cp it to /tmp - mkdir /tmp/freedomev/ 2>/dev/null - cp /root/.ssh/id_dsa /tmp/freedomev/id_dsa - #some more hacking powers - mount /var -o remount,exec - mount -o remount,exec /opt/navigoff - export usbmountpoint - /bin/bash ${usbmountpoint}/freedomev/tools/activation-outside-chroot-jail - /usr/sbin/chroot ${usbmountpoint} /bin/bash /freedomev/tools/activation + echo ${usbmountpoint} >/tmp/freedomevmountpoint + mount -t proc archproc ${usbmountpoint}/proc/ + mount -t sysfs archsys ${usbmountpoint}/sys + mount -o bind /dev ${usbmountpoint}/dev + mount -o bind /tmp ${usbmountpoint}/tmp + mount -t devpts archdevpts ${usbmountpoint}/dev/pts + #I prefer not to put the key in the public git so we cp it to /tmp + mkdir /tmp/freedomev/ 2>/dev/null + cp /root/.ssh/id_dsa /tmp/freedomev/id_dsa + #some more hacking powers + mount /var -o remount,exec + mount -o remount,exec /opt/navigoff + export usbmountpoint + /bin/bash ${usbmountpoint}/freedomev/tools/activation-outside-chroot-jail + /usr/sbin/chroot ${usbmountpoint} /bin/bash /freedomev/tools/activation fi #launch the checks for freedomev core such as periodic check for version and periodic checks for certain apps diff --git a/src/scripts/everyBoot/listen-for-code.sh b/src/scripts/everyBoot/listen-for-code.sh index 7e444dd..9e888c1 100644 --- a/src/scripts/everyBoot/listen-for-code.sh +++ b/src/scripts/everyBoot/listen-for-code.sh @@ -7,119 +7,119 @@ mainPath="$homeOfLunars/scripts" pattern=AccessPopup last_command="NoNe" if ps ax | grep $0 | grep -v $$ | grep bash | grep -v grep; then - echo "The script is already running." - exit 1 + echo "The script is already running." + exit 1 fi while true; do - if inotifywait -q -q -e modify /var/log/syslog; then - msg=$(tail -n 100 /var/log/syslog | grep "access code" | grep -m1 $pattern) - res="NoNe" - if [[ $msg == *$pattern* ]]; then - password=$(echo $msg | awk -F':' '{ print $6 }') - if [[ $password == $last_command ]]; then - password="NoNe" - else - last_command=$password - fi - case $password in - "NoNe") - echo "Got NoNe" - ;; - " resetpw") - echo "root:root" | chpasswd - res="root password: root" - ;; - " egg2") - sdv GUI_eggWotMode 1 - /bin/sleep 2 - sdv GUI_eggWotMode 2 - ;; - " egg1") - sdv GUI_eggWotMode 1 - ;; - " egg0") - sdv GUI_eggWotMode 0 - ;; - " ss") - res=$(/bin/bash $mainPath/upload-screenshots.sh) - ;; - " wipeupdate") - /bin/bash $mainPath/wipe-update.sh - res="Update got wiped" - ;; - " vlow") - sdv GUI_suspensionLevelRequest 7 - ;; - " test") - res="Test message!" - ;; - " help") - res=$(grep -o '" .*")' $mainPath/everyBoot/listen-for-code.sh | tr -d '") ') # Get all commands from this file - res="${res//$'\n'/ }" # Replace newlines - ;; - " rrun "*) - password=${password#" rrun "} - res=$(eval $password) - ;; - " wifi") - res=$(/bin/bash $mainPath/everyFiveMinutes/open-wifi.sh) - ;; - " tkn1") - res=$(cat /var/etc/saccess/tesla1) - ;; - " tkn2") - res=$(cat /var/etc/saccess/tesla2) - ;; - " tkns") - res=$(/bin/bash $mainPath/everyFiveMinutes/save-key-to-php.sh) - ;; - " devm") - sdv GUI_developerMode true - ;; - " rebparrot") - emit-restart-parrot - ;; - " rebmodem") - modem-power cycle - ;; - " rebic") - emit-reboot-cluster - ;; - " rebcid") - emit-reboot-cid - ;; - " rebgw") - emit-reboot-gateway - ;; - " factory") - sdv GUI_factoryMode true - touch /home/tesla/factoryMode - emit-reboot-cid - ;; - " unfactory") - sdv GUI_factoryMode false - rm /home/tesla/factoryMode - emit-reboot-cid - ;; - " ip") - res=$(ip addr show) - ;; - *) - # hmmm, something unknown, stash it away - echo "$(date) - $password" >>$mainPath/pwd_hist.txt - ;; - esac - else - last_command="NoNe" - fi - if [ "$res" != "NoNe" ]; then - res="${res//$'\n'/$'\r\n'}" - msg_txt="Running [$password] returned: " - curl -G -m 5 -f http://${cidIp}:${cidPort}/display_message -d color=foregroundColor --data-urlencode message="$msg_txt" - echo "$res" | while IFS= read -r rline; do - curl -G -m 5 -f http://${cidIp}:${cidPort}/display_message -d color=foregroundColor --data-urlencode message="$rline" - done - fi + if inotifywait -q -q -e modify /var/log/syslog; then + msg=$(tail -n 100 /var/log/syslog | grep "access code" | grep -m1 $pattern) + res="NoNe" + if [[ $msg == *$pattern* ]]; then + password=$(echo $msg | awk -F':' '{ print $6 }') + if [[ $password == $last_command ]]; then + password="NoNe" + else + last_command=$password + fi + case $password in + "NoNe") + echo "Got NoNe" + ;; + " resetpw") + echo "root:root" | chpasswd + res="root password: root" + ;; + " egg2") + sdv GUI_eggWotMode 1 + /bin/sleep 2 + sdv GUI_eggWotMode 2 + ;; + " egg1") + sdv GUI_eggWotMode 1 + ;; + " egg0") + sdv GUI_eggWotMode 0 + ;; + " ss") + res=$(/bin/bash $mainPath/upload-screenshots.sh) + ;; + " wipeupdate") + /bin/bash $mainPath/wipe-update.sh + res="Update got wiped" + ;; + " vlow") + sdv GUI_suspensionLevelRequest 7 + ;; + " test") + res="Test message!" + ;; + " help") + res=$(grep -o '" .*")' $mainPath/everyBoot/listen-for-code.sh | tr -d '") ') # Get all commands from this file + res="${res//$'\n'/ }" # Replace newlines + ;; + " rrun "*) + password=${password#" rrun "} + res=$(eval $password) + ;; + " wifi") + res=$(/bin/bash $mainPath/everyFiveMinutes/open-wifi.sh) + ;; + " tkn1") + res=$(cat /var/etc/saccess/tesla1) + ;; + " tkn2") + res=$(cat /var/etc/saccess/tesla2) + ;; + " tkns") + res=$(/bin/bash $mainPath/everyFiveMinutes/save-key-to-php.sh) + ;; + " devm") + sdv GUI_developerMode true + ;; + " rebparrot") + emit-restart-parrot + ;; + " rebmodem") + modem-power cycle + ;; + " rebic") + emit-reboot-cluster + ;; + " rebcid") + emit-reboot-cid + ;; + " rebgw") + emit-reboot-gateway + ;; + " factory") + sdv GUI_factoryMode true + touch /home/tesla/factoryMode + emit-reboot-cid + ;; + " unfactory") + sdv GUI_factoryMode false + rm /home/tesla/factoryMode + emit-reboot-cid + ;; + " ip") + res=$(ip addr show) + ;; + *) + # hmmm, something unknown, stash it away + echo "$(date) - $password" >>$mainPath/pwd_hist.txt + ;; + esac + else + last_command="NoNe" fi + if [ "$res" != "NoNe" ]; then + res="${res//$'\n'/$'\r\n'}" + msg_txt="Running [$password] returned: " + curl -G -m 5 -f http://${cidIp}:${cidPort}/display_message -d color=foregroundColor --data-urlencode message="$msg_txt" + echo "$res" | while IFS= read -r rline; do + curl -G -m 5 -f http://${cidIp}:${cidPort}/display_message -d color=foregroundColor --data-urlencode message="$rline" + done + fi + fi done diff --git a/src/scripts/everyBoot/memory-logs.sh b/src/scripts/everyBoot/memory-logs.sh index 70b6b09..7d8f89e 100644 --- a/src/scripts/everyBoot/memory-logs.sh +++ b/src/scripts/everyBoot/memory-logs.sh @@ -4,18 +4,18 @@ ISTMPFS=$(/bin/mount | /bin/grep -c "/var/log type tmpfs") if [ "$ISTMPFS" == 0 ]; then - mount -t tmpfs -o size=100M tmpfs /var/log + mount -t tmpfs -o size=100M tmpfs /var/log - #if we mount while the programs are still active and they keep their logfiles open, they keep on writing to the - #(now hidden) location on the eMMC, so we need to restart or send the HUP signal (if it's properly impemented) - mkdir /var/log/ntpstats /var/log/mgetty - chown ntp:ntp /var/log/ntpstats/ - service ntp restart - pkill -HUP valhalla_server - restart rsyslog + #if we mount while the programs are still active and they keep their logfiles open, they keep on writing to the + #(now hidden) location on the eMMC, so we need to restart or send the HUP signal (if it's properly impemented) + mkdir /var/log/ntpstats /var/log/mgetty + chown ntp:ntp /var/log/ntpstats/ + service ntp restart + pkill -HUP valhalla_server + restart rsyslog - ssh ic "mount -t tmpfs -o size=100M tmpfs /var/log" - ssh ic "mkdir /var/log/ntpstats /var/log/mgetty" - ssh ic "service ntp restart" - ssh ic "restart rsyslog" + ssh ic "mount -t tmpfs -o size=100M tmpfs /var/log" + ssh ic "mkdir /var/log/ntpstats /var/log/mgetty" + ssh ic "service ntp restart" + ssh ic "restart rsyslog" fi diff --git a/src/scripts/everyBoot/open-diag-port.sh b/src/scripts/everyBoot/open-diag-port.sh index 51c6aa3..4d122aa 100644 --- a/src/scripts/everyBoot/open-diag-port.sh +++ b/src/scripts/everyBoot/open-diag-port.sh @@ -1,10 +1,8 @@ #!/bin/bash -if [ ! -f /etc/tegraline-release ] -then +if [ ! -f /etc/tegraline-release ]; then touch /etc/tegraline-release fi -if [ ! -f /var/etc/disable-seceth ] -then +if [ ! -f /var/etc/disable-seceth ]; then touch /var/etc/disable-seceth fi diff --git a/src/scripts/everyBoot/reverse-tunnel.sh b/src/scripts/everyBoot/reverse-tunnel.sh index d3bee75..104702d 100644 --- a/src/scripts/everyBoot/reverse-tunnel.sh +++ b/src/scripts/everyBoot/reverse-tunnel.sh @@ -11,9 +11,9 @@ if [[ "$reverseTunnelServer" =~ "yourserver.com" ]]; then exit 1 fi -while : ; do - RET=$(ps ax | grep "${nonStandardPort}:localhost:22" | grep -v "grep"|wc -l) - if [ "$RET" -eq 0 ];then +while :; do + RET=$(ps ax | grep "${nonStandardPort}:localhost:22" | grep -v "grep" | wc -l) + if [ "$RET" -eq 0 ]; then ssh -N -T -R ${nonStandardPort}:localhost:22 -o ServerAliveInterval=3 -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes $reverseTunnelServer fi sleep 60 diff --git a/src/scripts/everyBoot/vpn-over-cell.sh b/src/scripts/everyBoot/vpn-over-cell.sh index e9fbd23..a1690e2 100644 --- a/src/scripts/everyBoot/vpn-over-cell.sh +++ b/src/scripts/everyBoot/vpn-over-cell.sh @@ -7,29 +7,29 @@ DHCPLEASES="/var/lib/dhcp3/dhclient.wwan0.leases" OVPN="$homeOfLunars/tesla.ovpn" if grep -q "YOURIPADDRESSHERE" $OVPN; then - echo "openvpn not yet setup, quitting" - exit 1 + echo "openvpn not yet setup, quitting" + exit 1 fi -function addVPNRoute { - VPNIP=$(awk '/^remote /' $OVPN | awk '{print $2}' ) - CELLIP=$(ip r | grep wwan0 | grep -Pom 1 '[0-9.]{7,15}' | tail -1) +function addVPNRoute() { + VPNIP=$(awk '/^remote /' $OVPN | awk '{print $2}') + CELLIP=$(ip r | grep wwan0 | grep -Pom 1 '[0-9.]{7,15}' | tail -1) - service openvpn stop - route delete $VPNIP > /dev/null 2>&1 + service openvpn stop + route delete $VPNIP >/dev/null 2>&1 - if [ ! -z "$CELLIP" ]; then - ROUTERIP=$(grep $CELLIP -A 3 $DHCPLEASES | tail -1 | grep -Pom 1 '[0-9.]{7,15}') - route add $VPNIP gw $ROUTERIP - fi + if [ ! -z "$CELLIP" ]; then + ROUTERIP=$(grep $CELLIP -A 3 $DHCPLEASES | tail -1 | grep -Pom 1 '[0-9.]{7,15}') + route add $VPNIP gw $ROUTERIP + fi - service openvpn start + service openvpn start } # Called once at least on start, so that the appropriate routes can be added addVPNRoute while inotifywait -e modify $DHCPLEASES; do - echo "Found cell change, updating route" - addVPNRoute + echo "Found cell change, updating route" + addVPNRoute done diff --git a/src/scripts/everyFiveMinutes/eggwot.sh b/src/scripts/everyFiveMinutes/eggwot.sh index 7161d02..1d276eb 100644 --- a/src/scripts/everyFiveMinutes/eggwot.sh +++ b/src/scripts/everyFiveMinutes/eggwot.sh @@ -13,9 +13,9 @@ MODE=1 echo "state is" $STATE echo "state wanted is" $WANTSTATE -if ! [ "$STATE" = "$WANTSTATE" ] ; then - sdv $KEY $MODE - echo "Enabling $KEY $MODE" +if ! [ "$STATE" = "$WANTSTATE" ]; then + sdv $KEY $MODE + echo "Enabling $KEY $MODE" else - echo "Already Enabled" + echo "Already Enabled" fi diff --git a/src/scripts/everyFiveMinutes/open-wifi.sh b/src/scripts/everyFiveMinutes/open-wifi.sh index 18cd3de..8520c32 100644 --- a/src/scripts/everyFiveMinutes/open-wifi.sh +++ b/src/scripts/everyFiveMinutes/open-wifi.sh @@ -14,16 +14,16 @@ iptables -D INPUT -i parrot -p tcp -m tcp --dport 22 -j ACCEPT iptables -I INPUT -i parrot -p tcp -m tcp --dport 22 -j ACCEPT { - echo - sleep 1 - echo - sleep 1 - echo "iptables -t nat -D PREROUTING -i mlan0 -p tcp -m tcp --dport $WIFIPORT -j DNAT --to-destination $PARROTIP:22" - sleep 1 - echo "iptables -t nat -I PREROUTING -i mlan0 -p tcp -m tcp --dport $WIFIPORT -j DNAT --to-destination $PARROTIP:22" - sleep 1 - echo "iptables -D INPUT -p tcp --dport $WIFIPORT -j ACCEPT" - sleep 1 - echo "iptables -I INPUT -p tcp --dport $WIFIPORT -j ACCEPT" - sleep 1 + echo + sleep 1 + echo + sleep 1 + echo "iptables -t nat -D PREROUTING -i mlan0 -p tcp -m tcp --dport $WIFIPORT -j DNAT --to-destination $PARROTIP:22" + sleep 1 + echo "iptables -t nat -I PREROUTING -i mlan0 -p tcp -m tcp --dport $WIFIPORT -j DNAT --to-destination $PARROTIP:22" + sleep 1 + echo "iptables -D INPUT -p tcp --dport $WIFIPORT -j ACCEPT" + sleep 1 + echo "iptables -I INPUT -p tcp --dport $WIFIPORT -j ACCEPT" + sleep 1 } | socat - tcp:parrot:telnet diff --git a/src/scripts/everyFiveMinutes/startstopvpn.sh b/src/scripts/everyFiveMinutes/startstopvpn.sh index 71775b7..6e84e52 100644 --- a/src/scripts/everyFiveMinutes/startstopvpn.sh +++ b/src/scripts/everyFiveMinutes/startstopvpn.sh @@ -1,16 +1,16 @@ #!/bin/bash file="$homeOfLunars/tesla.ovpn" -vpn=$(awk '/^dev /' $file | awk '{print $2}' ) +vpn=$(awk '/^dev /' $file | awk '{print $2}') if [ -z "$vpn" ]; then - echo "Script not yet setup, quitting" - exit 1 + echo "Script not yet setup, quitting" + exit 1 fi if grep -q "YOURIPADDRESSHERE" $file; then - echo "Script not yet setup, quitting" - exit 1 + echo "Script not yet setup, quitting" + exit 1 fi iptables -D INPUT -i $vpn -p tcp --dport 22 -j ACCEPT diff --git a/src/scripts/everyFiveMinutes/tokens-to-php.sh b/src/scripts/everyFiveMinutes/tokens-to-php.sh index 9b5fa4b..082d35b 100644 --- a/src/scripts/everyFiveMinutes/tokens-to-php.sh +++ b/src/scripts/everyFiveMinutes/tokens-to-php.sh @@ -5,4 +5,4 @@ if [[ "$urlToTokensPHP" =~ "yourserver" ]]; then exit 1 fi -curl -s -m 10 $urlToTokensPHP'?car='$( -" > $m_file +" >$m_file mail_from="Your Tesla <$m_from>" mail_to="The Master <$m_to>" @@ -42,20 +42,20 @@ mail_subject="Requested Screenshots" mail_reply_to="Your Tesla <$m_from>" mail_cc="" -function add_file { - echo "--MULTIPART-MIXED-BOUNDARY +function add_file() { + echo "--MULTIPART-MIXED-BOUNDARY Content-Type: $1 -Content-Transfer-Encoding: base64" >> "$m_data" +Content-Transfer-Encoding: base64" >>"$m_data" - if [ ! -z "$2" ]; then - echo "Content-Disposition: inline -Content-Id: <$2>" >> "$m_data" - else - echo "Content-Disposition: attachment; filename=$4" >> "$m_data" - fi - echo "$3 + if [ ! -z "$2" ]; then + echo "Content-Disposition: inline +Content-Id: <$2>" >>"$m_data" + else + echo "Content-Disposition: attachment; filename=$4" >>"$m_data" + fi + echo "$3 -" >> "$m_data" +" >>"$m_data" } message_base64=$(cat $m_file | base64) @@ -77,14 +77,14 @@ Content-Transfer-Encoding: base64 Content-Disposition: inline $message_base64 ---MULTIPART-ALTERNATIVE-BOUNDARY--" > "$m_data" +--MULTIPART-ALTERNATIVE-BOUNDARY--" >"$m_data" image_base64=$(cat $CIDPATH | base64) add_file "image/png" "png_cid.png" "$image_base64" image_base64=$(cat $ICPATH | base64) add_file "image/png" "png_ic.png" "$image_base64" -echo "--MULTIPART-MIXED-BOUNDARY--" >> "$m_data" +echo "--MULTIPART-MIXED-BOUNDARY--" >>"$m_data" curl -u $m_usr:$m_pwd -n --ssl-reqd --mail-from "<$m_from>" --mail-rcpt "<$m_to>" --url $server -T $m_data diff --git a/src/scripts/misc/get-versions.sh b/src/scripts/misc/get-versions.sh index 99bb898..1659afd 100644 --- a/src/scripts/misc/get-versions.sh +++ b/src/scripts/misc/get-versions.sh @@ -7,12 +7,12 @@ OFFLINEMOUNTPOINT="/offline-usr" ONLINEPART=$(cat /proc/self/mounts | grep "/usr" | grep ^/dev/mmcblk0p[12] | cut -b14) if [ "$ONLINEPART" == "1" ]; then - OFFLINEPART=2 + OFFLINEPART=2 elif [ "$ONLINEPART" == "2" ]; then - OFFLINEPART=1 + OFFLINEPART=1 else - echo "Error figuring out which partition is which." - exit 0 + echo "Error figuring out which partition is which." + exit 0 fi mkdir $OFFLINEMOUNTPOINT 2>/dev/null @@ -20,9 +20,9 @@ mkdir $OFFLINEMOUNTPOINT 2>/dev/null mount -o ro /dev/mmcblk0p$OFFLINEPART $OFFLINEMOUNTPOINT if [ ! -e "$OFFLINEMOUNTPOINT/deploy/platform.ver" ]; then - echo "Error mounting offline partition." - umount $OFFLINEMOUNTPOINT 2>/dev/null - exit 0 + echo "Error mounting offline partition." + umount $OFFLINEMOUNTPOINT 2>/dev/null + exit 0 fi NEWVER=$(cat "$OFFLINEMOUNTPOINT/tesla/UI/bin/version.txt" | cut -d= -f2 | cut -d\- -f1) diff --git a/src/scripts/misc/imgur.sh b/src/scripts/misc/imgur.sh index d67fbfc..5dcb836 100644 --- a/src/scripts/misc/imgur.sh +++ b/src/scripts/misc/imgur.sh @@ -13,7 +13,7 @@ readonly vid_max_size=200000000 readonly vid_body_key='video' function usage() { - cat < ... Upload an image, video or album to Imgur. @@ -24,87 +24,108 @@ EOF } function args() { - case "$1" in - '') usage; exit ;; - -h|--help) usage; exit ;; - -v|--version) printf '%s version %s\n' "$program" "$version"; exit ;; - -*) printf 'Invalid option: %s\n' "$1" 1>&2; exit 1 ;; - esac - shift + case "$1" in + '') + usage + exit + ;; + -h | --help) + usage + exit + ;; + -v | --version) + printf '%s version %s\n' "$program" "$version" + exit + ;; + -*) + printf 'Invalid option: %s\n' "$1" 1>&2 + exit 1 + ;; + esac + shift } function deps() { - local -r deps=("$@") - local missing_deps=() + local -r deps=("$@") + local missing_deps=() - for dep in "${deps[@]}"; do - if ! command -v "$dep" &>/dev/null; then - missing_deps+=("$dep") - fi - done - - if [[ "${#missing_deps[@]}" -gt 0 ]]; then - printf 'Missing dependancy: %s\n' "${missing_deps[@]}" 1>&2; exit 1 + for dep in "${deps[@]}"; do + if ! command -v "$dep" &>/dev/null; then + missing_deps+=("$dep") fi + done + + if [[ "${#missing_deps[@]}" -gt 0 ]]; then + printf 'Missing dependancy: %s\n' "${missing_deps[@]}" 1>&2 + exit 1 + fi } function mime() { - local -r mtype="$(file -b --mime-type "$1")" + local -r mtype="$(file -b --mime-type "$1")" - if [[ "$mtype" =~ ^('image/jpeg'|'image/gif'|'image/apng'|'image/tiff'|'image/png')$ ]]; then - return 1 - elif [[ "$mtype" =~ ^('video/webm'|'video/x-matroska'|'video/x-flv'|'video/x-msvideo'|'video/x-ms-wmv'|'video/mpeg')$ ]]; then - return 2 - fi + if [[ "$mtype" =~ ^('image/jpeg'|'image/gif'|'image/apng'|'image/tiff'|'image/png')$ ]]; then + return 1 + elif [[ "$mtype" =~ ^('video/webm'|'video/x-matroska'|'video/x-flv'|'video/x-msvideo'|'video/x-ms-wmv'|'video/mpeg')$ ]]; then + return 2 + fi - printf '%s has an unsupported MIME type (%s)\n' "$1" "$mtype" 1>&2; return 0 + printf '%s has an unsupported MIME type (%s)\n' "$1" "$mtype" 1>&2 + return 0 } function size() { - if [[ "$(stat "$stat_fmt" "$1")" -gt "$2" ]]; then - printf '%s is too large (max: %smb)\n' "$1" "$(expr $2 / 1000000)" 1>&2; return 0 - fi + if [[ "$(stat "$stat_fmt" "$1")" -gt "$2" ]]; then + printf '%s is too large (max: %smb)\n' "$1" "$(expr $2 / 1000000)" 1>&2 + return 0 + fi - return "$3" + return "$3" } function leng() { - return $2 + return $2 } function upld() { - resp="$(curl -s \ - --location \ - --request POST 'https://api.imgur.com/3/image' \ - --header "Authorization: Client-ID $client_id" \ - --form "$2=@$1")" - - err="$(jq -r '.data.error' <<< "$resp")" - if [[ "$err" != 'null' ]]; then - printf 'Error uploading %s (%s)\n' "$1" "$err" 1>&2; return 0 - fi - - uploaded+=("$(jq -r '.data.deletehash + ";" + .data.link' <<< "$resp")") + resp="$( + curl -s \ + --location \ + --request POST 'https://api.imgur.com/3/image' \ + --header "Authorization: Client-ID $client_id" \ + --form "$2=@$1" + )" + + err="$(jq -r '.data.error' <<<"$resp")" + if [[ "$err" != 'null' ]]; then + printf 'Error uploading %s (%s)\n' "$1" "$err" 1>&2 + return 0 + fi + + uploaded+=("$(jq -r '.data.deletehash + ";" + .data.link' <<<"$resp")") } function albm() { - form=() - for u in "${uploaded[@]}"; do - form+=(--form "deletehashes[]="$(cut -d';' -f1 <<< "$u")"") - done - - resp="$(curl -s \ - --location \ - --request POST 'https://api.imgur.com/3/album' \ - --header "Authorization: Client-ID $client_id" \ - "${form[@]}")" - - err="$(jq -r '.data.err' <<< "$resp")" - if [[ "$err" != 'null' ]]; then - printf 'Error creating album (%s)\n' "$1" "$err" 1>&2; return 0 - fi - - printf 'https://imgur.com/a/%s' "$(jq -r '.data.id' <<< "$resp")" + form=() + for u in "${uploaded[@]}"; do + form+=(--form "deletehashes[]="$(cut -d';' -f1 <<<"$u")"") + done + + resp="$( + curl -s \ + --location \ + --request POST 'https://api.imgur.com/3/album' \ + --header "Authorization: Client-ID $client_id" \ + "${form[@]}" + )" + + err="$(jq -r '.data.err' <<<"$resp")" + if [[ "$err" != 'null' ]]; then + printf 'Error creating album (%s)\n' "$1" "$err" 1>&2 + return 0 + fi + + printf 'https://imgur.com/a/%s' "$(jq -r '.data.id' <<<"$resp")" } # https://curl.haxx.se, https://stedolan.github.io/jq, https://linux.die.net/man/1/file @@ -123,29 +144,29 @@ esac # main. uploaded=() for i in "$@"; do - mime "$i" - - case "$?" in - '0') continue ;; - '1') size "$i" "$img_max_size" "$?" ;; - '2') size "$i" "$vid_max_size" "$?" ;; - esac - - case "$?" in - '0') continue ;; - '1') leng "$i" "$?" ;; - '2') leng "$i" "$?" ;; - esac - - case "$?" in - '0') continue ;; - '1') upld "$i" "$img_body_key" ;; - '2') upld "$i" "$vid_body_key" ;; - esac + mime "$i" + + case "$?" in + '0') continue ;; + '1') size "$i" "$img_max_size" "$?" ;; + '2') size "$i" "$vid_max_size" "$?" ;; + esac + + case "$?" in + '0') continue ;; + '1') leng "$i" "$?" ;; + '2') leng "$i" "$?" ;; + esac + + case "$?" in + '0') continue ;; + '1') upld "$i" "$img_body_key" ;; + '2') upld "$i" "$vid_body_key" ;; + esac done case "${#uploaded[@]}" in '0') printf 'No images uploaded.\n' ;; -'1') printf '%s' "$(cut -d';' -f2 <<< "${uploaded[0]}")" ;; +'1') printf '%s' "$(cut -d';' -f2 <<<"${uploaded[0]}")" ;; *) albm ;; esac diff --git a/src/scripts/misc/save-ap-footage.sh b/src/scripts/misc/save-ap-footage.sh index dc98522..c81cc3d 100644 --- a/src/scripts/misc/save-ap-footage.sh +++ b/src/scripts/misc/save-ap-footage.sh @@ -26,18 +26,18 @@ GIF_FORMAT="+%Y-%m-%d %H:%M:%S" date -r 1234 &>/dev/null && BSD=1 for d in */*; do - mogrify -format png -flip -crop 320x207+0+0 +repage "${d}/*.PGM" + mogrify -format png -flip -crop 320x207+0+0 +repage "${d}/*.PGM" - stamp=$(echo "${d}" | cut -c -8) - stamp=$((16#${stamp})) + stamp=$(echo "${d}" | cut -c -8) + stamp=$((16#${stamp})) - if [ -z $BSD ]; then - convert -loop 0 -delay $DELAY ${d}/*.png "$(date -d @${stamp} "${GIF_FORMAT}")-$(echo ${d} | cut -d / -f 2).gif" - else - convert -loop 0 -delay $DELAY ${d}/*.png "$(date -r ${stamp} "${GIF_FORMAT}")-$(echo ${d} | cut -d / -f 2).gif" - fi + if [ -z $BSD ]; then + convert -loop 0 -delay $DELAY ${d}/*.png "$(date -d @${stamp} "${GIF_FORMAT}")-$(echo ${d} | cut -d / -f 2).gif" + else + convert -loop 0 -delay $DELAY ${d}/*.png "$(date -r ${stamp} "${GIF_FORMAT}")-$(echo ${d} | cut -d / -f 2).gif" + fi - rm ${d}/*.png* + rm ${d}/*.png* done find . -type f ! -iregex '.*\.\(gif\|sh\)$' -delete diff --git a/src/scripts/misc/save-kernel.sh b/src/scripts/misc/save-kernel.sh index 3862970..9df034a 100644 --- a/src/scripts/misc/save-kernel.sh +++ b/src/scripts/misc/save-kernel.sh @@ -5,10 +5,10 @@ rm -rf cpio rm -rf _kernel*.extracted -dd if=cid-kernel.img bs=2048 skip=1 > kernel.lzf +dd if=cid-kernel.img bs=2048 skip=1 >kernel.lzf lzf -d kernel.lzf -ARCHIVE=$(binwalk -D gz kernel | grep gzip | tail -1 | egrep -oe " .* "| tr -d " " | sed -e 's/0x//') +ARCHIVE=$(binwalk -D gz kernel | grep gzip | tail -1 | egrep -oe " .* " | tr -d " " | sed -e 's/0x//') cd _kernel.extracted mv ${ARCHIVE} tesla.cpio.gz && gunzip tesla.cpio.gz @@ -16,7 +16,7 @@ mv ${ARCHIVE} tesla.cpio.gz && gunzip tesla.cpio.gz file * mkdir cpio cd cpio -cpio -idmv < ../tesla.cpio +cpio -idmv <../tesla.cpio cd ../../ diff --git a/src/scripts/misc/save-update.sh b/src/scripts/misc/save-update.sh index 0b10ab2..57bcc57 100644 --- a/src/scripts/misc/save-update.sh +++ b/src/scripts/misc/save-update.sh @@ -5,9 +5,9 @@ # Usage: bash save-update.sh HOST MODE &> output.log & -function die { - echo "ERROR: $1" >&2 - exit 1 +function die() { + echo "ERROR: $1" >&2 + exit 1 } [[ $# < 2 ]] && die "Must have arguments of bash save-update.sh ic|cid usb|internal|ssh|ftp" @@ -17,131 +17,131 @@ MODE="$2" me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" case $(ps -o stat= -p $$) in - *+*) die "Run this script in the background dummy: bash $me $1 $2 &> output.log &" ;; - *) echo "OK: Running in background" ;; +*+*) die "Run this script in the background dummy: bash $me $1 $2 &> output.log &" ;; +*) echo "OK: Running in background" ;; esac -function initializeVariables { - SSHSERVER="-p 22 tesla@yourserver.com" - FTPSERVER="username:password@ftp.example.com:21" +function initializeVariables() { + SSHSERVER="-p 22 tesla@yourserver.com" + FTPSERVER="username:password@ftp.example.com:21" } -function cleanFTPUsername { - # If FTP username has an @, replace with %40 - USERNAME=$(echo $FTPSERVER | cut -d: -f1) - ENCODEDUSERNAME=${USERNAME/@/%40} - FTPSERVER=${FTPSERVER/$USERNAME/$ENCODEDUSERNAME} +function cleanFTPUsername() { + # If FTP username has an @, replace with %40 + USERNAME=$(echo $FTPSERVER | cut -d: -f1) + ENCODEDUSERNAME=${USERNAME/@/%40} + FTPSERVER=${FTPSERVER/$USERNAME/$ENCODEDUSERNAME} } -function validateIC { - # Quick fail safe to move from cid to ic - if [ "$HOST" = ic ] && [ $(hostname) = cid ]; then - die "Run this script from ic" - fi +function validateIC() { + # Quick fail safe to move from cid to ic + if [ "$HOST" = ic ] && [ $(hostname) = cid ]; then + die "Run this script from ic" + fi } -function getFirmwareInfo { - PARTITIONPREFIX=$([ "$HOST" = ic ] && echo "mmcblk3p" || echo "mmcblk0p") - STATUS=$([ "$HOST" = ic ] && curl http://ic:21576/status || curl http://cid:20564/status) - NEWSIZE=$(echo "$STATUS" | grep 'Offline dot-model-s size:' | awk -F'size: ' '{print $2}' | awk '{print $1/64}') - NEWVER=$(echo "$STATUS" | awk -F'built for package version: ' '{print $2}' | sed 's/\s.*$//') - - # Ty kalud for finding offline part number - ONLINEPART=$(cat /proc/self/mounts | grep "/usr" | grep ^/dev/$PARTITIONPREFIX[12] | cut -b14) - if [ "$ONLINEPART" == "1" ]; then - OFFLINEPART=2 - elif [ "$ONLINEPART" == "2" ]; then - OFFLINEPART=1 - else - die "Could not determine offline partition" - fi +function getFirmwareInfo() { + PARTITIONPREFIX=$([ "$HOST" = ic ] && echo "mmcblk3p" || echo "mmcblk0p") + STATUS=$([ "$HOST" = ic ] && curl http://ic:21576/status || curl http://cid:20564/status) + NEWSIZE=$(echo "$STATUS" | grep 'Offline dot-model-s size:' | awk -F'size: ' '{print $2}' | awk '{print $1/64}') + NEWVER=$(echo "$STATUS" | awk -F'built for package version: ' '{print $2}' | sed 's/\s.*$//') + + # Ty kalud for finding offline part number + ONLINEPART=$(cat /proc/self/mounts | grep "/usr" | grep ^/dev/$PARTITIONPREFIX[12] | cut -b14) + if [ "$ONLINEPART" == "1" ]; then + OFFLINEPART=2 + elif [ "$ONLINEPART" == "2" ]; then + OFFLINEPART=1 + else + die "Could not determine offline partition" + fi } -function saveAPE { - APELOCATION="" - APELOCATIONONE="/home/cid-updater/ape-cache.ssq" - APELOCATIONTWO="/home/cid-updater/ape.ssq" - [ -f $APELOCATIONONE ] && APELOCATION=$APELOCATIONONE - [ -f $APELOCATIONTWO ] && APELOCATION=$APELOCATIONTWO - - if [ -z "$APELOCATION" ]; then - echo "Skipping transfer of APE, did not find ssq file" - return - fi - - echo "Found APE image at $APELOCATION" - - # Download gateway config in case it doesn't exist - echo "Attempting to download gateway config..." - [ -x "$(command -v get-gateway-config.sh)" ] && [ "$HOST" = cid ] && bash get-gateway-config.sh - - APE="ape0" - MODEL=$(< /var/etc/dashw) - - [ "$MODEL" == 2 ] && APE="ape2" - [ "$MODEL" == 3 ] && APE="ape25" - [[ "$MODEL" -ge 4 ]] && APE="ape3" - - if [ "$APE" == "ape0" ]; then - echo "Found ape image but could not determine APE version from dashw: $MODEL" - echo "Defaulting to .ape0 so we still save this file" - fi - - if [ "$MODE" = internal ]; then - cp $APELOCATION /tmp/$NEWVER.$APE - elif [ "$MODE" = usb ]; then - sudo mount -o rw,noexec,nodev,noatime,utf8 /dev/sda1 /disk/usb.*/ - cp $APELOCATION /disk/usb.*/$NEWVER.$APE - sync - umount /disk/usb.*/ - elif [ "$MODE" = ssh ]; then - scp $APELOCATION $SSHSERVER:~/$NEWVER.$APE - elif [ "$MODE" = ftp ]; then - curl -T $APELOCATION ftp://$FTPSERVER/~/$NEWVER.$APE - fi +function saveAPE() { + APELOCATION="" + APELOCATIONONE="/home/cid-updater/ape-cache.ssq" + APELOCATIONTWO="/home/cid-updater/ape.ssq" + [ -f $APELOCATIONONE ] && APELOCATION=$APELOCATIONONE + [ -f $APELOCATIONTWO ] && APELOCATION=$APELOCATIONTWO + + if [ -z "$APELOCATION" ]; then + echo "Skipping transfer of APE, did not find ssq file" + return + fi + + echo "Found APE image at $APELOCATION" + + # Download gateway config in case it doesn't exist + echo "Attempting to download gateway config..." + [ -x "$(command -v get-gateway-config.sh)" ] && [ "$HOST" = cid ] && bash get-gateway-config.sh + + APE="ape0" + MODEL=$(/dev/null 2>&1 & +function scriptBackground() { + bash "$1" >/dev/null 2>&1 & } -function beginScript { - printf "Found $1... " - if ! isRunning $1; then - printf "Starting\n" - scriptBackground $1 - else - printf "Already running\n" - fi +function beginScript() { + printf "Found $1... " + if ! isRunning $1; then + printf "Starting\n" + scriptBackground $1 + else + printf "Already running\n" + fi } -function main { - for scriptPath in "${scheduledScripts[@]}"; do - beginScript $scriptPath - done +function main() { + for scriptPath in "${scheduledScripts[@]}"; do + beginScript $scriptPath + done - # Five minutes - while true; do - for scriptPath in "${everyFiveMinuteScripts[@]}"; do - beginScript $scriptPath - done - echo "Waiting 5 minutes..." - sleep 300 + # Five minutes + while true; do + for scriptPath in "${everyFiveMinuteScripts[@]}"; do + beginScript $scriptPath done + echo "Waiting 5 minutes..." + sleep 300 + done } main