Skip to content

Commit

Permalink
refactor: refactor of User input during install
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
KwadFan committed Aug 13, 2022
1 parent 2fb45c3 commit e294c11
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 35 deletions.
68 changes: 45 additions & 23 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function import_config {
[ "$(cut -d " " -f1 < /proc/device-tree/model)" == "Raspberry" ] &&
[ -f "tools/config.rpi-bullseye" ]; then
# shellcheck disable=SC1091
source tools/config.bullseye
source tools/config.rpi-bullseye
return 0
fi

Expand Down Expand Up @@ -174,17 +174,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
}

Expand Down Expand Up @@ -294,7 +304,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
Expand All @@ -308,16 +318,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
;;

n*|N*)
echo -e "Adding Crowsnest Update Manager entry to moonraker.conf ... [SKIPPED]"
;;
esac
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|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
Expand Down
33 changes: 21 additions & 12 deletions tools/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand All @@ -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}"
Expand Down

0 comments on commit e294c11

Please sign in to comment.