Skip to content

Commit

Permalink
chore(bazzite-rollback-helper): Minor tweaks (#1805)
Browse files Browse the repository at this point in the history
* chore(bazzite-rollback-helper): Return 1 errcode on unsuccesful rebase

* chore(bazzite-rollback-helper): Add '-y' flag to skip confirmation on rebase

* chore(bazzite-rollback-helper): Confirmation on rebase defaults to yes

* chore(bazzite-rollback-helper): Reword rebase cancelation message

* chore(bazzite-rollback-helper): Comment out debug messages
  • Loading branch information
Zeglius authored Oct 29, 2024
1 parent ba42e0e commit 8c4e1c1
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions system_files/desktop/shared/usr/bin/bazzite-rollback-helper
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ INPUTS:
echo "$_help" && return
fi

# Skip asking for confirmation by passing the '-y' flag
local CONFIRM_YES
CONFIRM_YES=$(
while (( $# )); do
case "$1" in
-y|--yes) echo 1; return ;;
esac
shift
done
echo 0
)

# Fetch our image reference prefix (ex.: ostree-image-signed:docker://ghcr.io/ublue-os)
# from rpm-ostree
local base_img_pfx
Expand All @@ -106,29 +118,34 @@ INPUTS:
"") echo >&2 "$_help"; return ;;
ostree-image-*)
# ostree-image
echo >&2 "Format detected"
# echo >&2 "Format detected"
img_ref=$usr_inpt
;;
*:*)
# IMG_NAME:TAG
echo >&2 "Format detected: IMG_NAME:TAG"
# echo >&2 "Format detected: IMG_NAME:TAG"
img_ref="$base_img_pfx"/"$usr_inpt"
;;
*)
# TAG
echo >&2 "Format detected: TAG"
# echo >&2 "Format detected: TAG"
img_ref="$base_img_pfx"/"$DEFAULT_IMAGE":"$usr_inpt"
;;
esac

# Ask for confirmation. If is okay, rebase.
local question="\
Rebasing to $img_ref. Continue? [y/N]: "
read -rp "$question" yn
Rebasing to $img_ref. Continue? [Y/n]: "
local yn
if [[ $CONFIRM_YES -ne 1 ]]; then
read -rp "$question" yn
yn=${yn:=y} # Default to yes
else yn=y
fi
case $yn in
# Finally, rebase
[yY]) rpm-ostree rebase "$img_ref" ;;
*) echo >&2 "Canceling..."; return ;;
[yY]) rpm-ostree rebase "$img_ref" || return 1 ;;
*) echo >&2 "Stopping rebase..."; return 1 ;;
esac
}

Expand Down

0 comments on commit 8c4e1c1

Please sign in to comment.