Skip to content

Commit 77df91c

Browse files
committed
chksysconfig: merge missing settings instead of overwriting user config
The verify function checks for a missing system.hostname to detect a corrupt or truncated system.cfg. The intent is to restore defaults so the system boots correctly. However, the current implementation runs `rsync -a /usr/config/ /storage/.config` which overwrites the entire user config tree — WiFi credentials, SSH settings, emulator preferences and per-game overrides are all replaced with factory defaults. This creates a cycle: the full rsync restores system.hostname, but EmulationStation's save logic strips settings that match its internal defaults (including system.hostname). On the next hard crash, the hostname is missing again, triggering another full overwrite. Replace the destructive rsync with a merge that adds keys present in the reference config but missing from the user config. Existing user settings are preserved. Retroarch config restoration is separated to only run when those specific files are actually missing. Observed on RK3566 (RGB30) during thermal shutdown and on Retroid Pocket 5 during hard crashes from stress testing.
1 parent 18d80a9 commit 77df91c

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

  • projects/ROCKNIX/packages/rocknix/sources/scripts

projects/ROCKNIX/packages/rocknix/sources/scripts/chksysconfig

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,38 @@ restore() {
1818
cp ${CFG_PATH}/system.cfg.backup ${CFG_PATH}/system.cfg
1919
}
2020

21+
merge_missing_settings() {
22+
local ref="/usr/config/system/configs/system.cfg"
23+
[ ! -f "$ref" ] && return
24+
local tmp="${CFG_PATH}/system.cfg.merge"
25+
cp "${CFG_PATH}/system.cfg" "$tmp"
26+
while IFS='=' read -r key value; do
27+
[[ -z "$key" || "$key" = \#* ]] && continue
28+
if ! grep -q "^${key}=" "$tmp" 2>/dev/null; then
29+
echo "${key}=${value}" >> "$tmp"
30+
fi
31+
done < "$ref"
32+
sort "$tmp" > "${CFG_PATH}/system.cfg"
33+
rm -f "$tmp"
34+
}
35+
2136
verify() {
2237
TYPE=$(grep a ${CFG_PATH}/system.cfg 2>&1)
2338
if [[ "${TYPE}" =~ binary ]]; then
2439
restore
2540
fi
2641

27-
# Check if any configs are missing and restore everything if they are
42+
# Restore retroarch configs if missing entirely
2843
if [ ! -s /storage/.config/retroarch/retroarch-core-options.cfg ] || \
29-
[ ! -s /storage/.config/retroarch/retroarch.cfg ] || \
30-
! grep -q system.hostname /storage/.config/system/configs/system.cfg; then
31-
rsync -a /usr/config/ /storage/.config
44+
[ ! -s /storage/.config/retroarch/retroarch.cfg ]; then
45+
rsync -a /usr/config/retroarch/ /storage/.config/retroarch/
46+
fi
47+
48+
# If system.cfg is missing critical settings (e.g. after a hard crash
49+
# that truncated the file), merge any missing keys from the reference
50+
# config rather than overwriting all user settings with rsync.
51+
if ! grep -q system.hostname ${CFG_PATH}/system.cfg 2>/dev/null; then
52+
merge_missing_settings
3253
fi
3354
}
3455

0 commit comments

Comments
 (0)