Creality-Helper-Script/files/services/S58factoryreset

63 lines
2 KiB
Text
Raw Permalink Normal View History

2024-05-19 17:52:17 +02:00
#!/bin/sh
#
2024-05-21 11:29:51 +02:00
# This script does the equivalent of `echo "all" | nc -U /var/run/wipe.sock`
2024-05-19 17:52:17 +02:00
#
factory_reset() {
/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
2024-06-30 11:37:20 +02:00
/usr/bin/find /overlay/upper/ \
-path '/overlay/upper/etc/dropbear' -prune -o \
-path /overlay/upper/etc/localtime -prune -o \
-path /overlay/upper/etc/init.d/S58factoryreset -prune -o \
2024-06-14 01:48:34 +02:00
-exec rm {} \; >/dev/null 2>&1
/usr/bin/find /overlay/upper/ -type d \
-depth -print \
-exec rmdir {} \; >/dev/null 2>&1
2024-05-21 11:29:51 +02:00
/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
/usr/bin/find /usr/data/creality/userdata \
-path '/usr/data/creality/userdata/config/system_config.json' -prune -o \
-path '/usr/data/creality/userdata/user_agree_root' -prune -o \
-path '/usr/data/creality/userdata' -o -type d -o -print \
-exec rm {} \; >/dev/null 2>&1
/usr/bin/find /usr/data/creality/ \
-depth -print \
-exec rmdir {} \; >/dev/null 2>&1
2024-05-19 17:52:17 +02:00
/bin/sync >/dev/null 2>&1
/sbin/swapoff -a >/dev/null 2>&1
/sbin/reboot -f >/dev/null 2>&1
}
case "$1" in
start)
2024-12-10 13:04:50 +01:00
FLAG_FILE=$(ls /tmp/udisk/sda*/factory_reset 2> /dev/null)
2024-11-28 22:14:33 +01:00
if [ $? -eq 0 ] && [ "x$FLAG_FILE" != "x" ]; then
FLAG_FILE=$(echo $FLAG_FILE | awk '{print $1}')
2024-05-19 17:52:17 +02:00
echo "Info: Executing factory reset..."
2024-11-28 22:14:33 +01:00
mv "$FLAG_FILE" "${FLAG_FILE}.old" >/dev/null 2>&1
2024-05-19 17:52:17 +02:00
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