Skip to content

Commit 50a22f0

Browse files
author
guoping.liu
committed
fixed debug handler and factory reset for z2m
1 parent 68db5c4 commit 50a22f0

File tree

5 files changed

+701
-70
lines changed

5 files changed

+701
-70
lines changed

config/sources/families/trhub.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ family_tweaks_bsp() {
266266
cp "$SRC/packages/bsp/thirdreality/common/hubv3-usb-sync.service" "$destination/lib/systemd/system/" || exit_with_error "Unable to copy hubv3-usb-sync.service"
267267
chmod a+x "$destination/lib/thirdreality/hubv3-usb-sync.sh" || exit_with_error "Unable to set hubv3-usb-sync.sh script mode"
268268

269+
cp "$SRC/packages/bsp/thirdreality/common/hubv3-generate-ota-indexes.sh" "$destination/lib/thirdreality/" || exit_with_error "Unable to copy hubv3-generate-ota-indexes.sh"
270+
chmod a+x "$destination/lib/thirdreality/hubv3-generate-ota-indexes.sh" || exit_with_error "Unable to set hubv3-generate-ota-indexes.sh script mode"
271+
269272
mkdir -p --mode=775 "$destination/etc/udev/rules.d/" || exit_with_error "Unable to mkdir rules.d"
270273
cp "$SRC/packages/bsp/thirdreality/common/20-usb-mount.rules" "$destination/etc/udev/rules.d/" || exit_with_error "Unable to copy 20-usb-mount.rules"
271274

packages/bsp/thirdreality/common/factory-reset-supervised.sh

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@ error_handler() {
2121

2222
trap 'error_handler $LINENO' ERR
2323

24-
systemctl stop haos-agent > /dev/null 2>&1 || true
25-
systemctl stop hassio-apparmor > /dev/null 2>&1 || true
26-
systemctl stop hassio-supervisor > /dev/null 2>&1 || true
27-
28-
systemctl disable haos-agent > /dev/null 2>&1 || true
29-
systemctl disable hassio-apparmor > /dev/null 2>&1 || true
30-
systemctl disable hassio-supervisor > /dev/null 2>&1 || true
31-
32-
apt-get remove -y homeassistant-supervised os-agent
33-
apt-get remove -y homeassistant-supervised\* > /dev/null 2>&1 || true
34-
35-
if [ -f "/usr/bin/docker" ]; then
36-
# Stop and kill containers and images.
37-
for repo in "${repositories_to_remove[@]}"; do
38-
images=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "^$repo" || true)
39-
if [ ! -z "$images" ]; then
40-
for image in $images; do
41-
containers=$(docker ps -a -q --filter ancestor="$image")
42-
if [ -n "$containers" ]; then
43-
echo "Stopping containers based on image: $image"
44-
docker stop $containers
45-
docker rm $containers
46-
fi
24+
# systemctl stop haos-agent > /dev/null 2>&1 || true
25+
# systemctl stop hassio-apparmor > /dev/null 2>&1 || true
26+
# systemctl stop hassio-supervisor > /dev/null 2>&1 || true
27+
28+
# systemctl disable haos-agent > /dev/null 2>&1 || true
29+
# systemctl disable hassio-apparmor > /dev/null 2>&1 || true
30+
# systemctl disable hassio-supervisor > /dev/null 2>&1 || true
31+
32+
# apt-get remove -y homeassistant-supervised os-agent
33+
# apt-get remove -y homeassistant-supervised\* > /dev/null 2>&1 || true
34+
35+
# if [ -f "/usr/bin/docker" ]; then
36+
# # Stop and kill containers and images.
37+
# for repo in "${repositories_to_remove[@]}"; do
38+
# images=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "^$repo" || true)
39+
# if [ ! -z "$images" ]; then
40+
# for image in $images; do
41+
# containers=$(docker ps -a -q --filter ancestor="$image")
42+
# if [ -n "$containers" ]; then
43+
# echo "Stopping containers based on image: $image"
44+
# docker stop $containers
45+
# docker rm $containers
46+
# fi
4747

48-
echo "Removing image: $image"
49-
docker rmi "$image"
50-
done
51-
fi
52-
done
53-
54-
echo "Selected containers stopped and images removed successfully."
55-
56-
sleep 5
57-
docker system prune -a -f > /dev/null 2>&1
58-
59-
apt-get remove -y docker-ce docker-ce-cli containerd.io
60-
apt-get remove -y docker-compose-plugin
61-
apt-get remove -y docker-compose
62-
apt-get remove -y docker.io
63-
apt-get remove -y docker
64-
apt-get remove -y docker-doc
65-
apt-get remove -y docker-registry
66-
fi
48+
# echo "Removing image: $image"
49+
# docker rmi "$image"
50+
# done
51+
# fi
52+
# done
53+
54+
# echo "Selected containers stopped and images removed successfully."
55+
56+
# sleep 5
57+
# docker system prune -a -f > /dev/null 2>&1
58+
59+
# apt-get remove -y docker-ce docker-ce-cli containerd.io
60+
# apt-get remove -y docker-compose-plugin
61+
# apt-get remove -y docker-compose
62+
# apt-get remove -y docker.io
63+
# apt-get remove -y docker
64+
# apt-get remove -y docker-doc
65+
# apt-get remove -y docker-registry
66+
# fi
6767

6868
if [ -f "/etc/hassio.json" ]; then
6969
rm -rf /etc/hassio.json
@@ -77,25 +77,25 @@ if [ -d "/var/lib/homeassistant" ]; then
7777
rm -rf /var/lib/homeassistant
7878
fi
7979

80-
sync
80+
/usr/bin/sync
8181

8282
sleep 0.5
8383

8484
echo "Update WIFI settings ..."
8585

86+
if [ -e "/usr/bin/nmcli" ]; then
87+
nmcli -t -f UUID con show | xargs -I {} nmcli con delete uuid {} 2>/dev/null || true
88+
fi
89+
90+
/usr/bin/sync
91+
8692
# reset wifi connection information
8793
if [ -e "/etc/wpa_supplicant/wpa_supplicant-nl80211-wlan0.conf" ]; then
8894
rm -rf /etc/wpa_supplicant/wpa_supplicant-nl80211-wlan0.conf
89-
90-
if [ -e "/usr/sbin/dhclient" ]; then
91-
/usr/sbin/dhclient -r wlan0
92-
fi
93-
94-
if [ -f "/lib/systemd/system/setupwifi.service" ]; then
95-
systemctl disable setupwifi.service
96-
fi
9795
fi
9896

97+
/usr/bin/sync
98+
9999
echo "Factory reset completed. Rebooting now..."
100100

101101
sleep 5

packages/bsp/thirdreality/common/factory-reset.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ remove_homeassistant_core()
204204
apt-get purge -y thirdreality-python3.13 > /dev/null || true
205205
apt-get purge -y thirdreality-python3 > /dev/null || true
206206
apt-get purge -y thirdreality-otbr-agent > /dev/null || true
207-
apt-get purge -y thirdreality-zigbee-mqtt > /dev/null || true
207+
#apt-get purge -y thirdreality-zigbee-mqtt > /dev/null || true
208208

209209
apt-get autoremove -y >/dev/null || true
210210
systemctl daemon-reload
@@ -222,6 +222,18 @@ remove_zigbee2mqtt()
222222

223223
dpkg --configure -a > /dev/null || true
224224

225+
local z2m_backup_dir="/opt/z2m_tmp_backup"
226+
if [ -d /opt/zigbee2mqtt/data ]; then
227+
print_info "Backing up /opt/zigbee2mqtt/data before package removal"
228+
rm -rf /opt/zigbee2mqtt/data/log > /dev/null 2>&1 || true
229+
rm -rf "${z2m_backup_dir}" > /dev/null 2>&1 || true
230+
mkdir -p "${z2m_backup_dir}"
231+
cp -a /opt/zigbee2mqtt/data/. "${z2m_backup_dir}"/ >/dev/null 2>&1 || true
232+
233+
/usr/bin/sync
234+
/usr/bin/sync
235+
fi
236+
225237
apt-get purge -y thirdreality-zigbee-mqtt > /dev/null || true
226238
apt-get purge -y nodejs libsystemd-dev > /dev/null || true
227239
apt-get purge -y mosquitto mosquitto-clients > /dev/null || true
@@ -231,7 +243,18 @@ remove_zigbee2mqtt()
231243
systemctl daemon-reload
232244
userdel mosquitto > /dev/null 2>&1 || true
233245

234-
rm -rf /opt/zigbee2mqtt > /dev/null 2>&1 || true
246+
if [ -d "${z2m_backup_dir}" ]; then
247+
print_info "Restoring Zigbee2MQTT data from temporary backup"
248+
rm -rf /opt/zigbee2mqtt > /dev/null 2>&1 || true
249+
mkdir -p /opt/zigbee2mqtt/data
250+
cp -a "${z2m_backup_dir}"/. /opt/zigbee2mqtt/data/ >/dev/null 2>&1 || true
251+
rm -rf "${z2m_backup_dir}" > /dev/null 2>&1 || true
252+
253+
/usr/bin/sync
254+
/usr/bin/sync
255+
else
256+
rm -rf /opt/zigbee2mqtt > /dev/null 2>&1 || true
257+
fi
235258

236259
rm -rf /etc/mosquitto > /dev/null 2>&1 || true
237260
}

0 commit comments

Comments
 (0)