Skip to content

Commit f783b6b

Browse files
author
linux_name2
committed
fix(atomic-guard): graceful degradation when common.sh fails to load
1 parent 7bac764 commit f783b6b

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

‎bin/atomic-guard‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
# checks and process-tree walking that would break with errexit.
99

1010
readonly LIBDIR="/usr/lib/atomic"
11-
_p=$(verify-lib "${LIBDIR}/common.sh" "$LIBDIR/" 2>/dev/null) && source "$_p"
11+
12+
# Load common.sh with graceful degradation
13+
_COMMON_LOADED=0
14+
if _p=$(verify-lib "${LIBDIR}/common.sh" "$LIBDIR/" 2>/dev/null) && [[ -n "$_p" ]]; then
15+
if source "$_p" 2>/dev/null; then
16+
_COMMON_LOADED=1
17+
fi
18+
fi
19+
1220
LOCK_FILE="${LOCK_FILE:-/var/lock/atomic-upgrade.lock}"
1321

1422
# If guard is disabled in config, allow everything
@@ -25,9 +33,6 @@ if [[ "${ATOMIC_UPGRADE:-}" == "1" ]]; then
2533
fi
2634

2735
# ── Sysupgrade detection ────────────────────────────────────────
28-
# Only block full system upgrades (-Su / -Syu / --sync --sysupgrade).
29-
# Walk up the process tree to find the pacman process, then inspect
30-
# its cmdline arguments.
3136
is_sysupgrade() {
3237
local pid=$$
3338
while [[ $pid -ne 1 ]]; do
@@ -48,7 +53,6 @@ is_sysupgrade() {
4853
fi
4954
pid=$(awk '/^PPid:/{print $2}' "/proc/$pid/status" 2>/dev/null) || break
5055
done
51-
# Cannot find pacman in process tree — block for safety
5256
echo "atomic-guard: pacman not found in process tree, blocking" >&2
5357
return 0
5458
}
@@ -58,11 +62,31 @@ if ! is_sysupgrade; then
5862
fi
5963

6064
# Allow AUR helpers — walk up the process tree via /proc
61-
62-
if type -t is_child_of_aur_helper &>/dev/null && is_child_of_aur_helper; then
63-
echo -e "\033[33mNOTE: AUR helper sysupgrade runs on live system (not atomic)\033[0m" >&2
64-
echo -e "\033[33m For atomic upgrades use: sudo atomic-upgrade\033[0m" >&2
65-
exit 0
65+
if [[ $_COMMON_LOADED -eq 1 ]]; then
66+
if type -t is_child_of_aur_helper &>/dev/null && is_child_of_aur_helper; then
67+
echo -e "\033[33mNOTE: AUR helper sysupgrade runs on live system (not atomic)\033[0m" >&2
68+
echo -e "\033[33m For atomic upgrades use: sudo atomic-upgrade\033[0m" >&2
69+
exit 0
70+
fi
71+
else
72+
# Fallback: inline AUR helper check when common.sh failed to load
73+
_check_aur_helper() {
74+
local pid=$$
75+
while [[ $pid -ne 1 ]]; do
76+
local comm
77+
comm=$(cat "/proc/$pid/comm" 2>/dev/null) || break
78+
case "$comm" in
79+
yay|paru|pikaur|aura) return 0 ;;
80+
esac
81+
pid=$(awk '/^PPid:/{print $2}' "/proc/$pid/status" 2>/dev/null) || break
82+
done
83+
return 1
84+
}
85+
if _check_aur_helper; then
86+
echo -e "\033[33mNOTE: AUR helper sysupgrade runs on live system (not atomic)\033[0m" >&2
87+
echo -e "\033[33m For atomic upgrades use: sudo atomic-upgrade\033[0m" >&2
88+
exit 0
89+
fi
6690
fi
6791

6892
cat << 'EOF'

0 commit comments

Comments
 (0)