feat: add mainsail theme installer

This commit is contained in:
th33xitus
2021-03-22 10:55:24 +01:00
parent 749293dde0
commit 7c7dd4ec3c
3 changed files with 121 additions and 8 deletions

78
scripts/ms_theme_installer.sh Executable file
View File

@@ -0,0 +1,78 @@
### base variables
SYSTEMDDIR="/etc/systemd/system"
check_select_printer(){
unset printer_num
### get klipper cfg loc and set default theme loc
check_klipper_cfg_path
THEME_PATH="$klipper_cfg_loc/.theme"
### 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
printer_count=$(ls /etc/systemd/system/moonraker*.service | wc -l)
if [ $printer_count -gt 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:${default} " printer_num
### rewrite the theme path matching the selected printer
THEME_PATH="$klipper_cfg_loc/printer_$printer_num/.theme"
fi
}
ms_theme_delete(){
### check and select printer if there is more than 1
check_select_printer
### remove .theme folder
if [ -d $THEME_PATH ]; then
status_msg "Removing Theme ..."
rm -rf $THEME_PATH && ok_msg "Theme removed!\n"
else
status_msg "No Theme installed!\n"
fi
}
ms_theme_dracula(){
THEME_RAW_URL="https://raw.githubusercontent.com/steadyjaw/dracula-mainsail-theme/master/config/.theme/"
### check and select printer if there is more than 1
check_select_printer
### list filenames we need to download
files=(
custom.css
favicon-32x32.png
favicon-64x64.png
sidebar-background.png
sidebar-logo.svg
)
### check for .theme folder
[ ! -d $THEME_PATH ] && mkdir -p $THEME_PATH
cd $THEME_PATH
### download all files
status_msg "Installing Dracula theme ..."
status_msg "Please wait ..."
for file in ${files[@]}
do
status_msg "Downloading $file ..."
wget -q "$THEME_RAW_URL$file" -O $file
ok_msg "Done!"
done
### check if all files got downloaded
if [ $(ls | wc -l) = ${#files[@]} ]; then
echo
ok_msg "Theme installation complete!"
ok_msg "Please remember to delete your browser cache!\n"
else
echo
warn_msg "Some files are missing! Please try again!\n"
fi
}

View File

@@ -5,14 +5,14 @@ advanced_ui(){
echo -e "| 0) $OPRINT_SERVICE_STATUS| "
hr
echo -e "| | | "
echo -e "| Klipper: | System: | "
echo -e "| 1) [Switch Version] | 7) [Change hostname] | "
echo -e "| Klipper: | Mainsail: | "
echo -e "| 1) [Switch Version] | 7) [Theme installer] | "
echo -e "| 2) [Rollback] | | "
echo -e "| | Extensions: | "
echo -e "| Firmware: | 8) [Shell Command] | "
echo -e "| | System: | "
echo -e "| Firmware: | 8) [Change hostname] | "
echo -e "| 3) [Build only] | | "
echo -e "| 4) [Build + Flash] | | "
echo -e "| 5) [Build + SD Flash] | | "
echo -e "| 4) [Build + Flash] | Extensions: | "
echo -e "| 5) [Build + SD Flash] | 9) [Shell Command] | "
echo -e "| 6) [Get MCU ID] | | "
quit_footer
}
@@ -31,7 +31,7 @@ advanced_menu(){
print_msg && clear_msg
advanced_ui;;
1)
do_action "switch_menu" "advanced_ui";;
do_action "switch_menu";;
2)
do_action "load_klipper_state" "advanced_ui";;
3)
@@ -57,12 +57,14 @@ advanced_menu(){
6)
do_action "get_mcu_id" "advanced_ui";;
7)
do_action "ms_theme_menu";;
8)
clear
print_header
create_custom_hostname && set_hostname
print_msg && clear_msg
advanced_ui;;
8)
9)
do_action "setup_gcode_shell_command" "advanced_ui";;
Q|q)
clear; main_menu; break;;

33
scripts/ui/ms_theme_menu.sh Executable file
View File

@@ -0,0 +1,33 @@
ms_theme_ui(){
top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | "
hr
echo -e "| Please note: | "
echo -e "| Installing a theme from this menu will overwrite an | "
echo -e "| already installed theme or modified custom.css file! | "
hr
echo -e "| Theme: | "
echo -e "| 1) [Dracula] | "
echo -e "| | "
echo -e "| R) [Remove Theme] | "
echo -e "| | "
quit_footer
}
ms_theme_menu(){
do_action "" "ms_theme_ui"
while true; do
read -p "${cyan}Perform action:${default} " action; echo
case "$action" in
1)
do_action "ms_theme_dracula" "ms_theme_ui";;
R|r)
do_action "ms_theme_delete" "ms_theme_ui";;
Q|q)
clear; advanced_menu; break;;
*)
deny_action "ms_theme_ui";;
esac
done
ms_theme_menu
}