This commit is contained in:
Cyril 2024-05-19 17:52:17 +02:00
parent 1c54a94e8e
commit 3bcde4c953
3 changed files with 53 additions and 5 deletions

45
files/services/S58factoryreset Executable file
View file

@ -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

View file

@ -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"

View file

@ -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!"