new rollback feature

This commit is contained in:
th33xitus
2020-07-27 10:29:28 +02:00
parent dc4cc59038
commit 82d76b18f0
6 changed files with 146 additions and 49 deletions

View File

@@ -1,7 +1,7 @@
#don't edit this file if you don't know what you are doing...
backup_before_update=false
previous_origin_state=25a9a32e
previous_smoothing_state=feb966c1
previous_shaping_state=e0b94b7f
previous_moonraker_state=9c29a4fc
previous_dev_moonraker_state=528f9f25
previous_origin_state=0
previous_smoothing_state=0
previous_shaping_state=0
previous_moonraker_state=0
previous_dev_moonraker_state=0

View File

@@ -337,34 +337,40 @@ advanced_menu(){
2)
clear
print_header
build_fw
load_klipper_state
print_msg && clear_msg
advanced_ui;;
3)
clear
print_header
flash_routine
build_fw
print_msg && clear_msg
advanced_ui;;
4)
clear
print_header
get_usb_id
flash_routine
print_msg && clear_msg
advanced_ui;;
5)
clear
print_header
get_usb_id && write_printer_id
get_usb_id
print_msg && clear_msg
advanced_ui;;
6)
clear
print_header
create_dwc2fk_cfg
get_usb_id && write_printer_id
print_msg && clear_msg
advanced_ui;;
7)
clear
print_header
create_dwc2fk_cfg
print_msg && clear_msg
advanced_ui;;
8)
clear
print_header
create_custom_hostname
@@ -443,6 +449,12 @@ switch_menu(){
fi
}
#rollback_menu(){
# load_klipper_state
# print_msg && clear_msg
# advanced_menu
#}
backup_menu(){
print_header
print_msg && clear_msg

92
scripts/rollback.sh Executable file
View File

@@ -0,0 +1,92 @@
save_klipper_state(){
source_ini
#read current klipper state
COMMIT_STATE=$(git rev-parse --short HEAD)
if [ $GET_BRANCH = origin/master ]; then
ORI_OLD=$previous_origin_state
ORI_NEW=$COMMIT_STATE
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
elif [ $GET_BRANCH = dmbutyugin/scurve-shaping ]; then
SHA_OLD=$previous_shaping_state
SHA_NEW=$COMMIT_STATE
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
elif [ $GET_BRANCH = dmbutyugin/scurve-smoothing ]; then
SMO_OLD=$previous_smoothing_state
SMO_NEW=$COMMIT_STATE
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE
elif [ $GET_BRANCH = Arksine/work-web_server-20200131 ]; then
WWS_OLD=$previous_moonraker_state
WWS_NEW=$COMMIT_STATE
sed -i "/previous_moonraker_state=/s/$WWS_OLD/$WWS_NEW/" $INI_FILE
elif [ $GET_BRANCH = Arksine/dev-moonraker-testing ]; then
DMT_OLD=$previous_dev_moonraker_state
DMT_NEW=$COMMIT_STATE
sed -i "/previous_dev_moonraker_state=/s/$DMT_OLD/$DMT_NEW/" $INI_FILE
fi
}
load_klipper_state(){
source_ini
print_branch
CURR_COMM=$(git rev-parse --short=8 HEAD)
if [ "$GET_BRANCH" == "origin/master" ]; then
PREV_COMM=$previous_origin_state
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then
PREV_COMM=$previous_shaping_state
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then
PREV_COMM=$previous_smoothing_state
elif [ "$GET_BRANCH" == "Arksine/work-web_server-20200131" ]; then
PREV_COMM=$previous_moonraker_state
elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then
PREV_COMM=$previous_dev_moonraker_state
fi
PREV_COMM_DATE=$(git show -s --format=%cd --date=short $PREV_COMM)
CURR_COMM_DATE=$(git show -s --format=%cd --date=short $CURR_COMM)
if [ $CURR_COMM = $PREV_COMM ]; then
CURR_UI=$(echo -e "${green}$CURR_COMM from $CURR_COMM_DATE${default}")
PREV_UI=$(echo -e "${green}$PREV_COMM from $PREV_COMM_DATE${default}")
else
CURR_UI=$(echo -e "${yellow}$CURR_COMM from $CURR_COMM_DATE${default}")
PREV_UI=$(echo -e "${yellow}$PREV_COMM from $PREV_COMM_DATE${default}")
fi
rollback_ui
rollback_klipper
}
rollback_klipper(){
if [ "$CURR_COMM" != "$PREV_COMM" ]; then
while true; do
echo -e "${cyan}"
read -p "###### Do you want to rollback to $PREV_COMM? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"")
clear
print_header
status_msg "Rolling back to $PREV_COMM ..."
git reset --hard $PREV_COMM -q
ok_msg "Rollback complete!"; echo
load_klipper_state
break;;
N|n|No|no) clear; advanced_menu; break;;
Q|q) clear; advanced_menu; break;;
esac
done
else
while true; do
echo -e "${cyan}"
read -p "Perform action: " action; echo
echo -e "${default}"
case "$action" in
Q|q)
clear; advanced_menu; break;;
*)
clear
print_header
print_unkown_cmd
print_msg && clear_msg
rollback_ui;;
esac
done
fi
}

