chore: changed userinput style

Contains also indentation to two spaces instead of four

as requested by th33xitus

Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
Stephan Wendel
2023-01-26 20:54:33 +01:00
parent 12175681c4
commit 08dbafa087

View File

@@ -15,150 +15,153 @@
# https://github.com/KwadFan/crowsnest # # https://github.com/KwadFan/crowsnest #
#=======================================================================# #=======================================================================#
# shellcheck enable=require-variable-braces
# shellcheck disable=SC2154
# Error Handling # Error Handling
set -e set -e
# Helper messages # Helper messages
function multi_instance_message(){ function multi_instance_message(){
echo -e "Crowsnest is NOT designed to support Multi Instances." echo -e "Crowsnest is NOT designed to support Multi Instances."
echo -e "A Workaround for this is to choose the most used instance as a 'master'" echo -e "A Workaround for this is to choose the most used instance as a 'master'"
echo -e "Use this instance to setup your 'crowsnest.conf' and steering it's service.\n" echo -e "Use this instance to setup your 'crowsnest.conf' and steering it's service.\n"
echo -e "Found the following instances:\n" echo -e "Found the following instances:\n"
for i in ${1}; do for i in ${1}; do
select_msg "${i}" select_msg "${i}"
done done
echo -e "\nLaunching crowsnest's configuration tool ..." echo -e "\nLaunching crowsnest's configuration tool ..."
continue_config continue_config
} }
# Helper funcs # Helper funcs
function clone_crowsnest(){ function clone_crowsnest(){
$(command -v git) clone "${CROWSNEST_REPO}" -b master "${CROWSNEST_DIR}" $(command -v git) clone "${CROWSNEST_REPO}" -b master "${CROWSNEST_DIR}"
} }
function check_multi_instance(){ function check_multi_instance(){
local -a instances local -a instances
readarray -t instances < <(find "${HOME}" -regex "${HOME}/[a-zA-Z0-9_]+_data/*" -printf "%P\n" 2> /dev/null | sort) readarray -t instances < <(find "${HOME}" -regex "${HOME}/[a-zA-Z0-9_]+_data/*" -printf "%P\n" 2> /dev/null | sort)
if [[ "${#instances[@]}" -gt 1 ]]; then if [[ "${#instances[@]}" -gt 1 ]]; then
status_msg "Multi Instance Install detected ..." status_msg "Multi Instance Install detected ..."
multi_instance_message "${instances[*]}" multi_instance_message "${instances[*]}"
if [[ -d "${HOME}/crowsnest" ]]; then if [[ -d "${HOME}/crowsnest" ]]; then
pushd "${HOME}/crowsnest" &> /dev/null || exit 1 pushd "${HOME}/crowsnest" &> /dev/null || exit 1
if ! make config ;then if ! make config ;then
error_msg "Something went wrong! Please try again..." error_msg "Something went wrong! Please try again..."
if [[ -f "tools/.config" ]]; then if [[ -f "tools/.config" ]]; then
rm -f tools/.config rm -f tools/.config
fi
exit 1
fi
if [[ ! -f "tools/.config" ]]; then
log_error "failure while generating .config"
error_msg "Generating .config failed, installation aborted"
exit 1
fi
popd &> /dev/null || exit 1
fi fi
exit 1
fi
if [[ ! -f "tools/.config" ]]; then
log_error "failure while generating .config"
error_msg "Generating .config failed, installation aborted"
exit 1
fi
popd &> /dev/null || exit 1
fi fi
fi
} }
function continue_config() { function continue_config() {
local reply local reply
while true; do while true; do
read -erp "Continue? [Y/n]: " -i "Y" reply read -erp "${cyan}###### Continuing with configuration? (y/N):${white} " reply
case "${reply}" in case "${reply}" in
[Yy]* ) [Yy]* )
break break
;; ;;
[Nn]* ) [Nn]* )
warn_msg "Installation aborted by user ... Exiting!" warn_msg "Installation aborted by user ... Exiting!"
exit 1 exit 1
;; ;;
* ) * )
echo -e "\e[31mERROR: Please type Y or N !\e[0m" echo -e "\e[31mERROR: Please type Y or N !\e[0m"
;; ;;
esac esac
done done
return 0 return 0
} }
# Install func # Install func
function install_crowsnest(){ function install_crowsnest(){
# Step 1: jump to home directory # Step 1: jump to home directory
pushd "${HOME}" &> /dev/null || exit 1 pushd "${HOME}" &> /dev/null || exit 1
# Step 2: Clone crowsnest repo # Step 2: Clone crowsnest repo
status_msg "Cloning 'crowsnest' repository ..." status_msg "Cloning 'crowsnest' repository ..."
if [[ ! -d "${HOME}/crowsnest" ]] && if [[ ! -d "${HOME}/crowsnest" ]] &&
[[ -z "$(ls -A "${HOME}/crowsnest")" ]]; then [[ -z "$(ls -A "${HOME}/crowsnest")" ]]; then
clone_crowsnest clone_crowsnest
else else
ok_msg "crowsnest repository already exists ..." ok_msg "crowsnest repository already exists ..."
fi fi
# Step 3: Install dependencies # Step 3: Install dependencies
# status_msg "Install basic dependencies ..." # status_msg "Install basic dependencies ..."
# install_basic_deps # install_basic_deps
dependency_check git make dependency_check git make
# Step 4: Check for Multi Instance # Step 4: Check for Multi Instance
check_multi_instance check_multi_instance
# Step 5: Launch crowsnest installer # Step 5: Launch crowsnest installer
pushd "${HOME}/crowsnest" &> /dev/null || exit 1 pushd "${HOME}/crowsnest" &> /dev/null || exit 1
title_msg "Installer will prompt you for sudo password!" title_msg "Installer will prompt you for sudo password!"
status_msg "Launching crowsnest installer ..." status_msg "Launching crowsnest installer ..."
if ! sudo make install; then if ! sudo make install; then
error_msg "Something went wrong! Please try again..." error_msg "Something went wrong! Please try again..."
exit 1 exit 1
fi fi
# Step 5: Leave directory (twice due two pushd) # Step 5: Leave directory (twice due two pushd)
popd &> /dev/null || exit 1 popd &> /dev/null || exit 1
popd &> /dev/null || exit 1 popd &> /dev/null || exit 1
} }
# Remove func # Remove func
function remove_crowsnest(){ function remove_crowsnest(){
pushd "${HOME}/crowsnest" &> /dev/null || exit 1 pushd "${HOME}/crowsnest" &> /dev/null || exit 1
title_msg "Uninstaller will prompt you for sudo password!" title_msg "Uninstaller will prompt you for sudo password!"
status_msg "Launching crowsnest Uninstaller ..." status_msg "Launching crowsnest Uninstaller ..."
if ! make uninstall; then if ! make uninstall; then
error_msg "Something went wrong! Please try again..." error_msg "Something went wrong! Please try again..."
exit 1 exit 1
fi fi
if [[ -e "${CROWSNEST_DIR}" ]]; then if [[ -e "${CROWSNEST_DIR}" ]]; then
status_msg "Removing Crowsnest directory ..." status_msg "Removing Crowsnest directory ..."
rm -rf "${CROWSNEST_DIR}" rm -rf "${CROWSNEST_DIR}"
fi fi
} }
# Status funcs # Status funcs
get_crowsnest_status(){ get_crowsnest_status(){
local -a files local -a files
files=( files=(
"${CROWSNEST_DIR}" "${CROWSNEST_DIR}"
"/usr/local/bin/crowsnest" "/usr/local/bin/crowsnest"
"/etc/logrotate.d/crowsnest" "/etc/logrotate.d/crowsnest"
"/etc/systemd/system/crowsnest.service" "/etc/systemd/system/crowsnest.service"
"$(find "${HOME}" -name 'crowsnest.env' 2> /dev/null || "$(find "${HOME}" -name 'crowsnest.env' 2> /dev/null ||
echo "${HOME}/printer_data/systemd/crowsnest.env")" echo "${HOME}/printer_data/systemd/crowsnest.env")"
) )
# Contains ugly hackaround for multi instance... :( # Contains ugly hackaround for multi instance... :(
local count local count
count=0 count=0
for file in "${files[@]}"; do for file in "${files[@]}"; do
[[ -e "${file}" ]] && count=$(( count +1 )) [[ -e "${file}" ]] && count=$(( count +1 ))
done done
if [[ "${count}" -eq "${#files[*]}" ]]; then if [[ "${count}" -eq "${#files[*]}" ]]; then
echo "Installed" echo "Installed"
elif [[ "${count}" -gt 0 ]]; then elif [[ "${count}" -gt 0 ]]; then
echo "Incomplete!" echo "Incomplete!"
else else
echo "Not installed!" echo "Not installed!"
fi fi
} }
# Update funcs # Update funcs