mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
feat(mainsail): use mainsail-config repo for downloading mainsail macros (#301)
This commit is contained in:
@@ -30,7 +30,7 @@ function install_mainsail() {
|
|||||||
|
|
||||||
status_msg "Initializing Mainsail installation ..."
|
status_msg "Initializing Mainsail installation ..."
|
||||||
### first, we create a backup of the full klipper_config dir - safety first!
|
### first, we create a backup of the full klipper_config dir - safety first!
|
||||||
backup_klipper_config_dir
|
#backup_klipper_config_dir
|
||||||
|
|
||||||
### check for other enabled web interfaces
|
### check for other enabled web interfaces
|
||||||
unset SET_LISTEN_PORT
|
unset SET_LISTEN_PORT
|
||||||
@@ -39,30 +39,6 @@ function install_mainsail() {
|
|||||||
### check if another site already listens to port 80
|
### check if another site already listens to port 80
|
||||||
mainsail_port_check
|
mainsail_port_check
|
||||||
|
|
||||||
# ### ask user to install mjpg-streamer
|
|
||||||
# local install_mjpg_streamer
|
|
||||||
# if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
|
||||||
# while true; do
|
|
||||||
# echo
|
|
||||||
# top_border
|
|
||||||
# echo -e "| Install MJPG-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
|
|
||||||
|
|
||||||
### download mainsail
|
### download mainsail
|
||||||
download_mainsail
|
download_mainsail
|
||||||
|
|
||||||
@@ -82,9 +58,6 @@ function install_mainsail() {
|
|||||||
### add mainsail to the update manager in moonraker.conf
|
### add mainsail to the update manager in moonraker.conf
|
||||||
patch_mainsail_update_manager
|
patch_mainsail_update_manager
|
||||||
|
|
||||||
### install mjpg-streamer
|
|
||||||
# [[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
|
||||||
|
|
||||||
fetch_webui_ports #WIP
|
fetch_webui_ports #WIP
|
||||||
|
|
||||||
### confirm message
|
### confirm message
|
||||||
@@ -92,22 +65,21 @@ function install_mainsail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function install_mainsail_macros() {
|
function install_mainsail_macros() {
|
||||||
|
local yn
|
||||||
while true; do
|
while true; do
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
echo -e "| It is recommended to have some important macros in |"
|
echo -e "| It is recommended to use special macros in order to |"
|
||||||
echo -e "| your printer configuration to have Mainsail fully |"
|
echo -e "| have Mainsail fully functional and working. |"
|
||||||
echo -e "| functional and working. |"
|
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| The recommended macros for Mainsail 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://github.com/mainsail-crew/mainsail-config |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| If you already have these macros in your config file, |"
|
echo -e "| If you already use these macros skip this step. |"
|
||||||
echo -e "| skip this step and answer with 'no'. |"
|
|
||||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||||
echo -e "| add the recommended example macros to your config. |"
|
echo -e "| download the recommended macros. |"
|
||||||
bottom_border
|
bottom_border
|
||||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
read -p "${cyan}###### Download the recommended macros? (Y/n):${white} " yn
|
||||||
case "${yn}" in
|
case "${yn}" in
|
||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
select_msg "Yes"
|
select_msg "Yes"
|
||||||
@@ -124,36 +96,64 @@ function install_mainsail_macros() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function download_mainsail_macros() {
|
function download_mainsail_macros() {
|
||||||
local ms_cfg path configs regex
|
local ms_cfg_repo path configs regex line gcode_dir
|
||||||
|
|
||||||
ms_cfg="https://raw.githubusercontent.com/mainsail-crew/mainsail-config/master/mainsail.cfg"
|
ms_cfg_repo="https://github.com/mainsail-crew/mainsail-config.git"
|
||||||
regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
|
regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
|
||||||
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||||
|
|
||||||
if [[ -n ${configs} ]]; then
|
if [[ -z ${configs} ]]; then
|
||||||
for config in ${configs}; do
|
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
|
||||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
|
||||||
if [[ ! -f "${path}/mainsail.cfg" ]]; then
|
|
||||||
status_msg "Downloading mainsail.cfg to ${path} ..."
|
|
||||||
log_info "downloading mainsail.cfg to: ${path}"
|
|
||||||
wget "${ms_cfg}" -O "${path}/mainsail.cfg"
|
|
||||||
|
|
||||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
|
||||||
log_info "modify mainsail.cfg"
|
|
||||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg"
|
|
||||||
|
|
||||||
### write include to the very first line of the printer.cfg
|
|
||||||
if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then
|
|
||||||
log_info "modify printer.cfg"
|
|
||||||
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
|
||||||
fi
|
|
||||||
ok_msg "Done!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
log_error "execution stopped! reason: no printer.cfg found"
|
log_error "execution stopped! reason: no printer.cfg found"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
status_msg "Cloning mainsail-config ..."
|
||||||
|
[[ -d "${HOME}/mainsail-config" ]] && rm -rf "${HOME}/mainsail-config"
|
||||||
|
if git clone "${ms_cfg_repo}" "${HOME}/mainsail-config"; then
|
||||||
|
for config in ${configs}; do
|
||||||
|
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||||
|
|
||||||
|
if [[ -e "${path}/mainsail.cfg" && ! -h "${path}/mainsail.cfg" ]]; then
|
||||||
|
warn_msg "Attention! Existing mainsail.cfg detected!"
|
||||||
|
warn_msg "The file will be renamed to 'mainsail.bak.cfg' to be able to continue with the installation."
|
||||||
|
if ! mv "${path}/mainsail.cfg" "${path}/mainsail.bak.cfg"; then
|
||||||
|
error_msg "Renaming mainsail.cfg failed! Aborting installation ..."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -h "${path}/mainsail.cfg" ]]; then
|
||||||
|
warn_msg "Recreating symlink in ${path} ..."
|
||||||
|
rm -rf "${path}/mainsail.cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! ln -sf "${HOME}/mainsail-config/client.cfg" "${path}/mainsail.cfg"; then
|
||||||
|
error_msg "Creating symlink failed! Aborting installation ..."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -Eq "^\[include mainsail.cfg\]$" "${path}/printer.cfg"; then
|
||||||
|
log_info "${path}/printer.cfg"
|
||||||
|
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
line=$(($(grep -n "\[include mainsail.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
|
||||||
|
gcode_dir=${path/config/gcodes}
|
||||||
|
if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then
|
||||||
|
log_info "${path}/printer.cfg"
|
||||||
|
sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
print_error "Cloning failed! Aborting installation ..."
|
||||||
|
log_error "execution stopped! reason: cloning failed"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
patch_mainsail_config_update_manager
|
||||||
|
|
||||||
|
ok_msg "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_mainsail() {
|
function download_mainsail() {
|
||||||
@@ -196,7 +196,7 @@ function remove_mainsail_dir() {
|
|||||||
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
|
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_mainsail_config() {
|
function remove_mainsail_nginx_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!"
|
||||||
@@ -248,9 +248,18 @@ function remove_legacy_mainsail_log_symlinks() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove_mainsail_config() {
|
||||||
|
if [[ -d "${HOME}/mainsail-config" ]]; then
|
||||||
|
status_msg "Removing ${HOME}/mainsail-config ..."
|
||||||
|
rm -rf "${HOME}/mainsail-config"
|
||||||
|
ok_msg "${HOME}/mainsail-config removed!"
|
||||||
|
print_confirm "Mainsail-Config successfully removed!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function remove_mainsail() {
|
function remove_mainsail() {
|
||||||
remove_mainsail_dir
|
remove_mainsail_dir
|
||||||
remove_mainsail_config
|
remove_mainsail_nginx_config
|
||||||
remove_mainsail_logs
|
remove_mainsail_logs
|
||||||
remove_mainsail_log_symlinks
|
remove_mainsail_log_symlinks
|
||||||
remove_legacy_mainsail_log_symlinks
|
remove_legacy_mainsail_log_symlinks
|
||||||
@@ -623,3 +632,36 @@ MOONRAKER_CONF
|
|||||||
do_action_service "restart" "moonraker"
|
do_action_service "restart" "moonraker"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function patch_mainsail_config_update_manager() {
|
||||||
|
local patched moonraker_configs regex
|
||||||
|
regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||||
|
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||||
|
|
||||||
|
patched="false"
|
||||||
|
for conf in ${moonraker_configs}; do
|
||||||
|
if ! grep -Eq "^\[update_manager mainsail-config\]\s*$" "${conf}"; then
|
||||||
|
### add new line to conf if it doesn't end with one
|
||||||
|
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||||
|
|
||||||
|
### add Mainsails update manager section to moonraker.conf
|
||||||
|
status_msg "Adding Mainsail-Config to update manager in file:\n ${conf}"
|
||||||
|
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||||
|
|
||||||
|
[update_manager mainsail-config]
|
||||||
|
type: git_repo
|
||||||
|
primary_branch: master
|
||||||
|
path: ~/mainsail-config
|
||||||
|
origin: https://github.com/mainsail-crew/mainsail-config.git
|
||||||
|
managed_services: klipper
|
||||||
|
MOONRAKER_CONF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
patched="true"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${patched} == "true" ]]; then
|
||||||
|
do_action_service "restart" "moonraker"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ function remove_ui() {
|
|||||||
echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
|
echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |"
|
||||||
hr
|
hr
|
||||||
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
echo -e "| Firmware & API: | 3rd Party Webinterface: |"
|
||||||
echo -e "| 1) [Klipper] | 6) [OctoPrint] |"
|
echo -e "| 1) [Klipper] | 7) [OctoPrint] |"
|
||||||
echo -e "| 2) [Moonraker] | |"
|
echo -e "| 2) [Moonraker] | |"
|
||||||
echo -e "| | Webcam Streamer: |"
|
echo -e "| | Webcam Streamer: |"
|
||||||
echo -e "| Klipper Webinterface: | 7) [Crowsnest] |"
|
echo -e "| Klipper Webinterface: | 8) [Crowsnest] |"
|
||||||
echo -e "| 3) [Mainsail] | 8) [MJPG-Streamer] |"
|
echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] |"
|
||||||
echo -e "| 4) [Fluidd] | |"
|
echo -e "| 4) [Mainsail-Config] | |"
|
||||||
echo -e "| | Other: |"
|
echo -e "| 5) [Fluidd] | Other: |"
|
||||||
echo -e "| Touchscreen GUI: | 9) [PrettyGCode] |"
|
echo -e "| | 10) [PrettyGCode] |"
|
||||||
echo -e "| 5) [KlipperScreen] | 10) [Telegram Bot] |"
|
echo -e "| Touchscreen GUI: | 11) [Telegram Bot] |"
|
||||||
echo -e "| | 11) [Obico for Klipper] |"
|
echo -e "| 6) [KlipperScreen] | 12) [Obico for Klipper] |"
|
||||||
echo -e "| | 12) [NGINX] |"
|
echo -e "| | 13) [NGINX] |"
|
||||||
back_footer
|
back_footer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,22 +46,24 @@ function remove_menu() {
|
|||||||
3)
|
3)
|
||||||
do_action "remove_mainsail" "remove_ui";;
|
do_action "remove_mainsail" "remove_ui";;
|
||||||
4)
|
4)
|
||||||
do_action "remove_fluidd" "remove_ui";;
|
do_action "remove_mainsail_config" "remove_ui";;
|
||||||
5)
|
5)
|
||||||
do_action "remove_klipperscreen" "remove_ui";;
|
do_action "remove_fluidd" "remove_ui";;
|
||||||
6)
|
6)
|
||||||
do_action "remove_octoprint" "remove_ui";;
|
do_action "remove_klipperscreen" "remove_ui";;
|
||||||
7)
|
7)
|
||||||
do_action "remove_crowsnest" "remove_ui";;
|
do_action "remove_octoprint" "remove_ui";;
|
||||||
8)
|
8)
|
||||||
do_action "remove_mjpg-streamer" "remove_ui";;
|
do_action "remove_crowsnest" "remove_ui";;
|
||||||
9)
|
9)
|
||||||
do_action "remove_prettygcode" "remove_ui";;
|
do_action "remove_mjpg-streamer" "remove_ui";;
|
||||||
10)
|
10)
|
||||||
do_action "remove_telegram_bot" "remove_ui";;
|
do_action "remove_prettygcode" "remove_ui";;
|
||||||
11)
|
11)
|
||||||
do_action "remove_moonraker_obico" "remove_ui";;
|
do_action "remove_telegram_bot" "remove_ui";;
|
||||||
12)
|
12)
|
||||||
|
do_action "remove_moonraker_obico" "remove_ui";;
|
||||||
|
13)
|
||||||
do_action "remove_nginx" "remove_ui";;
|
do_action "remove_nginx" "remove_ui";;
|
||||||
B|b)
|
B|b)
|
||||||
clear; main_menu; break;;
|
clear; main_menu; break;;
|
||||||
|
|||||||
Reference in New Issue
Block a user