View File

@@ -128,15 +128,15 @@ read_branch(){
print_branch(){
read_branch
if [ "$GET_BRANCH" == "origin/master" ]; then
PRINT_BRANCH="${cyan}$GET_BRANCH${default} "
PRINT_BRANCH="$GET_BRANCH "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then
PRINT_BRANCH="${cyan}scurve-shaping${default} "
PRINT_BRANCH="scurve-shaping "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then
PRINT_BRANCH="${cyan}scurve-smoothing${default} "
PRINT_BRANCH="scurve-smoothing "
elif [ "$GET_BRANCH" == "Arksine/work-web_server-20200131" ]; then
PRINT_BRANCH="${cyan}moonraker${default} "
PRINT_BRANCH="moonraker "
elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then
PRINT_BRANCH="${cyan}dev-moonraker${default} "
PRINT_BRANCH="dev-moonraker "
else
PRINT_BRANCH="${red}----${default} "
fi

View File

@@ -33,7 +33,7 @@ main_ui(){
hr
echo -e "| 0) [System status] | |"
echo -e "| | Klipper: $KLIPPER_STATUS|"
echo -e "| 1) [Install] | Branch: $PRINT_BRANCH|"
echo -e "| 1) [Install] | Branch: ${cyan}$PRINT_BRANCH${default}|"
echo -e "| 2) [Update] | |"
echo -e "| 3) [Remove] | DWC2: $DWC2_STATUS|"
echo -e "| | Mainsail: $MAINSAIL_STATUS|"
@@ -109,14 +109,15 @@ advanced_ui(){
hr
echo -e "| | | "
echo -e "| Klipper: | System: | "
echo -e "| 1) [Switch Version] | 7) [Change hostname] | "
echo -e "| 1) [Switch Version] | 8) [Change hostname] | "
echo -e "| 2) [Rollback] | | "
echo -e "| | | "
echo -e "| Firmware: | | "
echo -e "| 2) [Build Firmware] | | "
echo -e "| 3) [Flash MCU] | | "
echo -e "| 4) [Get Printer-ID] | | "
echo -e "| 5) [Write Printer-ID] | | "
echo -e "| 6) [Write DWC2 config] | | "
echo -e "| 3) [Build Firmware] | | "
echo -e "| 4) [Flash MCU] | | "
echo -e "| 5) [Get Printer-ID] | | "
echo -e "| 6) [Write Printer-ID] | | "
echo -e "| 7) [Write DWC2 config] | | "
echo -e "| | | "
quit_footer
}
@@ -161,4 +162,23 @@ kiauh_update_msg(){
echo -e "| ${yellow}There is a newer version of this script available!${default} | "
echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | "
bottom_border
}
rollback_ui(){
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | "
hr
echo -e "| If serious errors occured after updating Klipper, | "
echo -e "| you can use this menu to return to the previously | "
echo -e "| used commit from which you have updated. | "
bottom_border
top_border
echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | "
hr
echo -e "| Currently on commit: | "
echo -e "| $CURR_UI | "
hr
echo -e "| Commit last updated from: | "
echo -e "| $PREV_UI | "
quit_footer
}

View File

@@ -65,31 +65,4 @@ update_mainsail(){
status_msg "Updating Mainsail ..."
install_mainsail
start_klipper
}
save_klipper_state(){
source_ini
#read current klipper state
COMMIT_STATE=$(git rev-parse --short HEAD)
if [ $GET_BRANCH = origin/master ]; then
ORI_OLD=$previous_origin_state
ORI_NEW=$COMMIT_STATE
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
elif [ $GET_BRANCH = dmbutyugin/scurve-shaping ]; then
SHA_OLD=$previous_shaping_state
SHA_NEW=$COMMIT_STATE
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
elif [ $GET_BRANCH = dmbutyugin/scurve-smoothing ]; then
SMO_OLD=$previous_smoothing_state
SMO_NEW=$COMMIT_STATE
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE
elif [ $GET_BRANCH = Arksine/work-web_server-20200131 ]; then
WWS_OLD=$previous_moonraker_state
WWS_NEW=$COMMIT_STATE
sed -i "/previous_moonraker_state=/s/$WWS_OLD/$WWS_NEW/" $INI_FILE
elif [ $GET_BRANCH = Arksine/dev-moonraker-testing ]; then
DMT_OLD=$previous_dev_moonraker_state
DMT_NEW=$COMMIT_STATE
sed -i "/previous_dev_moonraker_state=/s/$DMT_OLD/$DMT_NEW/" $INI_FILE
fi
}