Skip to content

Commit 50308c5

Browse files
committed
fix: pipefail for dnf exit codes in update script
1 parent 52083f0 commit 50308c5

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

update.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,13 @@ do_version_upgrade() {
463463
download_output=$(mktemp)
464464
chmod 600 "$download_output" # Restrict permissions on temp file
465465

466-
# Use PIPESTATUS to capture dnf exit code, not tee's
467-
sudo dnf system-upgrade download --releasever="$target_version" -y 2>&1 | tee "$download_output"
468-
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
466+
# Use subshell with pipefail to capture dnf exit code correctly
467+
local dnf_exit=0
468+
(
469+
set -o pipefail
470+
sudo dnf system-upgrade download --releasever="$target_version" -y 2>&1 | tee "$download_output"
471+
) || dnf_exit=$?
472+
if [ "$dnf_exit" -ne 0 ]; then
469473
# Check if version doesn't exist (catch 404 errors, missing repos, etc.)
470474
if grep -qiE "unable to find.*releasever|no such.*version|not found|status code: 404|Failed to download metadata|Cannot prepare internal mirrorlist" "$download_output" 2>/dev/null; then
471475
print_error "Fedora $target_version is not available yet."
@@ -495,9 +499,13 @@ do_version_upgrade() {
495499

496500
if [[ "$retry" =~ ^[Yy](es)?$ ]]; then
497501
print_warning "Using --allowerasing - review removed packages carefully!"
498-
# Use PIPESTATUS to capture dnf exit code, not tee's
499-
sudo dnf system-upgrade download --releasever="$target_version" --allowerasing -y 2>&1 | tee "$download_output"
500-
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
502+
# Use subshell with pipefail to capture dnf exit code correctly
503+
local dnf_exit=0
504+
(
505+
set -o pipefail
506+
sudo dnf system-upgrade download --releasever="$target_version" --allowerasing -y 2>&1 | tee "$download_output"
507+
) || dnf_exit=$?
508+
if [ "$dnf_exit" -ne 0 ]; then
501509
if grep -qiE "unable to find.*releasever|no such.*version|not found|status code: 404|Failed to download metadata|Cannot prepare internal mirrorlist" "$download_output" 2>/dev/null; then
502510
print_error "Fedora $target_version is not available."
503511
rm -f "$download_output"

0 commit comments

Comments
 (0)