From 3bcde4c9533d512becf2fac451d44c4c7346c626 Mon Sep 17 00:00:00 2001 From: Cyril Date: Sun, 19 May 2024 17:52:17 +0200 Subject: [PATCH] Update --- files/services/S58factoryreset | 45 ++++++++++++++++++++++++++++++++++ scripts/menu/main_menu.sh | 5 ++++ scripts/tools.sh | 8 +++--- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100755 files/services/S58factoryreset diff --git a/files/services/S58factoryreset b/files/services/S58factoryreset new file mode 100755 index 0000000..23cc942 --- /dev/null +++ b/files/services/S58factoryreset @@ -0,0 +1,45 @@ +#!/bin/sh + +# +# This script will execute just before klipper starts and it does not rely on wipe data +# it does the equivalent of `echo "all" | nc -U /var/run/wipe.sock` +# +# It needs to run after S12udev is started which is what mounts the usb key +# + +FLAG_FILE="/tmp/udisk/sda1/factory_reset" + +factory_reset() { + mv "$FLAG_FILE" "${FLAG_FILE}.old" >/dev/null 2>&1 + /usr/bin/mcu_reset.sh >/dev/null 2>&1 + ACTION=stop /usr/bin/auto_uvc.sh >/dev/null 2>&1 + echo "Info: Factory reset was executed successfully, the printer will restart..." + /etc/init.d/rcK >/dev/null 2>&1 + /bin/rm -rf /overlay/upper/* >/dev/null 2>&1 + /usr/bin/find /usr/data/ -path '/usr/data/creality' -prune -o -path '/usr/data/wpa_supplicant.conf' -prune -o -path '/usr/data/machine_production_info' -prune -o -path '/usr/data/' -o -print -exec rm -rf {} \; >/dev/null 2>&1 + /bin/sync >/dev/null 2>&1 + /sbin/swapoff -a >/dev/null 2>&1 + /sbin/reboot -f >/dev/null 2>&1 +} + +case "$1" in + start) + if [ -f "$FLAG_FILE" ]; then + echo "Info: Executing factory reset..." + factory_reset + else + echo "Info: No 'factory_reset' file found on the USB drive!" + exit 1 + fi + ;; + reset) + echo "Info: Executing factory reset..." + factory_reset + ;; + *) + echo "Usage: $0 {start|reset}" + exit 1 + ;; +esac + +exit 0 diff --git a/scripts/menu/main_menu.sh b/scripts/menu/main_menu.sh index 6dd28d3..20b02e3 100755 --- a/scripts/menu/main_menu.sh +++ b/scripts/menu/main_menu.sh @@ -2,6 +2,11 @@ set -e +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 + get_model=$( /usr/bin/get_sn_mac.sh model 2>&1 ) if echo "$get_model" | grep -iq "K1"; then model="K1" diff --git a/scripts/tools.sh b/scripts/tools.sh index ac0b915..1166ef8 100755 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -85,9 +85,7 @@ function reset_factory_settings_message(){ echo -e " │ ${cyan}settings only performs a partial reset. ${white}│" hr echo -e " │ ${cyan}Note: After factory reset all features already been ${white}│" - echo -e " │ ${cyan}installed with Creality Helper Script must be reinstalled ${white}│" - echo -e " │ ${cyan}and it's necessary to reconnect your printer to your network ${white}│" - echo -e " │ ${cyan}from screen settings in 'Settings' → 'Network' tab. ${white}│" + echo -e " │ ${cyan}installed with Creality Helper Script must be reinstalled. ${white}│" hr bottom_line } @@ -339,6 +337,7 @@ function clear_cache(){ echo -e "Info: Clearing git cache..." cd "${HELPER_SCRIPT_FOLDER}" git gc --aggressive --prune=all + pip cache purge ok_msg "Cache has been cleared!" return;; N|n) @@ -412,8 +411,7 @@ function reset_factory_settings(){ case "${yn}" in Y|y) echo -e "${white}" - echo -e "Info: Restoration..." - echo "all" | nc -U /var/run/wipe.sock + "$INITD_FOLDER"/S58factoryreset reset ;; N|n) error_msg "Reset canceled!"