From 8df5078b3d6db6b49b6aaaaa77805006149e01c9 Mon Sep 17 00:00:00 2001 From: Stephan Wendel Date: Fri, 12 Aug 2022 21:58:47 +0200 Subject: [PATCH] refactor: refactor of User input during install Show default answers in case of user only hits enter. Includes fix: Install on rpi bullseye fails This also should fix #24 Signed-off-by: Stephan Wendel --- bin/Makefile | 20 ++++-- .../{config.rpi-bullseye => config.bullseye} | 0 tools/{config.rpi-buster => config.buster} | 0 tools/install.sh | 72 ++++++++++++------- tools/uninstall.sh | 33 +++++---- 5 files changed, 81 insertions(+), 44 deletions(-) rename tools/{config.rpi-bullseye => config.bullseye} (100%) rename tools/{config.rpi-buster => config.buster} (100%) diff --git a/bin/Makefile b/bin/Makefile index 160be92..772d16f 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -30,18 +30,26 @@ MAKEFLAGS += -j$(shell nproc) # OpenMAX IL Support OMX_SUPPORT = $(shell [ -d /opt/vc/include ] && echo 1 || echo 0) +# Ustreamer cloned? +USTREAMER_EXIST = $(shell [ -d ustreamer ] > /dev/null && echo 1 || echo 0) + all: - $(MAKE) ustreamer +ifeq ($(USTREAMER_EXIST), 0) + $(info INFO: ustreamer not found, cloning repository.) + $(shell git clone $(USTREAMER_REPO) ustreamer) +else + $(info INFO: ustreamer found.) +endif + $(MAKE) ustreamer-bin $(MAKE) rtsp # Build ustreamer -ustreamer: - $(shell if ! [ -d "bin/ustreamer" ]; then \ - git clone $(USTREAMER_REPO) ustreamer; fi) +ustreamer-bin: ifeq ($(OMX_SUPPORT), 1) - $(shell cd ustreamer; git reset -q --hard $(USTREAMER_OMX_BRANCH) &> /dev/null \ - ; cd ..) $(info Compiling ustreamer with OMX Support.) + $(info Changening to commit '$(USTREAMER_OMX_BRANCH)' ) + $(shell cd ustreamer; git reset -q --hard $(USTREAMER_OMX_BRANCH) \ + ; cd ..) WITH_OMX=1 $(MAKE) -C $(USTREAMER_PATH) else $(info Compiling ustreamer without OMX Support.) diff --git a/tools/config.rpi-bullseye b/tools/config.bullseye similarity index 100% rename from tools/config.rpi-bullseye rename to tools/config.bullseye diff --git a/tools/config.rpi-buster b/tools/config.buster similarity index 100% rename from tools/config.rpi-buster rename to tools/config.buster diff --git a/tools/install.sh b/tools/install.sh index 1c83f12..63ddc01 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -111,19 +111,17 @@ function import_config { ## rpi os buster if [ "$(uname -m)" != "x86_64" ] && - [ "$(cut -d " " -f1 < /proc/device-tree/model)" == "Raspberry" ] && [ "$(get_os_version buster)" != "0" ] && [ -f "tools/config.rpi-buster" ]; then # shellcheck disable=SC1091 - source tools/config.rpi-buster + source tools/config.buster return 0 fi - ## rpi os bullseye + ## bullseye if [ "$(uname -m)" != "x86_64" ] && [ "$(get_os_version bullseye)" != "0" ] && - [ "$(cut -d " " -f1 < /proc/device-tree/model)" == "Raspberry" ] && - [ -f "tools/config.rpi-bullseye" ]; then + [ -f "tools/config.bullseye" ]; then # shellcheck disable=SC1091 source tools/config.bullseye return 0 @@ -174,17 +172,27 @@ function detect_existing_webcamd { local remove if [ -x "/usr/local/bin/webcamd" ] && [ -d "${HOME}/mjpg-streamer" ]; then detect_msg - read -rp "Do you want to remove existing 'webcamd'? (YES/NO) " remove - if [ "${remove}" = "YES" ]; then - echo -en "\nStopping webcamd.service ...\r" - sudo systemctl stop webcamd.service &> /dev/null - echo -e "Stopping webcamd.service ... \t[OK]\r" - remove_existing_webcamd - else - echo -e "\nYou answered '${remove}'! Installation will be aborted..." - echo -e "GoodBye...\n" - exit 1 - fi + read -erp "Do you want to remove existing 'webcamd'? (y/N) " -i "N" remove + case "${remove}" in + y|Y|yes|Yes|YES) + echo -en "\nStopping webcamd.service ...\r" + sudo systemctl stop webcamd.service &> /dev/null + echo -e "Stopping webcamd.service ... \t[OK]\r" + remove_existing_webcamd + ;; + + n|N|no|No|NO) + echo -e "\nYou have to remove webcamd to use crowsnest!" + echo -e "Installation will be aborted..." + echo -e "GoodBye...\n" + exit 1 + ;; + *) + echo -e "\nYou answered '${remove}'! Invalid input ... [EXITING]" + echo -e "GoodBye...\n" + exit 1 + ;; + esac fi } @@ -294,7 +302,7 @@ function install_crowsnest { fi ## enable crowsnest.service echo -en "Enable crowsnest.service on boot ...\r" - sudo systemctl enable crowsnest.service + sudo systemctl enable crowsnest.service &> /dev/null echo -e "Enable crowsnest.service on boot ... [OK]\r" ## Add moonraker update manager entry ## Unattended @@ -308,16 +316,28 @@ function install_crowsnest { ## Manual install if [ "${UNATTENDED}" != "true" ] && [ "${CROWSNEST_ADD_CROWSNEST_MOONRAKER}" != "0" ]; then - read -rp "Do you want to add [update_manager] entry?(y/n) " addconf - case "${addconf}" in - y*|Y*) - add_update_entry - ;; + while true; do + read -erp "Do you want to add [update_manager] entry? (y/N) " -i "N" addconf + case "${addconf}" in + y|Y|yes|Yes|YES) + if [ "$(grep -c "crowsnest" "${moonraker_conf}")" == "0" ]; then + add_update_entry + else + echo -e "Update Manager entry already exists moonraker.conf ... [SKIPPED]" + fi + break + ;; - n*|N*) - echo -e "Adding Crowsnest Update Manager entry to moonraker.conf ... [SKIPPED]" - ;; - esac + n|N|no|No|NO) + echo -e "Adding Crowsnest Update Manager entry to moonraker.conf ... [SKIPPED]" + break + ;; + + *) + echo -e "\nInvalid input, please try again." + ;; + esac + done fi ## add $USER to group video diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 676bb36..b821d01 100755 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -72,17 +72,26 @@ trap 'err_exit $? $LINENO' ERR function ask_uninstall { local remove if [ -x "/usr/local/bin/crowsnest" ] && [ -d "${HOME}/crowsnest" ]; then - read -rp "Do you REALLY want to remove existing 'crowsnest'? (YES/NO) " remove - if [ "${remove}" = "YES" ]; then - uninstall_crowsnest - remove_raspicam_fix - remove_logrotate - goodbye_msg - else - echo -e "\nYou answered '${remove}'! Uninstall will be aborted..." - echo -e "GoodBye...\n" - exit 1 - fi + while true; do + read -erp "Do you REALLY want to remove existing 'crowsnest'? (y/N) " -i "N" remove + case "${remove}" in + y|Y|yes|Yes|YES) + uninstall_crowsnest + remove_raspicam_fix + remove_logrotate + goodbye_msg + break + ;; + n|N|no|No|NO) + echo -e "\nYou answered '${remove}'! Uninstall will be aborted..." + echo -e "GoodBye...\n" + exit 1 + ;; + *) + echo -e "\nInvalid input, please try again." + ;; + esac + done else echo -e "\n'crowsnest' seems not installed." echo -e "Exiting. GoodBye ..." @@ -98,7 +107,7 @@ function uninstall_crowsnest { echo -e "Stopping crowsnest.service ... \t[OK]\r" echo -en "\nDisable crowsnest.service ...\r" sudo systemctl disable crowsnest.service &> /dev/null - echo -e "Disablecrowsnest.service ... \t[OK]\r" + echo -e "Disable crowsnest.service ... \t[OK]\r" echo -en "Uninstalling crowsnest.service...\r" if [ -f "${servicefile}" ]; then sudo rm -f "${servicefile}"