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

@@ -23,8 +23,10 @@ for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
function update_kiauh() {
status_msg "Updating KIAUH ..."
cd "${KIAUH_SRCDIR}"
git reset --hard && git pull
ok_msg "Update complete! Please restart KIAUH."
exit 0
}
@@ -36,14 +38,18 @@ function update_kiauh() {
function kiauh_update_avail() {
[[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
local origin head
cd "${KIAUH_SRCDIR}"
### abort if not on master branch
! git branch -a | grep -q "\* master" && return
### compare commit hash
git fetch -q
origin=$(git rev-parse --short=8 origin/master)
head=$(git rev-parse --short=8 HEAD)
if [[ ${origin} != ${head} ]]; then
if [[ ${origin} != "${head}" ]]; then
echo "true"
fi
}

View File

@@ -12,28 +12,30 @@
set -e
function get_date() {
local current_date
current_date=$(date +"%y%m%d-%H%M")
echo "${current_date}"
}
function check_for_backup_dir() {
[ -d "${BACKUP_DIR}" ] && return
[[ -d ${BACKUP_DIR} ]] && return
status_msg "Create KIAUH backup directory ..."
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
}
function backup_before_update() {
read_kiauh_ini "${FUNCNAME[0]}"
# shellcheck disable=SC2154
local state="${backup_before_update}"
[ "${state}" = "false" ] && return
[[ ${state} = "false" ]] && return
backup_"${1}"
}
function backup_printer_cfg() {
check_for_backup_dir
local current_date
if [ -f "${PRINTER_CFG}" ]; then
if [[ -f "${PRINTER_CFG}" ]]; then
current_date=$(get_date)
status_msg "Timestamp: ${current_date}"
status_msg "Create backup of printer.cfg ..."
@@ -45,14 +47,18 @@ function backup_printer_cfg() {
function backup_klipper_config_dir() {
check_for_backup_dir
local current_date
if [ -d "${KLIPPER_CONFIG}" ]; then
local current_date config_folder_name
if [[ -d "${KLIPPER_CONFIG}" ]]; then
current_date=$(get_date)
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
status_msg "Timestamp: ${current_date}"
status_msg "Create backup of the Klipper config directory ..."
config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)"
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}"
cp -r "${KLIPPER_CONFIG}" "${_}"
print_confirm "Configuration directory backup complete!"
else
ok_msg "No config directory found! Skipping backup ..."
@@ -62,18 +68,21 @@ function backup_klipper_config_dir() {
function backup_moonraker_database() {
check_for_backup_dir
local current_date databases target_dir
databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/.moonraker_database(_[^0])?[0-9]*" | sort)
if [ -n "${databases}" ]; then
if [[ -n "${databases}" ]]; then
current_date=$(get_date)
target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}"
status_msg "Timestamp: ${current_date}"
mkdir -p "${target_dir}"
for database in ${databases}; do
status_msg "Create backup of ${database} ..."
cp -r "${database}" "${target_dir}"
ok_msg "Done!"
done
print_confirm "Moonraker database backup complete!"
else
print_error "No Moonraker database found! Skipping backup ..."
@@ -83,7 +92,8 @@ function backup_moonraker_database() {
function backup_klipper() {
local current_date
if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPY_ENV}" ]; then
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
status_msg "Creating Klipper backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -92,13 +102,14 @@ function backup_klipper() {
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
print_confirm "Klipper backup complete!"
else
print_error "Can't backup klipper and/or klipper-env directory! Not found!"
print_error "Can't back up 'klipper' and/or 'klipper-env' directory! Not found!"
fi
}
function backup_mainsail() {
local current_date
if [ -d "${MAINSAIL_DIR}" ]; then
if [[ -d ${MAINSAIL_DIR} ]]; then
status_msg "Creating Mainsail backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -107,13 +118,14 @@ function backup_mainsail() {
cp -r "${MAINSAIL_DIR}" "${_}"
print_confirm "Mainsail backup complete!"
else
print_error "Can't backup mainsail directory! Not found!"
print_error "Can't back up 'mainsail' directory! Not found!"
fi
}
function backup_fluidd() {
local current_date
if [ -d "${FLUIDD_DIR}" ]; then
if [[ -d ${FLUIDD_DIR} ]]; then
status_msg "Creating Fluidd backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -122,13 +134,14 @@ function backup_fluidd() {
cp -r "${FLUIDD_DIR}" "${_}"
print_confirm "Fluidd backup complete!"
else
print_error "Can't backup fluidd directory! Not found!"
print_error "Can't back up 'fluidd' directory! Not found!"
fi
}
function backup_moonraker() {
local current_date
if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_ENV}" ]; then
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
status_msg "Creating Moonraker backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -137,13 +150,14 @@ function backup_moonraker() {
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
print_confirm "Moonraker backup complete!"
else
print_error "Can't backup moonraker and/or moonraker-env directory! Not found!"
print_error "Can't back up moonraker and/or moonraker-env directory! Not found!"
fi
}
function backup_octoprint() {
local current_date
if [ -d "${OCTOPRINT_DIR}" ] && [ -d "${OCTOPRINT_CFG_DIR}" ]; then
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
status_msg "Creating OctoPrint backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -152,13 +166,13 @@ function backup_octoprint() {
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
print_confirm " OctoPrint backup complete!"
else
print_error "Can't backup OctoPrint and/or .octoprint directory!\n Not found!"
print_error "Can't back up OctoPrint and/or .octoprint directory!\n Not found!"
fi
}
function backup_klipperscreen() {
local current_date
if [ -d "${KLIPPERSCREEN_DIR}" ] ; then
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
status_msg "Creating KlipperScreen backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -167,13 +181,14 @@ function backup_klipperscreen() {
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
print_confirm "KlipperScreen backup complete!"
else
print_error "Can't backup KlipperScreen directory!\n Not found!"
print_error "Can't back up KlipperScreen directory!\n Not found!"
fi
}
function backup_telegram_bot() {
local current_date
if [ -d "${TELEGRAM_BOT_DIR}" ] ; then
if [[ -d ${TELEGRAM_BOT_DIR} ]] ; then
status_msg "Creating MoonrakerTelegramBot backup ..."
check_for_backup_dir
current_date=$(get_date)
@@ -182,6 +197,6 @@ function backup_telegram_bot() {
cp -r "${TELEGRAM_BOT_DIR}" "${_}"
print_confirm "MoonrakerTelegramBot backup complete!"
else
print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!"
print_error "Can't back up MoonrakerTelegramBot directory!\n Not found!"
fi
}

View File

@@ -12,8 +12,6 @@
set -e
function init_flash_process() {
local method
### step 1: check for required userhgroups (tty & dialout)
check_usergroups
@@ -29,6 +27,8 @@ function init_flash_process() {
echo -e "| 2) Updating via SD-Card Update |"
blank_line
back_help_footer
local choice method
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
@@ -54,6 +54,7 @@ function init_flash_process() {
### step 2: select how the mcu is connected to the host
select_mcu_connection
### step 3: select which detected mcu should be flashed
select_mcu_id "${method}"
}
@@ -71,12 +72,11 @@ function select_mcu_connection() {
echo -e "| 2) UART |"
blank_line
back_help_footer
local choice
while true; do
read -p "${cyan}###### Connection method:${white} " choice
case "${choice}" in
### continue to execute script even if get_usb_id or get_uart_id returns with exit code 1
### this is not critical, as the mcu_list array will be empty and that specific
### case is handled later during execution of the script
1)
status_msg "Identifying MCU connected via USB ...\n"
get_usb_id || true # continue even after exit code 1
@@ -101,7 +101,7 @@ function select_mcu_connection() {
function print_detected_mcu_to_screen() {
local i=1
if [ "${#mcu_list[@]}" -lt 1 ]; then
if (( ${#mcu_list[@]} < 1 )); then
print_error "No MCU found!\n MCU eihter not connected or not detected!"
return
fi
@@ -109,7 +109,7 @@ function print_detected_mcu_to_screen() {
for mcu in "${mcu_list[@]}"; do
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
i=$((i+1))
i=$(( i + 1 ))
done
echo
}
@@ -120,7 +120,7 @@ function print_detected_mcu_to_screen() {
function select_mcu_id() {
local i=0 sel_index=0 method=${1}
if [ "${#mcu_list[@]}" -lt 1 ]; then
if (( ${#mcu_list[@]} < 1 )); then
print_error "No MCU found!\n MCU eihter not connected or not detected!"
return
fi
@@ -132,25 +132,32 @@ function select_mcu_id() {
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |"
bottom_border
echo -e "${cyan}###### List of available MCU:${white}"
### list all mcus
for mcu in "${mcu_list[@]}"; do
i=$((i+1))
i=$(( i + 1 ))
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
done
### verify user input
while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${i}" ]; do
local regex="^[1-9]+$"
while [[ ! ${sel_index} =~ ${regex} ]] || [[ ${sel_index} -gt ${i} ]]; do
echo
read -p "${cyan}###### Select MCU to flash:${white} " sel_index
if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then
if [[ ! ${sel_index} =~ ${regex} ]]; then
error_msg "Invalid input!"
elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${i}" ]; then
elif [[ ${sel_index} -lt 1 ]] || [[ ${sel_index} -gt ${i} ]]; then
error_msg "Please select a number between 1 and ${i}!"
fi
mcu_index=$((sel_index - 1))
selected_mcu_id="${mcu_list[${mcu_index}]}"
local mcu_index=$(( sel_index - 1 ))
local selected_mcu_id="${mcu_list[${mcu_index}]}"
done
### confirm selection
local yn
while true; do
echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n"
read -p "${cyan}###### Continue? (Y/n):${white} " yn
@@ -158,10 +165,10 @@ function select_mcu_id() {
Y|y|Yes|yes|"")
select_msg "Yes"
status_msg "Flashing ${selected_mcu_id} ..."
if [ "${method}" == "regular" ]; then
if [[ ${method} == "regular" ]]; then
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
start_flash_mcu "${selected_mcu_id}"
elif [ "${method}" == "sdcard" ]; then
elif [[ ${method} == "sdcard" ]]; then
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
start_flash_sd "${selected_mcu_id}"
else
@@ -182,12 +189,14 @@ function select_mcu_id() {
function start_flash_mcu() {
local device=${1}
do_action_service "stop" "klipper"
if make flash FLASH_DEVICE="${device}"; then
ok_msg "Flashing successfull!"
else
warn_msg "Flashing failed!"
warn_msg "Please read the console output above!"
fi
do_action_service "start" "klipper"
}
@@ -208,7 +217,7 @@ function start_flash_sd() {
hr
### display all supported boards to the user
for board in "${board_list[@]}"; do
if [ "${i}" -lt 10 ]; then
if [[ ${i} -lt 10 ]]; then
printf "| ${i}) %-50s|\n" "${board_list[${i}]}"
else
printf "| ${i}) %-49s|\n" "${board_list[${i}]}"
@@ -218,11 +227,12 @@ function start_flash_sd() {
quit_footer
### make the user select one of the boards
local choice
while true; do
read -p "${cyan}###### Please select board type:${white} " choice
if [ "${choice}" = "q" ] || [ "${choice}" = "Q" ]; then
if [[ ${choice} = "q" || ${choice} = "Q" ]]; then
clear && advanced_menu && break
elif [ "${choice}" -le ${#board_list[@]} ]; then
elif [[ ${choice} -le ${#board_list[@]} ]]; then
local selected_board="${board_list[${choice}]}"
break
else
@@ -240,8 +250,10 @@ function start_flash_sd() {
blank_line
echo -e "| If you are unsure, stick to the default 250000! |"
bottom_border
local baud_rate regex="^[0-9]+$"
echo -e "${cyan}###### Please set the baud rate:${white} "
while [[ ! ${baud_rate} =~ ^[0-9]+$ ]]; do
while [[ ! ${baud_rate} =~ ${regex} ]]; do
read -e -i "250000" -e baud_rate
local selected_baud_rate=${baud_rate}
break
@@ -301,6 +313,7 @@ function get_usb_id() {
unset mcu_list
sleep 1
mcus=$(find /dev/serial/by-id/* 2>/dev/null)
for mcu in ${mcus}; do
mcu_list+=("${mcu}")
done
@@ -310,6 +323,7 @@ function get_uart_id() {
unset mcu_list
sleep 1
mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty[^0-9]+([0-9]+)?$" 2>/dev/null)
for mcu in ${mcus}; do
mcu_list+=("${mcu}")
done
@@ -343,6 +357,8 @@ function show_flash_method_help() {
echo -e "| - Fysetc Spider |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
@@ -377,6 +393,8 @@ function show_mcu_connection_help() {
echo -e "| this connection method. |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in

View File

@@ -262,7 +262,7 @@ function get_fluidd_status() {
if (( filecount == ${#data_arr[*]} )); then
status="Installed!"
elif ((filecount == 0)); then
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"

View File

@@ -17,28 +17,33 @@ set -e
function setup_gcode_shell_command() {
top_border
echo -e "| You are about to install the G-Code Shell Command |"
echo -e "| You are about to install the 'G-Code Shell Command' |"
echo -e "| extension. Please make sure to read the instructions |"
echo -e "| before you continue and remember that potential risks |"
echo -e "| can be involved after installing this extension! |"
blank_line
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
if [ ! -d "${KLIPPER_DIR}/klippy/extras" ]; then
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
return
fi
status_msg "Installing gcode shell command extension ..."
if [ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]; then
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
install_gcode_shell_command
else
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
while true; do
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
case "${yn}" in
@@ -68,12 +73,15 @@ function setup_gcode_shell_command() {
function install_gcode_shell_command() {
do_action_service "stop" "klipper"
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
ok_msg "Done!"
else
error_msg "Cannot copy file to target destination...Exiting!"
return 1
fi
local yn
while true; do
echo
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
@@ -87,6 +95,7 @@ function install_gcode_shell_command() {
break;;
esac
done
do_action_service "restart" "klipper"
print_confirm "Shell command extension installed!"
return
@@ -96,15 +105,17 @@ function create_example_shell_command() {
### create a backup of the config folder
backup_klipper_config_dir
local printer_cfgs
local printer_cfgs path
printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort)
for cfg in ${printer_cfgs}; do
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
if [ ! -f "${path}/shell_command.cfg" ]; then
if [[ ! -f "${path}/shell_command.cfg" ]]; then
status_msg "Copy shell_command.cfg to ${path} ..."
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
ok_msg "${path}/shell_command.cfg created!"
### write the include to the very first line of the printer.cfg
### write include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" "${cfg}"
fi
done

View File

@@ -492,7 +492,7 @@ function get_klipper_status() {
### remove the "SERVICE" entry from the data array if a klipper service is installed
local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}")
[[ ${sf_count} -gt 0 ]] && unset "data_arr[0]"
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0

View File

@@ -23,7 +23,7 @@ function klipperscreen_systemd() {
function install_klipperscreen() {
### return early if python version check fails
if [ "$(python3_check)" == "false" ]; then
if [[ $(python3_check) == "false" ]]; then
local error="Versioncheck failed! Python 3.7 or newer required!\n"
error="${error} Please upgrade Python."
print_error "${error}" && return
@@ -42,8 +42,10 @@ function klipperscreen_setup() {
local dep=(wget curl unzip dfu-util)
dependency_check "${dep[@]}"
status_msg "Downloading KlipperScreen ..."
# force remove existing KlipperScreen dir
[ -d "${KLIPPERSCREEN_DIR}" ] && rm -rf "${KLIPPERSCREEN_DIR}"
[[ -d ${KLIPPERSCREEN_DIR} ]] && rm -rf "${KLIPPERSCREEN_DIR}"
# clone into fresh KlipperScreen dir
cd "${HOME}" && git clone "${KLIPPERSCREEN_REPO}"
ok_msg "Download complete!"
@@ -58,23 +60,24 @@ function klipperscreen_setup() {
function remove_klipperscreen() {
### remove KlipperScreen dir
if [ -d "${KLIPPERSCREEN_DIR}" ]; then
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
status_msg "Removing KlipperScreen directory ..."
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
fi
### remove KlipperScreen VENV dir
if [ -d "${KLIPPERSCREEN_ENV}" ]; then
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
status_msg "Removing KlipperScreen VENV directory ..."
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
fi
### remove KlipperScreen service
if [ -e "${SYSTEMD}/KlipperScreen.service" ]; then
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
status_msg "Removing KlipperScreen service ..."
do_action_service "stop" "KlipperScreen"
do_action_service "disable" "KlipperScreen"
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
###reloading units
sudo systemctl daemon-reload
sudo systemctl reset-failed
@@ -82,14 +85,13 @@ function remove_klipperscreen() {
fi
### remove KlipperScreen log
if [ -e "/tmp/KlipperScreen.log" ]; then
if [[ -e "/tmp/KlipperScreen.log" ]]; then
status_msg "Removing KlipperScreen log file ..."
rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!"
fi
### remove KlipperScreen log symlink in config dir
if [ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]; then
if [[ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]]; then
status_msg "Removing KlipperScreen log symlink ..."
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
fi
@@ -109,11 +111,13 @@ function update_klipperscreen() {
cd "${KLIPPERSCREEN_DIR}"
git pull origin master -q && ok_msg "Fetch successfull!"
git checkout -f master && ok_msg "Checkout successfull"
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
status_msg "New dependecies detected..."
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
ok_msg "Dependencies have been installed!"
fi
ok_msg "Update complete!"
do_action_service "start" "KlipperScreen"
}
@@ -128,17 +132,17 @@ function get_klipperscreen_status() {
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
[ "${sf_count}" -gt 0 ] && unset "data_arr[0]"
(( sf_count > 0)) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0
for data in "${data_arr[@]}"; do
[ -e "${data}" ] && filecount=$(("${filecount}" + 1))
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
done
if (( filecount == ${#data_arr[*]})); then
if (( filecount == ${#data_arr[*]} )); then
status="Installed!"
elif ((filecount == 0)); then
elif (( filecount == 0 )); then
status="Not installed!"
else
status="Incomplete!"
@@ -147,16 +151,18 @@ function get_klipperscreen_status() {
}
function get_local_klipperscreen_commit() {
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
local commit
[ ! -d "${KLIPPERSCREEN_DIR}" ] || [ ! -d "${KLIPPERSCREEN_DIR}"/.git ] && return
cd "${KLIPPERSCREEN_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
}
function get_remote_klipperscreen_commit() {
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
local commit
[ ! -d "${KLIPPERSCREEN_DIR}" ] || [ ! -d "${KLIPPERSCREEN_DIR}"/.git ] && return
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
@@ -167,7 +173,8 @@ function compare_klipperscreen_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_klipperscreen_commit)"
remote_ver="$(get_remote_klipperscreen_commit)"
if [ "${local_ver}" != "${remote_ver}" ]; then
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add klipperscreen to the update all array for the update all function in the updater
@@ -177,6 +184,7 @@ function compare_klipperscreen_versions() {
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
KLIPPERSCREEN_UPDATE_AVAIL="false"
fi
echo "${versions}"
}
@@ -187,10 +195,12 @@ function compare_klipperscreen_versions() {
function patch_klipperscreen_update_manager() {
local moonraker_configs
moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort)
for conf in ${moonraker_configs}; do
if ! grep -Eq "[update_manager KlipperScreen]" "${conf}"; then
### add new line to conf if it doesn't end with one
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
### add KlipperScreens update manager section to moonraker.conf
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
@@ -203,6 +213,7 @@ env: ${HOME}/.KlipperScreen-env/bin/python
requirements: scripts/KlipperScreen-requirements.txt
install_script: scripts/KlipperScreen-install.sh
MOONRAKER_CONF
fi
done
}

View File

@@ -322,7 +322,7 @@ function print_theme_list() {
if [[ ${col1} != "name" ]]; then
printf "| ${i}) %-50s|\n" "[${col1}]"
fi
i=$((i+1))
i=$(( i + 1 ))
done <<< "${theme_list}"
}

View File

@@ -22,7 +22,7 @@ function install_mjpg-streamer() {
local service="${KIAUH_SRCDIR}/resources/webcamd.service"
### return early if webcamd.service already exists
if [ -f "${SYSTEMD}/webcamd.service" ]; then
if [[ -f "${SYSTEMD}/webcamd.service" ]]; then
print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
return
fi
@@ -36,11 +36,12 @@ function install_mjpg-streamer() {
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
dep+=(libjpeg8-dev)
fi
dependency_check "${dep[@]}"
### step 1: clone mjpg-streamer
status_msg "Downloading MJPG-Streamer ..."
[ -d "${HOME}/mjpg-streamer" ] && rm -rf "${HOME}/mjpg-streamer"
[[ -d "${HOME}/mjpg-streamer" ]] && rm -rf "${HOME}/mjpg-streamer"
cd "${HOME}" && git clone "${repo}"
ok_msg "Download complete!"
@@ -53,6 +54,7 @@ function install_mjpg-streamer() {
status_msg "Installing MJPG-Streamer ..."
cd "${HOME}/mjpg-streamer" && mv mjpg-streamer-experimental/* .
mkdir www-mjpgstreamer
cat <<EOT >> ./www-mjpgstreamer/index.html
<html>
<head><title>mjpg_streamer test page</title></head>
@@ -65,14 +67,15 @@ function install_mjpg-streamer() {
</body>
</html>
EOT
sudo wget "${webcamd}" -O "/usr/local/bin/webcamd"
sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
sudo chmod +x /usr/local/bin/webcamd
### step 4: create webcam.txt config file
[ ! -d "${KLIPPER_CONFIG}" ] && mkdir -p "${KLIPPER_CONFIG}"
if [ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]; then
[[ ! -d ${KLIPPER_CONFIG} ]] && mkdir -p "${KLIPPER_CONFIG}"
if [[ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]]; then
status_msg "Creating webcam.txt config file ..."
wget "${webcam_txt}" -O "${KLIPPER_CONFIG}/webcam.txt"
ok_msg "Done!"
@@ -94,13 +97,13 @@ EOT
fi
### step 6.1: create webcamd.log symlink
[ ! -d "${KLIPPER_LOGS}" ] && mkdir -p "${KLIPPER_LOGS}"
if [ -f "/var/log/webcamd.log" ] && [ ! -L "${KLIPPER_LOGS}/webcamd.log" ]; then
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
if [[ -f "/var/log/webcamd.log" && ! -L "${KLIPPER_LOGS}/webcamd.log" ]]; then
ln -s "/var/log/webcamd.log" "${KLIPPER_LOGS}/webcamd.log"
fi
### step 6.2: add webcamd.log logrotate
if [ ! -f "/etc/logrotate.d/webcamd" ]; then
if [[ ! -f "/etc/logrotate.d/webcamd" ]]; then
status_msg "Create logrotate rule ..."
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
/var/log/webcamd.log
@@ -121,7 +124,8 @@ EOF
### step 7: check if user is in group "video"
local usergroup_changed="false" usergroup_video
usergroup_video=$(groups "${USER}" | grep "video")
if [ -z "${usergroup_video}" ]; then
if [[ -z ${usergroup_video} ]]; then
status_msg "Adding user ${USER} to group 'video' ..."
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
usergroup_changed="true"
@@ -129,10 +133,11 @@ EOF
### confirm message
local confirm_msg="MJPG-Streamer has been set up!"
if [ "${usergroup_changed}" == "true" ]; then
if [[ ${usergroup_changed} == "true" ]]; then
confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}"
confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
fi
print_confirm "${confirm_msg}"
### print webcam ip adress/url
@@ -151,7 +156,7 @@ EOF
function remove_mjpg-streamer() {
### remove MJPG-Streamer service
if [ -e "${SYSTEMD}/webcamd.service" ]; then
if [[ -e "${SYSTEMD}/webcamd.service" ]]; then
status_msg "Removing MJPG-Streamer service ..."
sudo systemctl stop webcamd && sudo systemctl disable webcamd
sudo rm -f "${SYSTEMD}/webcamd.service"
@@ -162,20 +167,20 @@ function remove_mjpg-streamer() {
fi
### remove webcamd from /usr/local/bin
if [ -e "/usr/local/bin/webcamd" ]; then
if [[ -e "/usr/local/bin/webcamd" ]]; then
sudo rm -f "/usr/local/bin/webcamd"
fi
### remove MJPG-Streamer directory
if [ -d "${HOME}/mjpg-streamer" ]; then
if [[ -d "${HOME}/mjpg-streamer" ]]; then
status_msg "Removing MJPG-Streamer directory ..."
rm -rf "${HOME}/mjpg-streamer"
ok_msg "MJPG-Streamer directory removed!"
fi
### remove webcamd log and symlink
[ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log"
[ -L "${KLIPPER_LOGS}/webcamd.log" ] && rm -f "${KLIPPER_LOGS}/webcamd.log"
[[ -f "/var/log/webcamd.log" ]] && sudo rm -f "/var/log/webcamd.log"
[[ -L "${KLIPPER_LOGS}/webcamd.log" ]] && rm -f "${KLIPPER_LOGS}/webcamd.log"
print_confirm "MJPG-Streamer successfully removed!"
}

View File

@@ -504,7 +504,7 @@ function get_moonraker_status() {
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}")
[[ ${sf_count} -gt 0 ]] && unset "data_arr[0]"
(( sf_count > 0 )) && unset "data_arr[0]"
### count+1 for each found data-item from array
local filecount=0

View File

@@ -16,13 +16,15 @@ set -e
#===================================================#
function remove_nginx() {
if [ -f "${SYSTEMD}/nginx.service" ]; then
if [[ -f "${SYSTEMD}/nginx.service" ]]; then
status_msg "Stopping Nginx service ..."
sudo systemctl stop nginx && sudo systemctl disable nginx
ok_msg "Service stopped and disabled!"
status_msg "Purging Nginx from system ..."
sudo apt-get purge nginx nginx-common -y
sudo update-rc.d -f nginx remove
print_confirm "Nginx successfully removed!"
else
print_error "Looks like Nginx was already removed!\n Skipping..."
@@ -35,42 +37,52 @@ function remove_nginx() {
function set_upstream_nginx_cfg() {
local current_date
current_date=$(get_date)
local upstreams="${NGINX_CONFD}/upstreams.conf"
local common_vars="${NGINX_CONFD}/common_vars.conf"
current_date=$(get_date)
### backup existing nginx configs
[ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
if [ -f "${upstreams}" ]; then
[[ ! -d "${BACKUP_DIR}/nginx_cfg" ]] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
if [[ -f ${upstreams} ]]; then
sudo mv "${upstreams}" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf"
fi
if [ -f "${common_vars}" ]; then
if [[ -f ${common_vars} ]]; then
sudo mv "${common_vars}" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf"
fi
### transfer ownership of backed up files from root to ${USER}
local files
files=$(find "${BACKUP_DIR}/nginx_cfg")
for file in ${files}; do
if [ "$(stat -c "%U" "${file}" )" != "${USER}" ]; then
if [[ $(stat -c "%U" "${file}") != "${USER}" ]]; then
log_info "chown for user: ${USER} on file: ${file}"
sudo chown "${USER}" "${file}"
fi
done
### copy nginx configs to target destination
[ ! -f "${upstreams}" ] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}"
[ ! -f "${common_vars}" ] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}"
[[ ! -f ${upstreams} ]] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}"
[[ ! -f ${common_vars} ]] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}"
}
function symlink_webui_nginx_log() {
local interface=${1} path="${KLIPPER_LOGS}"
local access_log="/var/log/nginx/${interface}-access.log"
local error_log="/var/log/nginx/${interface}-error.log"
[ ! -d "${path}" ] && mkdir -p "${path}"
if [ -f "${access_log}" ] && [ ! -L "${path}/${interface}-access.log" ]; then
[[ ! -d ${path} ]] && mkdir -p "${path}"
if [[ -f ${access_log} && ! -L "${path}/${interface}-access.log" ]]; then
status_msg "Creating symlink for ${access_log} ..."
ln -s "${access_log}" "${path}"
ok_msg "Done!"
fi
if [ -f "${error_log}" ] && [ ! -L "${path}/${interface}-error.log" ]; then
if [[ -f ${error_log} && ! -L "${path}/${interface}-error.log" ]]; then
status_msg "Creating symlink for ${error_log} ..."
ln -s "${error_log}" "${path}"
ok_msg "Done!"
@@ -90,58 +102,69 @@ function match_nginx_configs() {
upstreams_webcams=$(grep -Ec "mjpgstreamer" "/etc/nginx/conf.d/upstreams.conf")
mainsail_webcams=$(grep -Ec "mjpgstreamer" "${mainsail_nginx_cfg}" 2>/dev/null || echo "0")
fluidd_webcams=$(grep -Ec "mjpgstreamer" "${fluidd_nginx_cfg}" 2>/dev/null || echo "0")
status_msg "Checking validity of NGINX configurations ..."
### check for outdated upstreams.conf
if ((upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams)); then
if (( upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams )); then
status_msg "Outdated upstreams.conf found! Updating ..."
sudo rm -f "${upstreams}" "${common_vars}"
set_upstream_nginx_cfg
require_service_restart="true"
ok_msg "Done!"
fi
### check for outdated mainsail config
if [ -e "${mainsail_nginx_cfg}" ] && ((upstreams_webcams > mainsail_webcams)); then
if [[ -e ${mainsail_nginx_cfg} ]] && (( upstreams_webcams > mainsail_webcams )); then
status_msg "Outdated Mainsail config found! Updating ..."
sudo rm -f "${mainsail_nginx_cfg}"
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}"
sudo sed -i "s/<<UI>>/mainsail/g" "${mainsail_nginx_cfg}"
sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}"
sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}"
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}"
require_service_restart="true"
ok_msg "Done!"
fi
### check for outdated fluidd config
if [ -e "${fluidd_nginx_cfg}" ] && ((upstreams_webcams > fluidd_webcams)); then
if [[ -e ${fluidd_nginx_cfg} ]] && (( upstreams_webcams > fluidd_webcams )); then
status_msg "Outdated Fluidd config found! Updating ..."
sudo rm -f "${fluidd_nginx_cfg}"
sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}"
sudo sed -i "s/<<UI>>/fluidd/g" "${fluidd_nginx_cfg}"
sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}"
sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}"
sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}"
require_service_restart="true"
ok_msg "Done!"
fi
### only restart nginx if configs were updated
[ "${require_service_restart}" == "true" ] && sudo systemctl restart nginx.service
[[ ${require_service_restart} == "true" ]] && sudo systemctl restart nginx.service
}
function process_disruptive_services() {
#handle haproxy service
if [ "${DISABLE_HAPROXY}" = "true" ] || [ "${REMOVE_HAPROXY}" = "true" ]; then
if [[ ${DISABLE_HAPROXY} == "true" || ${REMOVE_HAPROXY} == "true" ]]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
fi
### disable haproxy
if [ "${DISABLE_HAPROXY}" = "true" ]; then
if [[ ${DISABLE_HAPROXY} == "true" ]]; then
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy
if [ "${REMOVE_HAPROXY}" = "true" ]; then
if [[ ${REMOVE_HAPROXY} == "true" ]]; then
status_msg "Removing haproxy ..."
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!"
fi
@@ -149,19 +172,19 @@ function process_disruptive_services() {
fi
### handle lighttpd service
if [ "${DISABLE_LIGHTTPD}" = "true" ] || [ "${REMOVE_LIGHTTPD}" = "true" ]; then
if [[ ${DISABLE_LIGHTTPD} == "true" || ${REMOVE_LIGHTTPD} == "true" ]]; then
if systemctl is-active lighttpd -q; then
status_msg "Stopping lighttpd service ..."
sudo systemctl stop lighttpd && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "${DISABLE_LIGHTTPD}" = "true" ]; then
if [[ ${DISABLE_LIGHTTPD} == "true" ]]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!"
### remove lighttpd
if [ "${REMOVE_LIGHTTPD}" = "true" ]; then
if [[ ${REMOVE_LIGHTTPD} == "true" ]]; then
status_msg "Removing lighttpd ..."
sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!"
fi
@@ -169,19 +192,19 @@ function process_disruptive_services() {
fi
### handle apache2 service
if [ "${DISABLE_APACHE2}" = "true" ] || [ "${REMOVE_APACHE2}" = "true" ]; then
if [[ ${DISABLE_APACHE2} == "true" || ${REMOVE_APACHE2} == "true" ]]; then
if systemctl is-active apache2 -q; then
status_msg "Stopping apache2 service ..."
sudo systemctl stop apache2 && ok_msg "Service stopped!"
fi
### disable lighttpd
if [ "${DISABLE_APACHE2}" = "true" ]; then
if [[ ${DISABLE_APACHE2} == "true" ]]; then
status_msg "Disabling lighttpd ..."
sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!"
### remove lighttpd
if [ "${REMOVE_APACHE2}" = "true" ]; then
if [[ ${REMOVE_APACHE2} == "true" ]]; then
status_msg "Removing apache2 ..."
sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!"
fi
@@ -191,29 +214,31 @@ function process_disruptive_services() {
function process_services_dialog() {
#notify user about haproxy or lighttpd services found and possible issues
if [ "${HAPROXY_FOUND}" = "true" ] || [ "${LIGHTTPD_FOUND}" = "true" ] || [ "${APACHE2_FOUND}" = "true" ]; then
if [[ ${HAPROXY_FOUND} == "true" || ${LIGHTTPD_FOUND} == "true" || ${APACHE2_FOUND} == "true" ]]; then
while true; do
echo
top_border
echo -e "| ${red}Possibly disruptive/incompatible services found!${white} |"
hr
if [ "${HAPROXY_FOUND}" = "true" ]; then
if [[ ${HAPROXY_FOUND} == "true" ]]; then
echo -e "| ● haproxy |"
fi
if [ "${LIGHTTPD_FOUND}" = "true" ]; then
if [[ ${LIGHTTPD_FOUND} == "true" ]]; then
echo -e "| ● lighttpd |"
fi
if [ "${APACHE2_FOUND}" = "true" ]; then
if [[ ${APACHE2_FOUND} == "true" ]]; then
echo -e "| ● apache2 |"
fi
hr
echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It is recommend to remove those packages. |"
echo -e "| behaviour. It's recommended to remove those packages. |"
echo -e "| |"
echo -e "| 1) Remove packages (recommend) |"
echo -e "| 2) Disable only (may cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${white} |"
bottom_border
local action
read -p "${cyan}###### Please choose:${white} " action
case "${action}" in
1)
@@ -241,42 +266,43 @@ function process_services_dialog() {
function set_nginx_cfg() {
local interface=${1}
if [ "${SET_NGINX_CFG}" = "true" ]; then
if [[ ${SET_NGINX_CFG} == "true" ]]; then
local cfg="${RESOURCES}/${interface}"
#check for dependencies
local dep=(nginx)
dependency_check "${dep[@]}"
#execute operations
status_msg "Creating Nginx configuration for ${interface^} ..."
#copy content from resources to the respective nginx config file
cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}"
##edit the nginx config file before moving it
sed -i "s/<<UI>>/${interface}/g" "${cfg}"
if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then
if [[ ${SET_LISTEN_PORT} != "${DEFAULT_PORT}" ]]; then
status_msg "Configuring port for ${interface^} ..."
#set listen port ipv4
sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}"
#set listen port ipv6
sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}"
fi
#set correct user
if [ "${interface}" = "mainsail" ] || [ "${interface}" = "fluidd" ]; then
if [[ ${interface} == "mainsail" || ${interface} == "fluidd" ]]; then
sudo sed -i "/root/s/pi/${USER}/" "${cfg}"
fi
#moving the config file into correct directory
sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}"
ok_msg "Nginx configuration for ${interface^} was set!"
if [ -n "${SET_LISTEN_PORT}" ]; then
if [[ -n ${SET_LISTEN_PORT} ]]; then
ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!"
else
ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!"
fi
#remove nginx default config
if [ -e "/etc/nginx/sites-enabled/default" ]; then
if [[ -e "/etc/nginx/sites-enabled/default" ]]; then
sudo rm "/etc/nginx/sites-enabled/default"
fi
#create symlink for own sites
if [ ! -e "/etc/nginx/sites-enabled/${interface}" ]; then
if [[ ! -e "/etc/nginx/sites-enabled/${interface}" ]]; then
sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/"
fi
sudo systemctl restart nginx.service
@@ -292,16 +318,16 @@ function read_listen_port() {
function detect_enabled_sites() {
MAINSAIL_ENABLED="false" FLUIDD_ENABLED="false" OCTOPRINT_ENABLED="false"
#check if there is another UI config already installed and reads the port they are listening on
if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then
if [[ -e "/etc/nginx/sites-enabled/mainsail" ]]; then
SITE_ENABLED="true" && MAINSAIL_ENABLED="true"
MAINSAIL_PORT=$(read_listen_port "mainsail")
fi
if [ -e "/etc/nginx/sites-enabled/fluidd" ]; then
if [[ -e "/etc/nginx/sites-enabled/fluidd" ]]; then
SITE_ENABLED="true" && FLUIDD_ENABLED="true"
FLUIDD_PORT=$(read_listen_port "fluidd")
fi
if [ -e "/etc/nginx/sites-enabled/octoprint" ]; then
if [[ -e "/etc/nginx/sites-enabled/octoprint" ]]; then
SITE_ENABLED="true" && OCTOPRINT_ENABLED="true"
OCTOPRINT_PORT=$(read_listen_port "octoprint")
fi

View File

@@ -27,6 +27,7 @@ function octoprint_setup_dialog() {
local klipper_services klipper_count user_input=() klipper_names=()
klipper_services=$(klipper_systemd)
klipper_count=$(echo "${klipper_services}" | wc -w )
for service in ${klipper_services}; do
klipper_names+=( "$(get_instance_name "${service}")" )
done
@@ -35,6 +36,7 @@ function octoprint_setup_dialog() {
if (( klipper_count == 1 )); then
ok_msg "Klipper installation found!\n"
octoprint_count=1
elif (( klipper_count > 1 )); then
top_border
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
@@ -59,6 +61,7 @@ function octoprint_setup_dialog() {
[[ ! ${octoprint_count} =~ ${re} ]] && error_msg "Input not a number"
(( octoprint_count > klipper_count )) && error_msg "Number of OctoPrint instances larger than existing Klipper instances"
done && select_msg "${octoprint_count}"
else
log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!"
return 1
@@ -308,12 +311,12 @@ function print_op_ip_list() {
#=================================================#
function remove_octoprint_service() {
[[ -z "$(octoprint_systemd)" ]] && return
[[ -z $(octoprint_systemd) ]] && return
###remove all octoprint services
status_msg "Removing OctoPrint Systemd Services ..."
for service in $(octoprint_systemd | cut -d"/" -f5)
do
for service in $(octoprint_systemd | cut -d"/" -f5); do
status_msg "Removing ${service} ..."
sudo systemctl stop "${service}"
sudo systemctl disable "${service}"
@@ -336,6 +339,7 @@ function remove_octoprint_sudoers() {
function remove_octoprint_env() {
local files
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
@@ -348,6 +352,7 @@ function remove_octoprint_env() {
function remove_octoprint_dir() {
local files
files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | sort)
if [[ -n ${files} ]]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
@@ -367,6 +372,7 @@ function remove_octoprint() {
sed -i "/^octoprint_port=/d" "${INI_FILE}"
local confirm="OctoPrint was successfully removed!"
print_confirm "${confirm}" && return
}

View File

@@ -16,34 +16,33 @@ set -e
#=================================================#
function install_pgc_for_klipper() {
pgconfsrc="${PGC_DIR}/pgcode.local.conf"
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
pgc_default_port="7136"
local pgconfsrc="${PGC_DIR}/pgcode.local.conf"
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
local pgc_uri pgc_custom_port pgc_default_port="7136"
status_msg "Installing PrettyGCode for Klipper ..."
### let the user decide which port is used
echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} "
read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port
### check nginx dependency
local dep=(nginx)
dependency_check "${dep[@]}"
### clone repo
[ -d "${PGC_DIR}" ] && rm -rf "${PGC_DIR}"
[[ -d ${PGC_DIR} ]] && rm -rf "${PGC_DIR}"
cd "${HOME}" && git clone "${PGC_REPO}"
### copy nginx config into destination directory
sudo cp "${pgconfsrc}" "${pgconf}"
### replace default pi user in case the user is called different
sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}"
### replace default port
if [ "${pgc_custom_port}" != "${pgc_default_port}" ]; then
if (( pgc_custom_port != pgc_default_port )); then
sudo sed -i "s|listen ${pgc_default_port};|listen ${pgc_custom_port};|" "${pgconf}"
sudo sed -i "s|listen \[::\]:${pgc_default_port};|listen \[::\]:${pgc_custom_port};|" "${pgconf}"
fi
### create symlink
[ ! -L "${pgconfsl}" ] && sudo ln -s "${pgconf}" "${pgconfsl}"
[[ ! -L ${pgconfsl} ]] && sudo ln -s "${pgconf}" "${pgconfsl}"
sudo systemctl restart nginx
### show URI
pgc_uri="http://$(hostname -I | cut -d" " -f1):${pgc_custom_port}"
echo -e "${cyan}\n● Accessible via:${white} ${pgc_uri}"
ok_msg "PrettyGCode for Klipper installed!\n"
@@ -54,17 +53,18 @@ function install_pgc_for_klipper() {
#=================================================#
function remove_prettygcode() {
pgconf="/etc/nginx/sites-available/pgcode.local.conf"
pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
if [ -d "${PGC_DIR}" ] || [ -f "${pgconf}" ] || [ -L "${pgconfsl}" ]; then
local pgconf="/etc/nginx/sites-available/pgcode.local.conf"
local pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf"
if [[ -d ${PGC_DIR} || -f ${pgconf} || -L ${pgconfsl} ]]; then
status_msg "Removing PrettyGCode for Klipper ..."
rm -rf "${PGC_DIR}"
sudo rm -f "${pgconf}"
sudo rm -f "${pgconfsl}"
sudo systemctl restart nginx
CONFIRM_MSG="PrettyGCode for Klipper successfully removed!"
print_confirm "PrettyGCode for Klipper successfully removed!"
else
ERROR_MSG="PrettyGCode for Klipper not found!\n Skipping..."
print_error "PrettyGCode for Klipper not found!\n Skipping..."
fi
}
@@ -73,6 +73,8 @@ function remove_prettygcode() {
#=================================================#
function update_pgc_for_klipper() {
[[ ! -d ${PGC_DIR} ]] && return
status_msg "Updating PrettyGCode for Klipper ..."
cd "${PGC_DIR}" && git pull
ok_msg "Update complete!"
@@ -84,7 +86,8 @@ function update_pgc_for_klipper() {
function get_local_prettygcode_commit() {
local commit
[ ! -d "${PGC_DIR}" ] || [ ! -d "${PGC_DIR}"/.git ] && return
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
cd "${PGC_DIR}"
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
echo "${commit}"
@@ -92,7 +95,8 @@ function get_local_prettygcode_commit() {
function get_remote_prettygcode_commit() {
local commit
[ ! -d "${PGC_DIR}" ] || [ ! -d "${PGC_DIR}"/.git ] && return
[[ ! -d ${PGC_DIR} || ! -d "${PGC_DIR}/.git" ]] && return
cd "${PGC_DIR}" && git fetch origin -q
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
echo "${commit}"
@@ -103,7 +107,8 @@ function compare_prettygcode_versions() {
local versions local_ver remote_ver
local_ver="$(get_local_prettygcode_commit)"
remote_ver="$(get_remote_prettygcode_commit)"
if [ "${local_ver}" != "${remote_ver}" ]; then
if [[ ${local_ver} != "${remote_ver}" ]]; then
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
# add prettygcode to the update all array for the update all function in the updater
@@ -113,5 +118,6 @@ function compare_prettygcode_versions() {
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
PGC_UPDATE_AVAIL="false"
fi
echo "${versions}"
}

View File

@@ -23,6 +23,7 @@ function rollback_menu() {
echo -e "| 2) Rollback Moonraker |"
back_footer
local action
while true; do
read -p "${cyan}###### Perform action:${white} " action
case "${action}" in
@@ -45,7 +46,7 @@ function rollback_menu() {
function rollback_component() {
local component=${1}
if [ ! -d "${HOME}/${component}" ]; then
if [[ ! -d "${HOME}/${component}" ]]; then
print_error "Rollback not possible! Missing installation?"
return
fi
@@ -53,7 +54,7 @@ function rollback_component() {
echo
top_border
echo -e "| Please select how many commits you want to revert. |"
echo -e "| Consider using the information provided by the Github |"
echo -e "| Consider using the information provided by the GitHub |"
echo -e "| commit history to decide how many commits to revert. |"
blank_line
echo -e "| ${red}Warning:${white} |"
@@ -61,9 +62,10 @@ function rollback_component() {
echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |"
back_footer
local count
while true; do
read -p "${cyan}###### Revert this amount of commits:${white} " count
if [ -n "${count}" ] && ((count > 0)); then
if [[ -n ${count} ]] && ((count > 0)); then
status_msg "Revert ${component^} by ${count} commits ..."
cd "${HOME}/${component}"
if git reset --hard HEAD~"${count}"; then
@@ -73,7 +75,7 @@ function rollback_component() {
print_error "Reverting ${component^} failed! Please see the console output above."
fi
break
elif [[ "${count}" == "B" || "${count}" == "b" ]]; then
elif [[ ${count} == "B" || ${count} == "b" ]]; then
clear && print_header && break
else
error_msg "Invalid command!"

View File

@@ -25,7 +25,7 @@ function change_klipper_repo_menu() {
repo=$(echo "${repo}" | sed -r "s/^http(s)?:\/\/github.com\///" | sed "s/\.git$//" )
repos+=("${repo}")
### if branch is not given, default to 'master'
[ -z "${branch}" ] && branch="master"
[[ -z ${branch} ]] && branch="master"
branches+=("${branch}")
done < <(grep -E "^[^#]" "${repo_file}")
@@ -37,23 +37,26 @@ function change_klipper_repo_menu() {
local i=0
for _ in "${repos[@]}"; do
printf "| %s) %-63s|\n" "${i}" "${yellow}${repos[${i}]}${white}${branches[${i}]}"
i=$((i+1))
i=$(( i + 1 ))
done
blank_line
back_help_footer
local option
while true; do
read -p "${cyan}###### Perform action:${white} " option
case "${option}" in
0 | "$((option < ${#repos[@]}))")
0 | "$(( option < ${#repos[@]} ))")
select_msg "Repo: ${repos[option]} Branch: ${branches[option]}"
if [ -d "${KLIPPER_DIR}" ]; then
if [[ -d ${KLIPPER_DIR} ]]; then
top_border
echo -e "| ${red}!!! ATTENTION !!!${white} |"
echo -e "| Existing Klipper folder found! Proceeding will remove | "
echo -e "| the existing Klipper folder and replace it with a | "
echo -e "| clean copy of the previously selected source repo! | "
bottom_border
local yn
while true; do
read -p "${cyan}###### Proceed? (Y/n):${white} " yn
case "${yn}" in
@@ -97,12 +100,15 @@ function change_klipper_repo_menu() {
function switch_klipper_repo() {
local repo_url branch
repo_url="https://github.com/${1}" branch=${2}
status_msg "Switching Klipper repository..."
do_action_service "stop" "klipper"
cd "${HOME}"
[ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}"
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
git clone "${repo_url}" "klipper" && cd "${KLIPPER_DIR}"
git checkout "${branch}" && cd "${HOME}"
do_action_service "start" "klipper"
}
@@ -119,6 +125,8 @@ function show_custom_klipper_repo_help() {
echo -e "| An example file is provided at the same location. |"
blank_line
back_footer
local choice
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in

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;;

View File

@@ -27,6 +27,8 @@ function accept_upload_conditions() {
blank_line
echo -e "| Do ${red}NOT${white} use this function if you don't agree! |"
bottom_border
local yn
while true; do
read -p "${cyan}Do you accept? (Y/n):${white} " yn
case "${yn}" in
@@ -47,11 +49,12 @@ function accept_upload_conditions() {
function upload_selection() {
read_kiauh_ini "${FUNCNAME[0]}"
local upload_agreed="${logupload_accepted}"
[ "${upload_agreed}" = "false" ] && accept_upload_conditions
[[ ${upload_agreed} == "false" ]] && accept_upload_conditions
local logfiles
local klipper_logs="${KLIPPER_LOGS}"
local logs_dir="${KLIPPER_LOGS}"
local webif_logs="/var/log/nginx"
function find_logfile() {
@@ -62,9 +65,9 @@ function upload_selection() {
}
find_logfile "kiauh.log" "/tmp"
find_logfile "klippy*.log" "${klipper_logs}"
find_logfile "moonraker*.log" "${klipper_logs}"
find_logfile "telegram*.log" "${klipper_logs}"
find_logfile "klippy*.log" "${logs_dir}"
find_logfile "moonraker*.log" "${logs_dir}"
find_logfile "telegram*.log" "${logs_dir}"
find_logfile "mainsail*" "${webif_logs}"
find_logfile "fluidd*" "${webif_logs}"
find_logfile "KlipperScreen.log" "/tmp"
@@ -77,20 +80,25 @@ function upload_selection() {
hr
echo -e "| You can choose the following logfiles for uploading: |"
blank_line
for log in "${logfiles[@]}"; do
log=${log//${HOME}/"~"}
((i < 10)) && printf "| ${i}) %-50s|\n" "${log}"
((i >= 10)) && printf "| ${i}) %-50s|\n" "${log}"
i=$((i + 1))
(( i < 10 )) && printf "| ${i}) %-50s|\n" "${log}"
(( i >= 10 )) && printf "| ${i}) %-50s|\n" "${log}"
i=$(( i + 1 ))
done
blank_line
back_footer
local option
while true; do
read -p "${cyan}###### Please select:${white} " option
if [[ -n "${option}" && "${option}" -ge 0 && "${option}" -lt "${#logfiles[@]}" ]]; then
if [[ -n ${option} && ${option} -ge 0 && ${option} -lt ${#logfiles[@]} ]]; then
upload_log "${logfiles[${option}]}"
upload_selection
elif [[ "${option}" == "B" || "${option}" == "b" ]]; then
elif [[ ${option} == "B" || ${option} == "b" ]]; then
return
else
error_msg "Invalid command!"
@@ -103,7 +111,8 @@ function upload_log() {
clear && print_header
status_msg "Uploading ${1} ..."
link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/')
if [ -n "${link}" ]; then
if [[ -n ${link} ]]; then
ok_msg "${1} upload successfull!"
echo -e "\n${cyan}###### Here is your link:${white}"
echo -e ">>>>>> ${link}\n"

View File

@@ -16,8 +16,7 @@ set -e
#================================================#
function check_euid() {
if [[ ${EUID} -eq 0 ]]
then
if [[ ${EUID} -eq 0 ]]; then
echo -e "${red}"
top_border
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
@@ -55,6 +54,7 @@ function title_msg() {
function print_error() {
[[ -z ${1} ]] && return
echo -e "${red}"
echo -e "#=======================================================#"
echo -e " ${1} "
@@ -64,6 +64,7 @@ function print_error() {
function print_confirm() {
[[ -z ${1} ]] && return
echo -e "${green}"
echo -e "#=======================================================#"
echo -e " ${1} "
@@ -111,11 +112,13 @@ function log_error() {
function read_kiauh_ini() {
local func=${1}
if [[ ! -f ${INI_FILE} ]]; then
print_error "ERROR: File '~/.kiauh.ini' not found!"
log_error "Reading from .kiauh.ini failed! File not found!"
return 1
fi
log_info "Reading from .kiauh.ini ... (${func})"
source "${INI_FILE}"
}
@@ -125,6 +128,7 @@ function init_ini() {
if [[ -f ${INI_FILE} ]] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then
rm "${INI_FILE}"
fi
### initialize v4.0.0 ini file
if [[ ! -f ${INI_FILE} ]]; then
{
@@ -137,27 +141,35 @@ function init_ini() {
echo -e "# KIAUH v4.0.0"
} >> "${INI_FILE}"
fi
if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then
echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^logupload_accepted=." "${INI_FILE}"; then
echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then
echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^fluidd_install_unstable=" "${INI_FILE}"; then
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
fi
fetch_webui_ports
}
@@ -166,6 +178,8 @@ function change_klipper_cfg_folder() {
current_cfg_loc="$(get_klipper_cfg_dir)"
example_loc=$(printf "%s/<your_config_folder>" "${HOME}")
recommended_loc=$(printf "%s/klipper_config" "${HOME}")
local yn
while true; do
top_border
echo -e "| ${yellow}IMPORTANT:${white} |"
@@ -217,7 +231,8 @@ function set_klipper_cfg_path() {
### copy config files to new klipper config folder
if [[ -n ${current_cfg_loc} && -d ${current_cfg_loc} ]]; then
status_msg "Copy config files to '${new_cfg_loc}' ..."
if [ ! -d "${new_cfg_loc}" ]; then
if [[ ! -d ${new_cfg_loc} ]]; then
log_info "Copy process started"
mkdir -p "${new_cfg_loc}"
cd "${current_cfg_loc}"
@@ -230,10 +245,13 @@ function set_klipper_cfg_path() {
fi
klipper_services=$(klipper_systemd)
if [[ -n ${klipper_services} ]]; then
status_msg "Re-writing Klipper services to use new config file location ..."
for service in ${klipper_services}; do
if [[ ${service} = "/etc/systemd/system/klipper.service" ]]; then
if grep "Environment=KLIPPER_CONFIG=" "${service}"; then
### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}"
@@ -241,8 +259,10 @@ function set_klipper_cfg_path() {
### single instance klipper service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}"
fi
else
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
if grep "Environment=KLIPPER_CONFIG=" "${service}"; then
### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}"
@@ -256,11 +276,14 @@ function set_klipper_cfg_path() {
fi
moonraker_services=$(moonraker_systemd)
if [[ -n ${moonraker_services} ]]; then
### handle multi moonraker instance service file
status_msg "Re-writing Moonraker services to use new config file location ..."
for service in ${moonraker_services}; do
if [[ ${service} = "/etc/systemd/system/moonraker.service" ]]; then
if grep "Environment=MOONRAKER_CONF=" "${service}"; then
### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}"
@@ -268,8 +291,10 @@ function set_klipper_cfg_path() {
### single instance moonraker service installed by kiauh v3
sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}"
fi
else
instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1)
if grep "Environment=MOONRAKER_CONF=" "${service}"; then
### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0
sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}"
@@ -279,7 +304,9 @@ function set_klipper_cfg_path() {
fi
fi
done
moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort)
### replace old file path with new one in moonraker.conf
local loc
for conf in ${moonraker_configs}; do
@@ -300,6 +327,7 @@ function set_klipper_cfg_path() {
function switch_mainsail_releasetype() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${mainsail_install_unstable}"
if [[ ${state} == "false" ]]; then
sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}"
log_info "mainsail_install_unstable changed (false -> true) "
@@ -312,6 +340,7 @@ function switch_mainsail_releasetype() {
function switch_fluidd_releasetype() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${fluidd_install_unstable}"
if [[ ${state} == "false" ]]; then
sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}"
log_info "fluidd_install_unstable changed (false -> true) "
@@ -324,6 +353,7 @@ function switch_fluidd_releasetype() {
function toggle_backup_before_update() {
read_kiauh_ini "${FUNCNAME[0]}"
local state="${backup_before_update}"
if [[ ${state} = "false" ]]; then
sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}"
else
@@ -334,6 +364,7 @@ function toggle_backup_before_update() {
function set_custom_klipper_repo() {
read_kiauh_ini "${FUNCNAME[0]}"
local repo=${1} branch=${2}
sed -i "/^custom_klipper_repo=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_repo=${repo}" "${INI_FILE}"
sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}"
@@ -347,10 +378,12 @@ function set_custom_klipper_repo() {
function do_action_service() {
local services action=${1} service=${2}
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[0-9a-zA-Z]+)?.service" | sort)
if [[ -n ${services} ]]; then
for service in ${services}; do
service=$(echo "${service}" | rev | cut -d"/" -f1 | rev)
status_msg "${action^} ${service} ..."
if sudo systemctl "${action}" "${service}"; then
log_info "${service}: ${action} > success"
ok_msg "${action^} ${service} successfull!"
@@ -386,13 +419,14 @@ function dependency_check() {
local dep=( "${@}" )
local packages
status_msg "Checking for the following dependencies:"
#check if package is installed, if not write its name into array
for pkg in "${dep[@]}"; do
echo -e "${cyan}${pkg} ${white}"
if [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]]; then
packages+=("${pkg}")
fi
[[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]] && \
packages+=("${pkg}")
done
#if array is not empty, install packages from array
if (( ${#packages[@]} > 0 )); then
status_msg "Installing the following dependencies:"
@@ -400,6 +434,7 @@ function dependency_check() {
echo -e "${cyan}${package} ${white}"
done
echo
if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then
ok_msg "Dependencies installed!"
else
@@ -414,24 +449,22 @@ function dependency_check() {
function system_check_webui() {
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
[[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]] && \
HAPROXY_FOUND="true"
### check system for an installed lighttpd service
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true"
fi
[[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]] && \
LIGHTTPD_FOUND="true"
### check system for an installed apache2 service
if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then
APACHE2_FOUND="true"
fi
[[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]] && \
APACHE2_FOUND="true"
}
function fetch_webui_ports() {
### read ports from possible installed interfaces and write them to ~/.kiauh.ini
local port interfaces=("mainsail" "fluidd" "octoprint")
### read ports from possible installed interfaces and write them to ~/.kiauh.ini
for interface in "${interfaces[@]}"; do
if [[ -f "/etc/nginx/sites-available/${interface}" ]]; then
port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2)
@@ -454,6 +487,7 @@ function fetch_webui_ports() {
function check_system_updates() {
local updates_avail info_msg
updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d")
if [[ -n ${updates_avail} ]]; then
# add system updates to the update all array for the update all function in the updater
SYS_UPDATE_AVAIL="true" && update_arr+=(update_system)
@@ -462,6 +496,7 @@ function check_system_updates() {
SYS_UPDATE_AVAIL="false"
info_msg="${green}System up to date! ${white}"
fi
echo "${info_msg}"
}
@@ -476,12 +511,15 @@ function update_system() {
function check_usergroups() {
local group_dialout group_tty
if grep -q "dialout" </etc/group && ! grep -q "dialout" <(groups "${USER}"); then
group_dialout="false"
fi
if grep -q "tty" </etc/group && ! grep -q "tty" <(groups "${USER}"); then
group_tty="false"
fi
if [[ ${group_dialout} == "false" || ${group_tty} == "false" ]] ; then
top_border
echo -e "| ${yellow}WARNING: Your current user is not in group:${white} |"
@@ -499,6 +537,8 @@ function check_usergroups() {
echo -e "| ${yellow}INFO:${white} |"
echo -e "| ${yellow}Relog required for group assignments to take effect!${white} |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${white} " yn
case "${yn}" in
@@ -534,6 +574,8 @@ function set_custom_hostname() {
echo -e "| can open Mainsail / Fluidd / Octoprint by |"
echo -e "| browsing to: http://my-printer.local |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn
case "${yn}" in
@@ -558,9 +600,12 @@ function change_hostname() {
echo -e "| ${red}No special characters allowed!${white} |"
echo -e "| ${red}No leading or trailing '-' allowed!${white} |"
bottom_border
while true; do
read -p "${cyan}###### Please set the new hostname:${white} " new_hostname
if [[ ${new_hostname} =~ ${regex} ]]; then
local yn
while true; do
echo
read -p "${cyan}###### Do you want '${new_hostname}' to be the new hostname? (Y/n):${white} " yn