Skip to content

Commit 1151ca3

Browse files
committed
desktops: gate pin-file on repo setup, write atomically
Review feedback on PR #838: 1. The pin-file block ran even when the repo setup was skipped (empty DESKTOP_REPO_URL), so a DE with `preferences:` but no matching `url`/`key_url`/`keyring` would create an orphan file under /etc/apt/preferences.d/. Nest the block inside the existing `[[ -n \$DESKTOP_REPO_URL ... ]]` guard so pins only land when the matching archive was actually configured. 2. The previous `: > \$pref_file` + `>>` loop left a truncated file on mid-write failure, which apt would misparse rather than ignore. Write to \${pref_file}.tmp, check each printf's exit status, and atomically `mv` on success. Any failure returns 1 (not exit 1 — that would kill armbian-config). No change to the emitted file content; smoke-tested against bianbu, still byte-identical to SpacemiT's documented pin file.
1 parent 0c27568 commit 1151ca3

1 file changed

Lines changed: 37 additions & 22 deletions

File tree

tools/modules/desktops/module_desktop_repo.sh

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,44 @@ function module_desktop_repo() {
5454
cat > "/etc/apt/sources.list.d/${de}.list" <<- EOF
5555
deb [signed-by=${DESKTOP_REPO_KEYRING}] ${DESKTOP_REPO_URL} ${DISTROID} main
5656
EOF
57-
fi
5857

59-
# Optional: write APT pin preferences. Only the fields emitted
60-
# by parse_desktop_yaml.py are trusted — no shell interpolation
61-
# of raw YAML strings.
62-
if [[ -n "${DESKTOP_REPO_PREFS_COUNT}" && "${DESKTOP_REPO_PREFS_COUNT}" -gt 0 ]]; then
63-
local pref_file="/etc/apt/preferences.d/${de}"
64-
: > "$pref_file"
65-
local i origin_var suite_var prio_var origin suite prio
66-
for (( i=0; i < DESKTOP_REPO_PREFS_COUNT; i++ )); do
67-
origin_var="DESKTOP_REPO_PREFS_${i}_ORIGIN"
68-
suite_var="DESKTOP_REPO_PREFS_${i}_SUITE"
69-
prio_var="DESKTOP_REPO_PREFS_${i}_PRIORITY"
70-
origin="${!origin_var}"
71-
suite="${!suite_var}"
72-
prio="${!prio_var}"
73-
{
74-
echo "Package: *"
75-
echo "Pin: release o=${origin}, n=${suite}"
76-
echo "Pin-Priority: ${prio}"
77-
echo
78-
} >> "$pref_file"
79-
done
58+
# Optional: APT pin preferences. Gated on the repo guard
59+
# above so prefs can only land when the matching archive
60+
# was actually configured. Written via temp + mv so a
61+
# mid-write failure never leaves a truncated stanza that
62+
# apt would misparse. Only fields emitted by
63+
# parse_desktop_yaml.py are interpolated.
64+
if [[ -n "${DESKTOP_REPO_PREFS_COUNT}" && "${DESKTOP_REPO_PREFS_COUNT}" -gt 0 ]]; then
65+
local pref_file="/etc/apt/preferences.d/${de}"
66+
local pref_tmp="${pref_file}.tmp"
67+
local i origin_var suite_var prio_var origin suite prio
68+
69+
if ! : > "$pref_tmp"; then
70+
echo "Error: cannot create ${pref_tmp}" >&2
71+
return 1
72+
fi
73+
74+
for (( i=0; i < DESKTOP_REPO_PREFS_COUNT; i++ )); do
75+
origin_var="DESKTOP_REPO_PREFS_${i}_ORIGIN"
76+
suite_var="DESKTOP_REPO_PREFS_${i}_SUITE"
77+
prio_var="DESKTOP_REPO_PREFS_${i}_PRIORITY"
78+
origin="${!origin_var}"
79+
suite="${!suite_var}"
80+
prio="${!prio_var}"
81+
if ! printf 'Package: *\nPin: release o=%s, n=%s\nPin-Priority: %s\n\n' \
82+
"$origin" "$suite" "$prio" >> "$pref_tmp"; then
83+
echo "Error: failed to write preferences for ${de}" >&2
84+
rm -f "$pref_tmp"
85+
return 1
86+
fi
87+
done
88+
89+
if ! mv "$pref_tmp" "$pref_file"; then
90+
echo "Error: failed to install ${pref_file}" >&2
91+
rm -f "$pref_tmp"
92+
return 1
93+
fi
94+
fi
8095
fi
8196
;;
8297
esac

0 commit comments

Comments
 (0)