#!/bin/bash # Function to detect the platform and set the shell accordingly detect_platform() { echo "Detecting OS" if [ -f /system/bin/sh ]; then SHELL_PATH="/system/bin/sh" echo "Android detected, using ${SHELL_PATH}." ANDROID=1 elif [ -f /bin/bash ]; then SHELL_PATH="/bin/bash" echo "LE/Linux Embedded detected, using ${SHELL_PATH}." ANDROID=0 else echo "Unknown platform, exiting." exit 1 fi } # Function to print styled messages print_message() { local COLOR="\e[1;93m" local ENDCOLOR="\e[0m" echo -e "${COLOR}${1}${ENDCOLOR}" } # Function to detect head generation detect_head_generation() { echo "Detecting Head Generation:" if test -b /dev/block/bootdevice/by-name/facrec; then echo "This is a DVT1" DVT1=1 else echo "Not DVT1" fi if [ "${ANDROID}" == 1 ]; then if [ "${DVT1}" == 0 ] && [ -d /data/data/com.anki.cozmoengine ]; then echo "This Vector is a P1 or P2 prototype. It is recommended you dump a new flash dump with QDL." exit 0 elif [ "${DVT1}" == 0 ] && [ ! -d /data/data/com.anki.cozmoengine ]; then echo "Anything Vector related was not found. Is this a phone/tablet? Exiting." exit 0 fi fi test -b /dev/block/bootdevice/by-name/templabel && echo "This is a DVT2." && DVT2=1 || echo "Not DVT2." test -b /dev/block/bootdevice/by-name/system_b && echo "This is a DVT3 or above." && DVT3=1 || echo "Not DVT3. I'm confused." CMDLINE=$(cat /proc/cmdline) [[ "${CMDLINE}" == *"anki.dev"* ]] && echo "There is anki.dev." && ANKIDEV=1 || echo "No anki.dev." if [ ${DVT3} == 1 ]; then BUILDPROP=$(cat /build.prop) if [[ ${BUILDPROP} == *"oskr"* ]]; then echo "This is an OSKR bot." OSKR=1 else echo "This is either a Whiskey or dev bot." OSKR=0 if [[ ${OSKR} == 0 ]] && [[ ${ANKIDEV} == 1 ]]; then echo "This is an ankidev bot, not OSKR." WHISKEY=0 else echo "This is a Whiskey DVT1, early Victor DVT4, or early Victor DVT3." WHISKEY=1 fi fi fi } # Function to echo current detected states for debugging echo_current_states() { echo "Echoing current strings:" for var in ANDROID DVT1 DVT2 DVT3 OSKR WHISKEY ANKIDEV; do echo "${var}: ${!var}" done } # Function for user confirmation prompt user_confirmation() { while true; do echo "$1 (yes/no then enter): " read yn < /dev/tty case $yn in [Yy]*) break;; [Nn]*) echo "Exiting."; exit;; wire) echo "Continuing, and using local IP for upgrade."; WIREADDRESS=192.168.1.2; break;; *) echo "Please answer yes or no.";; esac done } # Function to handle upgrades based on the detected configuration perform_upgrade() { if [[ ${OSKR} == 1 ]] && [[ ${DVT3} == 1 ]]; then echo "This script will upgrade this OSKR bot to Wire's firmware." user_confirmation "Would you like to continue?" mount -o rw,remount / curl -o /updatescript http://ota.pvic.xyz:80/update-engine chmod 755 /updatescript rm -f /anki/bin/update-engine print_message "The bot will now begin the update!" update-os http://${WIREADDRESS}:80/vic/raw/oskr/latest.ota fi if [[ ${ANKIDEV} == 1 ]] && [[ ${DVT3} == 1 ]]; then echo "This script will upgrade this Ankidev bot to Wire's firmware." user_confirmation "Would you like to continue?" mount -o rw,remount / curl -o /updatescript http://ota.pvic.xyz:80/update-engine chmod 755 /updatescript rm -f /anki/bin/update-engine print_message "The bot will now begin the update!" /updatescript http://${WIREADDRESS}:80/vic/raw/dev/latest.ota -v && echo -e "\nAll done! Rebooting..." && reboot && exit || echo "Update failed" && exit 0 fi if [[ ${DVT1} == 1 ]] && [[ ${ANDROID} == 1 ]]; then echo "This script will upgrade your Android DVT1 to Wire's firmware." user_confirmation "Would you like to continue?" curl http://wire.my.to:81/upgradedvt1init.sh | /system/bin/sh fi if [[ ${DVT2} == 1 ]] && [[ ${ANKIDEV} == 0 ]]; then echo "This script will upgrade your DVT2 to Wire's firmware." user_confirmation "Would you like to continue?" echo "Not implemented yet." fi } # Main script execution starts here ANDROID=0 DVT1=0 DVT2=0 DVT3=0 OSKR=0 WHISKEY=0 ANKIDEV=0 WIREADDRESS="ota.pvic.xyz" clear set -e detect_platform echo -e "\n" print_message "Enlighten Vector" echo -e "\n" detect_head_generation echo -e "\n" echo_current_states echo -e "\n" if [ "$EUID" -ne 0 ]; then echo "This script must be run as root." exit else echo "Root check passed." fi echo -e "\n" perform_upgrade echo -e "\nAll tasks completed."