Creality-Helper-Script/scripts/menu/main_menu.sh

154 lines
3.8 KiB
Bash
Raw Normal View History

2024-03-10 21:45:05 +01:00
#!/bin/sh
set -e
2024-05-19 17:52:17 +02:00
if [ ! -f /etc/init.d/S58factoryreset ]; then
cp /usr/data/helper-script/files/services/S58factoryreset /etc/init.d/S58factoryreset
chmod 755 /etc/init.d/S58factoryreset
fi
2024-05-01 16:10:07 +02:00
get_model=$( /usr/bin/get_sn_mac.sh model 2>&1 )
if echo "$get_model" | grep -iq "K1"; then
model="K1"
elif echo "$get_model" | grep -iq "F001"; then
model="3V3"
2024-06-13 22:08:06 +02:00
elif echo "$get_model" | grep -iq "F002"; then
model="3V3"
2024-05-15 01:05:45 +02:00
elif echo "$get_model" | grep -iq "F005"; then
model="3KE"
elif echo "$get_model" | grep -iq "F003"; then
model="10SE"
2024-05-01 16:10:07 +02:00
fi
2024-03-10 21:45:05 +01:00
function get_script_version() {
local version
cd "${HELPER_SCRIPT_FOLDER}"
version="$(git describe HEAD --always --tags | sed 's/-.*//')"
echo "${cyan}${version}${white}"
}
function version_line() {
local content="$1"
local content_length="${#content}"
2025-01-13 01:41:08 +01:00
local width=$((75))
2024-03-10 21:45:05 +01:00
local padding_length=$((width - content_length - 3))
printf " │ %*s%s%s\n" $padding_length '' "$content" " │"
}
function script_title() {
local title
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
title="K1 SERIES"
elif [ "$model" = "3V3" ]; then
title="ENDER-3 V3 SERIES"
2024-05-15 01:05:45 +02:00
elif [ "$model" = "3KE" ]; then
title="ENDER-3 V3 KE"
elif [ "$model" = "10SE" ]; then
title="CR-10 SE"
2024-03-10 21:45:05 +01:00
else
2024-05-15 01:05:45 +02:00
title="PRINTERS"
2024-03-10 21:45:05 +01:00
fi
echo "${title}"
}
function main_menu_ui() {
top_line
2024-05-01 16:10:07 +02:00
title "• HELPER SCRIPT FOR CREALITY $(script_title)" "${blue}"
2024-03-10 21:45:05 +01:00
title "Copyright © Cyril Guislain (Guilouz)" "${white}"
inner_line
2024-05-01 16:10:07 +02:00
title "/!\\ ONLY USE THIS SCRIPT WITH LATEST FIRMWARE VERSION /!\\" "${darkred}"
2024-03-10 21:45:05 +01:00
inner_line
hr
main_menu_option '1' '[Install]' 'Menu'
main_menu_option '2' '[Remove]' 'Menu'
main_menu_option '3' '[Customize]' 'Menu'
main_menu_option '4' '[Backup & Restore]' 'Menu'
main_menu_option '5' '[Tools]' 'Menu'
2024-05-20 20:52:55 +02:00
main_menu_option '6' '[Information]' 'Menu'
2024-03-10 21:45:05 +01:00
main_menu_option '7' '[System]' 'Menu'
hr
inner_line
hr
bottom_menu_option 'q' 'Exit' "${darkred}"
hr
version_line "$(get_script_version)"
bottom_line
}
function main_menu() {
clear
main_menu_ui
local main_menu_opt
while true; do
read -p "${white} Type your choice and validate with Enter: ${yellow}" main_menu_opt
case "${main_menu_opt}" in
1) clear
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
install_menu_k1
elif [ "$model" = "3V3" ]; then
install_menu_3v3
2024-05-29 00:13:52 +02:00
elif [ "$model" = "3KE" ]; then
install_menu_3ke
2024-03-10 21:45:05 +01:00
else
2024-05-29 00:13:52 +02:00
install_menu_10se
2024-03-10 21:45:05 +01:00
fi
break;;
2) clear
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
remove_menu_k1
elif [ "$model" = "3V3" ]; then
remove_menu_3v3
2024-05-29 00:13:52 +02:00
elif [ "$model" = "3KE" ]; then
remove_menu_3ke
2024-03-10 21:45:05 +01:00
else
2024-05-29 00:13:52 +02:00
remove_menu_10se
2024-03-10 21:45:05 +01:00
fi
break;;
3) clear
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
customize_menu_k1
elif [ "$model" = "3V3" ]; then
customize_menu_3v3
2024-05-29 00:13:52 +02:00
elif [ "$model" = "3KE" ]; then
customize_menu_3ke
2024-03-10 21:45:05 +01:00
else
2024-05-29 00:13:52 +02:00
customize_menu_10se
2024-03-10 21:45:05 +01:00
fi
break;;
4) clear
backup_restore_menu
break;;
5) clear
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
tools_menu_k1
elif [ "$model" = "3V3" ]; then
tools_menu_3v3
2024-05-29 00:13:52 +02:00
elif [ "$model" = "3KE" ]; then
tools_menu_3ke
2024-03-10 21:45:05 +01:00
else
2024-05-29 00:13:52 +02:00
tools_menu_10se
2024-03-10 21:45:05 +01:00
fi
main_ui;;
6) clear
2024-05-01 16:10:07 +02:00
if [ "$model" = "K1" ]; then
info_menu_k1
elif [ "$model" = "3V3" ]; then
info_menu_3v3
2024-05-29 00:13:52 +02:00
elif [ "$model" = "3KE" ]; then
info_menu_3ke
2024-03-10 21:45:05 +01:00
else
2024-05-29 00:13:52 +02:00
info_menu_10se
2024-03-10 21:45:05 +01:00
fi
break;;
7) clear
system_menu
break;;
Q|q)
clear; exit 0;;
*)
error_msg "Please select a correct choice!";;
esac
done
main_menu
}