From 3608a8c71d918002b7f465c0ae1c3bbc4ba5071f Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 19 Sep 2020 15:51:34 +0100 Subject: [PATCH] check for root - user feedback --- 7.2-install.txt | 7 +++++++ iiab-upgrade | 30 +++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/7.2-install.txt b/7.2-install.txt index 652ed227..56a650ae 100644 --- a/7.2-install.txt +++ b/7.2-install.txt @@ -70,6 +70,13 @@ case $OS_VER in ;; esac +# Everything else needs to be run as root +if [ $(id -u) -ne 0 ]; then + echo -e "$SCRIPT must be run as root. Try 'sudo $SCRIPT'\n" + exit 1 +fi + + echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASE ...\n" /usr/bin/apt -y install git nano whiptail mkdir -p $BASE diff --git a/iiab-upgrade b/iiab-upgrade index 49c4e000..2bf67d0c 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -18,6 +18,7 @@ UPDATE=0 MASTER=1 MIN_RPI_KERN=1336 SELFUPDATE_SCRIPT="/tmp/.updateScript.sh" + # scrape the command line if [ "$1" = "--interactive" ]; then shift 1 @@ -43,13 +44,24 @@ CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` echo "Found Kernel ""$CURR_KERN" if version_gt $MIN_RPI_KERN $CURR_KERN; then echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" - echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" + echo -e "\033[31;5mPLEASE RUN 'sudo apt update' then 'sudo apt install raspberrypi-kernel' then reboot.\033[0m" echo -e "\033[31;5mTHEN recheck the kernel version with iiab-upgrade --kernel-check \033[0m" - echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel \033[0m" - echo -e "\033[31;5mPlease check with developers before running the above command" + echo -e "\033[31;5mPlease check with developers before running the below command" + echo -e "\033[31;5mTHEN IF NEC run 'sudo rpi-update' to install a more recent kernel \033[0m" fi } +if [ "$1" = "--kernel-check" ]; then + check_kernel + exit 0 +fi + +# Everything else needs to be run as root +if [ $(id -u) -ne 0 ]; then + echo -e "$SCRIPT must be run as root. Try 'sudo $SCRIPT'\n" + exit 1 +fi + # Subroutines for upgrade logic check_branch(){ git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l @@ -104,7 +116,6 @@ function update_master(){ fi } - function check_revision(){ if [ -f $IIABENV ]; then source $IIABENV @@ -157,11 +168,6 @@ check_user_pwd() { } # start exec here -if [ "$1" = "--kernel-check" ]; then - check_kernel - exit 0 -fi - update_self if [ `check_branch` -gt 0 ]; then @@ -343,11 +349,9 @@ fi echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" echo -e "│ │" -echo -e "│ NOW INSTALL IIAB SOFTWARE! If glitches arise (connectivity or otherwise) │" -echo -e "│ │" -echo -e "│ PLEASE TRY TO CONTINUE BY RE-RUNNING PARENT SCRIPT 'sudo iiab' -- or run │" +echo -e "│ NOW UPGRADE IIAB SOFTWARE! If glitches arise (connectivity or otherwise) │" echo -e "│ │" -echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 stages. │" +echo -e "│ PLEASE TRY TO CONTINUE BY RE-RUNNING SCRIPT 'sudo iiab-upgrade' │" echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" cd $BASEDIR/iiab/