style: improve code-style and fix some shellcheck warnings

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-05-18 22:31:32 +02:00
parent 386ba3a0be
commit 435b1f46a8
24 changed files with 419 additions and 222 deletions

View File

@@ -28,6 +28,8 @@ function advanced_ui() {
function advanced_menu() {
do_action "" "advanced_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -31,6 +31,8 @@ function backup_ui() {
function backup_menu() {
do_action "" "backup_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -36,6 +36,7 @@ function install_menu() {
clear && print_header
install_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -45,34 +45,39 @@ function print_kiauh_version() {
function print_status() {
local status component="${1}"
status=$(get_"${component}"_status)
if [ "${status}" == "Not installed!" ]; then
if [[ ${status} == "Not installed!" ]]; then
status="${red}${status}${white}"
elif [ "${status}" == "Incomplete!" ]; then
elif [[ ${status} == "Incomplete!" ]]; then
status="${yellow}${status}${white}"
else
status="${green}${status}${white}"
fi
printf "%-28s" "${status}"
}
function print_klipper_repo() {
read_kiauh_ini
local repo klipper_status
klipper_status=$(get_klipper_status)
repo=$(echo ${custom_klipper_repo} | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
repo=$(echo "${custom_klipper_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//")
repo="${repo^^}"
if [[ "${klipper_status}" == "Not installed!" ]]; then
if [[ ${klipper_status} == "Not installed!" ]]; then
repo="${red}-${white}"
elif [[ -n "${repo}" && "${repo}" != "KLIPPER3D/KLIPPER" ]]; then
elif [[ -n ${repo} && ${repo} != "KLIPPER3D/KLIPPER" ]]; then
repo="${cyan}custom${white}"
else
repo="${cyan}Klipper3d/klipper${white}"
fi
printf "%-28s" "${repo}"
}
function kiauh_update_dialog() {
[ ! "$(kiauh_update_avail)" == "true" ] && return
[[ ! $(kiauh_update_avail) == "true" ]] && return
top_border
echo -e "|${green} New KIAUH update available! ${white}|"
hr
@@ -82,15 +87,18 @@ function kiauh_update_dialog() {
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
echo -e "|${yellow} features. Please consider updating! ${white}|"
bottom_border
local yn
read -p "${cyan}Do you want to update now? (Y/n):${white} " yn
while true; do
case "${yn}" in
Y|y|Yes|yes|"")
do_action "update_kiauh"
break;;
N|n|No|no) break;;
*)
deny_action "kiauh_update_dialog";;
Y|y|Yes|yes|"")
do_action "update_kiauh"
break;;
N|n|No|no)
break;;
*)
deny_action "kiauh_update_dialog";;
esac
done
}
@@ -100,6 +108,8 @@ function main_menu() {
#prompt for KIAUH update if update available
kiauh_update_dialog
main_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -32,6 +32,8 @@ function remove_ui() {
function remove_menu() {
do_action "" "remove_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -13,6 +13,7 @@ set -e
function settings_ui() {
read_kiauh_ini "${FUNCNAME[0]}"
local custom_cfg_loc="${custom_klipper_cfg_loc}"
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
@@ -21,37 +22,42 @@ function settings_ui() {
local bbu="${backup_before_update}"
### config location
if [ -z "${custom_cfg_loc}" ]; then
if [[ -z ${custom_cfg_loc} ]]; then
custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
else
custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
fi
### custom repository
custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
if [ -z "${custom_repo}" ]; then
if [[ -z ${custom_repo} ]]; then
custom_repo="${cyan}Klipper3D/klipper${white}"
else
custom_repo="${cyan}${custom_repo}${white}"
fi
### custom repository branch
if [ -z "${custom_branch}" ]; then
if [[ -z ${custom_branch} ]]; then
custom_branch="${cyan}master${white}"
else
custom_branch="${cyan}${custom_branch}${white}"
fi
### webinterface stable toggle
if [ "${ms_pre_rls}" == "false" ]; then
if [[ ${ms_pre_rls} == "false" ]]; then
ms_pre_rls="${red}${ms_pre_rls}${white}"
else
ms_pre_rls="${green}${ms_pre_rls}${white}"
fi
if [ "${fl_pre_rls}" == "false" ]; then
if [[ ${fl_pre_rls} == "false" ]]; then
fl_pre_rls="${red}${fl_pre_rls}${white}"
else
fl_pre_rls="${green}${fl_pre_rls}${white}"
fi
### backup before update toggle
if [ "${bbu}" == "false" ]; then
if [[ "${bbu}" == "false" ]]; then
bbu="${red}${bbu}${white}"
else
bbu="${green}${bbu}${white}"
@@ -74,18 +80,18 @@ function settings_ui() {
echo -e "| 1) Change Klipper config folder location |"
echo -e "| 2) Set custom Klipper repository |"
blank_line
if [ "${mainsail_install_unstable}" == "false" ]; then
if [[ ${mainsail_install_unstable} == "false" ]]; then
echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |"
else
echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |"
fi
if [ "${fluidd_install_unstable}" == "false" ]; then
if [[ ${fluidd_install_unstable} == "false" ]]; then
echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |"
else
echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |"
fi
blank_line
if [ "${backup_before_update}" == "false" ]; then
if [[ ${backup_before_update} == "false" ]]; then
echo -e "| 5) ${green}Enable${white} automatic backups before updates |"
else
echo -e "| 5) ${red}Disable${white} automatic backups before updates |"
@@ -94,7 +100,7 @@ function settings_ui() {
}
function show_settings_help() {
local choice default_cfg="${cyan}${HOME}/klipper_config${white}"
local default_cfg="${cyan}${HOME}/klipper_config${white}"
top_border
echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |"
@@ -131,6 +137,7 @@ function show_settings_help() {
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
@@ -145,11 +152,10 @@ function show_settings_help() {
}
function settings_menu() {
local action
clear && print_header
settings_ui
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in

View File

@@ -39,6 +39,8 @@ function update_ui() {
function update_menu() {
unset update_arr
do_action "" "update_ui"
local action
while true; do
read -p "${cyan}####### Perform action:${white} " action
case "${action}" in
@@ -73,44 +75,48 @@ function update_menu() {
function update_all() {
while true; do
if [ "${#update_arr[@]}" = "0" ]; then
CONFIRM_MSG="Everything is already up to date!"
if (( ${#update_arr[@]} == 0 )); then
print_confirm "Everything is already up-to-date!"
echo; break
fi
echo
top_border
echo -e "| The following installations will be updated: |"
if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then
if [[ "${KLIPPER_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Klipper${white} |"
fi
if [ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]; then
if [[ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Moonraker${white} |"
fi
if [ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]; then
if [[ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Mainsail${white} |"
fi
if [ "${FLUIDD_UPDATE_AVAIL}" = "true" ]; then
if [[ "${FLUIDD_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● Fluidd${white} |"
fi
if [ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]; then
if [[ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● KlipperScreen${white} |"
fi
if [ "${PGC_UPDATE_AVAIL}" = "true" ]; then
if [[ "${PGC_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● PrettyGCode for Klipper${white} |"
fi
if [ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]; then
if [[ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● MoonrakerTelegramBot${white} |"
fi
if [ "${SYS_UPDATE_AVAIL}" = "true" ]; then
if [[ "${SYS_UPDATE_AVAIL}" = "true" ]]; then
echo -e "| ${cyan}● System${white} |"
fi
bottom_border
if [ "${#update_arr[@]}" != "0" ]; then
local yn
if (( ${#update_arr[@]} != 0 )); then
read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn
case "$yn" in
case "${yn}" in
Y|y|Yes|yes|"")
for update in "${update_arr[@]}"
do
#shellcheck disable=SC2250
$update
done
break;;