feat: KIAUH v4.0.0 #191

Merged
dw-0 merged 453 commits from v4-rc into master 2022-05-29 20:11:16 +02:00
3 changed files with 126 additions and 100 deletions
Showing only changes of commit 3fd1a6bf99 - Show all commits

View File

@@ -41,8 +41,27 @@ function install_mainsail(){
mainsail_port_check mainsail_port_check
### ask user to install mjpg-streamer ### ask user to install mjpg-streamer
if [ ! -f "/etc/systemd/system/webcamd.service" ]; then local install_mjpg_streamer
get_user_selection_mjpg-streamer if [ ! -f "${SYSTEMD}/webcamd.service" ]; then
while true; do
echo
top_border
echo -e "| Install MJGP-Streamer for webcam support? |"
bottom_border
read -p "${cyan}###### Please select (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
install_mjpg_streamer="true"
break;;
N|n|No|no)
select_msg "No"
install_mjpg_streamer="false"
break;;
*)
error_msg "Invalid command!";;
esac
done
fi fi
### ask user to install the recommended webinterface macros ### ask user to install the recommended webinterface macros
@@ -56,14 +75,11 @@ function install_mainsail(){
### symlink nginx log ### symlink nginx log
symlink_webui_nginx_log "mainsail" symlink_webui_nginx_log "mainsail"
### copy the kiauh_macros.cfg to the config location
install_kiauh_macros
### install mainsail/fluidd ### install mainsail/fluidd
mainsail_setup mainsail_setup
### install mjpg-streamer ### install mjpg-streamer
[ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer [ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer
fetch_webui_ports #WIP fetch_webui_ports #WIP
@@ -79,7 +95,7 @@ function install_mainsail_macros(){
echo -e "| your printer configuration to have Mainsail fully |" echo -e "| your printer configuration to have Mainsail fully |"
echo -e "| functional and working. |" echo -e "| functional and working. |"
blank_line blank_line
echo -e "| The recommended macros can be seen here: |" echo -e "| The recommended macros for Mainsail can be seen here: |"
echo -e "| https://docs.mainsail.xyz/configuration#macros |" echo -e "| https://docs.mainsail.xyz/configuration#macros |"
blank_line blank_line
echo -e "| If you already have these macros in your config file, |" echo -e "| If you already have these macros in your config file, |"
@@ -162,32 +178,52 @@ function mainsail_setup(){
#================= REMOVE MAINSAIL =================# #================= REMOVE MAINSAIL =================#
#===================================================# #===================================================#
function remove_mainsail(){ function remove_mainsail_dir(){
### remove mainsail dir [ ! -d "${MAINSAIL_DIR}" ] && return
if [ -d "${MAINSAIL_DIR}" ]; then status_msg "Removing Mainsail directory ..."
status_msg "Removing Mainsail directory ..." rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" }
fi
### remove mainsail config for nginx function remove_mainsail_config(){
if [ -e "/etc/nginx/sites-available/mainsail" ]; then if [ -e "/etc/nginx/sites-available/mainsail" ]; then
status_msg "Removing Mainsail configuration for Nginx ..." status_msg "Removing Mainsail configuration for Nginx ..."
sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!" sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!"
fi fi
### remove mainsail symlink for nginx
if [ -L "/etc/nginx/sites-enabled/mainsail" ]; then if [ -L "/etc/nginx/sites-enabled/mainsail" ]; then
status_msg "Removing Mainsail Symlink for Nginx ..." status_msg "Removing Mainsail Symlink for Nginx ..."
sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!" sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!"
fi fi
}
### remove mainsail nginx logs and log symlinks function remove_mainsail_logs(){
for log in $(find /var/log/nginx -name "mainsail*"); do local files
sudo rm -f "${log}" files=$(find /var/log/nginx -name "mainsail*")
done if [ -n "${files}" ]; then
for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do for file in ${files}; do
rm -f "${log}" status_msg "Removing ${file} ..."
done sudo rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_mainsail_log_symlinks(){
local files
files=$(find "${HOME}/klipper_logs" -name "mainsail*")
if [ -n "${files}" ]; then
for file in ${files}; do
status_msg "Removing ${file} ..."
rm -f "${file}"
ok_msg "${file} removed!"
done
fi
}
function remove_mainsail(){
remove_mainsail_dir
remove_mainsail_config
remove_mainsail_logs
remove_mainsail_log_symlinks
### remove mainsail_port from ~/.kiauh.ini ### remove mainsail_port from ~/.kiauh.ini
sed -i "/^mainsail_port=/d" "${INI_FILE}" sed -i "/^mainsail_port=/d" "${INI_FILE}"
@@ -211,14 +247,8 @@ function update_mainsail(){
#================= MAINSAIL STATUS =================# #================= MAINSAIL STATUS =================#
#===================================================# #===================================================#
function get_mainsail_ver(){
MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1)
}
function mainsail_status(){ function mainsail_status(){
local status local status
### remove the "SERVICE" entry from the data array if a moonraker service is installed
local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail") local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail")
### count+1 for each found data-item from array ### count+1 for each found data-item from array
@@ -273,27 +303,21 @@ function compare_mainsail_versions(){
#=========== MAINSAIL THEME INSTALLER ===========# #=========== MAINSAIL THEME INSTALLER ===========#
#================================================# #================================================#
function get_theme_list(){ function print_theme_list(){
theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" local i=0 theme_list=${1}
theme_csv=$(curl -s -L "${theme_csv_url}")
unset t_name
unset t_note
unset t_auth
unset t_url
i=0
while IFS="," read -r col1 col2 col3 col4; do while IFS="," read -r col1 col2 col3 col4; do
t_name+=("${col1}") if [ "${col1}" != "name" ]; then
t_note+=("${col2}")
t_auth+=("${col3}")
t_url+=("${col4}")
if [ ! "${col1}" == "name" ]; then
printf "| ${i}) %-50s|\n" "[${col1}]" printf "| ${i}) %-50s|\n" "[${col1}]"
fi fi
i=$((i+1)) i=$((i+1))
done <<< "${theme_csv}" done <<< "${theme_list}"
} }
function ms_theme_ui(){ function ms_theme_installer_menu(){
local theme_author theme_repo theme_name theme_note theme_url
local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv"
theme_list=$(curl -s -L "${theme_csv_url}")
top_border top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | " echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | "
hr hr
@@ -304,82 +328,83 @@ function ms_theme_ui(){
echo -e "| Installing a theme from this menu will overwrite an | " echo -e "| Installing a theme from this menu will overwrite an | "
echo -e "| already installed theme or modified custom.css file! | " echo -e "| already installed theme or modified custom.css file! | "
hr hr
get_theme_list # dynamically generate the themelist from a csv file print_theme_list "${theme_list}"
echo -e "| | " echo -e "| | "
echo -e "| R) [Remove Theme] | " echo -e "| R) [Remove Theme] | "
back_footer back_footer
}
function ms_theme_menu(){ while IFS="," read -r col1 col2 col3 col4; do
ms_theme_ui theme_name+=("${col1}")
theme_note+=("${col2}")
theme_author+=("${col3}")
theme_repo+=("${col4}")
done <<< "${theme_list}"
while true; do while true; do
read -p "${cyan}Install theme:${white} " a; echo read -p "${cyan}Install theme:${white} " option
if [ "${a}" = "b" ] || [ "${a}" = "B" ]; then if ((option > 0 && option < ${#theme_name[@]})); then
clear && advanced_menu && break theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}"
elif [ "${a}" = "r" ] || [ "${a}" = "R" ]; then ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}"
break
elif [[ "${option}" == "R" || "${option}" == "r" ]]; then
ms_theme_delete ms_theme_delete
ms_theme_menu break
elif [ "${a}" -le ${#t_url[@]} ]; then elif [[ "${option}" == "B" || "${option}" == "b" ]]; then
ms_theme_install "${t_auth[${a}]}" "${t_url[${a}]}" "${t_name[${a}]}" "${t_note[${a}]}" advanced_menu
ms_theme_menu break
else else
clear && print_header error_msg "Invalid command!"
print_error "Invalid command!"
ms_theme_menu
fi fi
done done
ms_theme_menu ms_theme_installer_menu
} }
function check_select_printer(){ function ms_theme_install(){
unset printer_num local path moonraker_count theme_url=${1} theme_name theme_note
theme_name=${2} theme_note=${3}
### get klipper cfg loc and set default .theme folder loc ### check and select printer if there is more than 1
check_klipper_cfg_path path="$(get_klipper_cfg_dir)"
THEME_PATH="${KLIPPER_CONFIG}" moonraker_count=$(moonraker_systemd | wc -w)
if ((moonraker_count > 1)); then
### check if there is more than one moonraker instance and if yes
### ask the user to select the printer he wants to install/remove the theme
MR_SERVICE_COUNT=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service" | wc -l)
if [[ ${MR_SERVICE_COUNT} -gt 1 ]]; then
top_border top_border
echo -e "| More than one printer was found on this system! | " echo -e "| More than one printer was found on this system! | "
echo -e "| Please select the printer to which you want to | " echo -e "| Please select the printer to which you want to | "
echo -e "| apply the previously selected action. | " echo -e "| apply the previously selected action. | "
bottom_border bottom_border
read -p "${cyan}Select printer:${white} " printer_num read -p "${cyan}Select printer:${white} " printer
path="${path}/printer_${printer}"
### rewrite the .theme path matching the selected printer
THEME_PATH="${KLIPPER_CONFIG}/printer_${printer_num}"
fi fi
### create the cfg folder if there is none yet [ ! -d "${path}" ] && mkdir -p "${path}"
[ ! -d "${THEME_PATH}" ] && mkdir -p "${THEME_PATH}" [ -d "${path}/.theme" ] && rm -rf "${path}/.theme"
} status_msg "Installing ${theme_name[${option}]} ..."
cd "${path}" &&
function ms_theme_install(){ if git clone "${theme_url}" ".theme"; then
THEME_URL="https://github.com/$1/$2" ok_msg "Theme installation complete!"
[ -n "${theme_note}" ] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
### check and select printer if there is more than 1 ok_msg "Please remember to delete your browser cache!\n"
check_select_printer else
error_msg "Theme installation failed!\n"
### download all files fi
status_msg "Installing $3 ..."
status_msg "Please wait ..."
[ -d "${THEME_PATH}/.theme" ] && rm -rf "${THEME_PATH}/.theme"
cd "${THEME_PATH}" && git clone "${THEME_URL}" ".theme"
ok_msg "Theme installation complete!"
[ -n "$4" ] && echo "${yellow}###### Theme Info: $4${white}"
ok_msg "Please remember to delete your browser cache!\n"
} }
function ms_theme_delete(){ function ms_theme_delete(){
check_select_printer local path
if [ -d "${THEME_PATH}/.theme" ]; then path="$(get_klipper_cfg_dir)"
moonraker_count=$(moonraker_systemd | wc -w)
if ((moonraker_count > 1)); then
top_border
echo -e "| More than one printer was found on this system! | "
echo -e "| Please select the printer to which you want to | "
echo -e "| apply the previously selected action. | "
bottom_border
read -p "${cyan}Select printer:${white} " printer
path="${path}/printer_${printer}"
fi
if [ -d "${path}/.theme" ]; then
status_msg "Removing Theme ..." status_msg "Removing Theme ..."
rm -rf "${THEME_PATH}/.theme" && ok_msg "Theme removed!\n" rm -rf "${path}/.theme" && ok_msg "Theme removed!\n"
else else
status_msg "No Theme installed!\n" status_msg "No Theme installed!\n"
fi fi

View File

@@ -39,14 +39,15 @@ function remove_nginx(){
#===================================================# #===================================================#
function set_upstream_nginx_cfg(){ function set_upstream_nginx_cfg(){
get_date local current_date
current_date=$(get_date)
### backup existing nginx configs ### backup existing nginx configs
[ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg"
[ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf"
[ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf"
### transfer ownership of backed up files from root to ${USER} ### transfer ownership of backed up files from root to ${USER}
for log in $(ls "$BACKUP_DIR/nginx_cfg"); do for log in $(ls "$BACKUP_DIR/nginx_cfg"); do
sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/${log}"
done done
### copy nginx configs to target destination ### copy nginx configs to target destination
if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then

View File

@@ -49,7 +49,7 @@ function advanced_menu(){
print_detected_mcu_to_screen print_detected_mcu_to_screen
advanced_ui;; advanced_ui;;
6) 6)
do_action "ms_theme_menu";; do_action "ms_theme_installer_menu";;
7) 7)
clear clear
print_header print_header