refactor(mainsail): cover different cases during mainsail-config install
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
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
|
||||||
@@ -43,9 +43,7 @@ function install_mainsail() {
|
|||||||
download_mainsail
|
download_mainsail
|
||||||
|
|
||||||
### ask user to install the recommended webinterface macros
|
### ask user to install the recommended webinterface macros
|
||||||
if [[ ! -d "${HOME}/mainsail-config" ]]; then
|
install_mainsail_macros
|
||||||
install_mainsail_macros
|
|
||||||
fi
|
|
||||||
|
|
||||||
### create /etc/nginx/conf.d/upstreams.conf
|
### create /etc/nginx/conf.d/upstreams.conf
|
||||||
set_upstream_nginx_cfg
|
set_upstream_nginx_cfg
|
||||||
@@ -105,40 +103,55 @@ function download_mainsail_macros() {
|
|||||||
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||||
|
|
||||||
if [[ -z ${configs} ]]; then
|
if [[ -z ${configs} ]]; then
|
||||||
|
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
|
||||||
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 ..."
|
status_msg "Cloning mainsail-config ..."
|
||||||
if cd "${HOME}" && git clone "${ms_cfg_repo}"; then
|
[[ -d "${HOME}/mainsail-config" ]] && rm -rf "${HOME}/mainsail-config"
|
||||||
|
if git clone "${ms_cfg_repo}" "${HOME}/mainsail-config"; then
|
||||||
for config in ${configs}; do
|
for config in ${configs}; do
|
||||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||||
if [[ ! -e "${path}/mainsail.cfg" ]]; then
|
|
||||||
# link config to cfg-dir
|
if [[ -e "${path}/mainsail.cfg" && ! -h "${path}/mainsail.cfg" ]]; then
|
||||||
ln -sf "${HOME}/mainsail-config/mainsail.cfg" "${path}/mainsail.cfg"
|
warn_msg "Attention! Existing mainsail.cfg detected!"
|
||||||
# write include to the very first line of the printer.cfg
|
warn_msg "The file will be renamed to 'mainsail.bak.cfg' to be able to continue with the installation."
|
||||||
if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then
|
if ! mv "${path}/mainsail.cfg" "${path}/mainsail.bak.cfg"; then
|
||||||
log_info "${path}/printer.cfg"
|
error_msg "Renaming mainsail.cfg failed! Aborting installation ..."
|
||||||
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
|
||||||
fi
|
fi
|
||||||
# get linenumber of include statement and add 1
|
fi
|
||||||
line=$(($(grep -n "\[include mainsail.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
|
|
||||||
gcode_dir=${path/config/gcodes}
|
if [[ -h "${path}/mainsail.cfg" ]]; then
|
||||||
# insert required virtual_sdcard block into printer.cfg
|
warn_msg "Recreating symlink in ${path} ..."
|
||||||
if ! grep -Eq "^[virtual_sdcard]$" "${path}/printer.cfg"; then
|
rm -rf "${path}/mainsail.cfg"
|
||||||
log_info "${path}/printer.cfg"
|
fi
|
||||||
sed -Ei "${line} i\ \n[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
|
|
||||||
fi
|
if ! ln -sf "${HOME}/mainsail-config/mainsail.cfg" "${path}/mainsail.cfg"; then
|
||||||
# add the config repo to the moonraker updater
|
error_msg "Creating symlink failed! Aborting installation ..."
|
||||||
patch_mainsail_config_update_manager
|
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
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
print_error "Cloning failed!"
|
print_error "Cloning failed! Aborting installation ..."
|
||||||
log_error "execution stopped! reason: cloning failed"
|
log_error "execution stopped! reason: cloning failed"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
patch_mainsail_config_update_manager
|
||||||
|
|
||||||
ok_msg "Done!"
|
ok_msg "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user