Skip to content

Commit

Permalink
Merge branch 'unstable' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGospo committed Oct 28, 2024
2 parents 2ad5c3b + d79e02a commit e36a10b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
is_latest_version: true
is_stable_version: true
kernel_flavor: bazzite # must match a kernel_flavor from akmods repo
kernel_version: 6.11.5-306.bazzite.fc41.x86_64 # must match a cached version of the above flavor
kernel_version: 6.11.5-307.bazzite.fc41.x86_64 # must match a cached version of the above flavor
exclude:
- base_name: bazzite
target_nvidia_flavor: nvidia
Expand Down
149 changes: 107 additions & 42 deletions system_files/desktop/shared/usr/bin/bazzite-rollback-helper
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

image="$(echo $2 | cut -d ':' -f1)"
branch="$(echo $2 | cut -d ':' -f2)"
image="$(echo "$2" | cut -d ':' -f1)"
branch="$(echo "$2" | cut -d ':' -f2)"

IMAGE_INFO="/usr/share/ublue-os/image-info.json"
DEFAULT_IMAGE=$(jq -r '."image-name"' < $IMAGE_INFO)
Expand All @@ -17,10 +17,10 @@ This tool aims to help with rollbacks and rebases
Usage: bazzite-rollback-helper [OPTION] [ARGUMENT]
Options:
list List available Bazzite images, Default is "$DEFAULT_BRANCH"
rollback Rolls back to previously installed Bazzite image. alias for "rpm-ostree rollback"
current Show currently active Bazzite image
rebase Rebase/rollback to specified Bazzite image, Default is $DEFAULT_IMAGE:$DEFAULT_BRANCH
list [BRANCH] List available Bazzite images, Default is "$DEFAULT_BRANCH"
rollback Rolls back to previously installed Bazzite image. alias for "rpm-ostree rollback"
current Show currently active Bazzite image
rebase Rebase/rollback to specified Bazzite image, Default is $DEFAULT_IMAGE:$DEFAULT_BRANCH
Examples:
bazzite-rollback-helper list stable
Expand All @@ -38,50 +38,115 @@ EOF
)


if [[ "$1" == "list" ]]; then
if [ -z "$2" ]; then
echo "Listing images for $DEFAULT_BRANCH"
skopeo list-tags docker://ghcr.io/ublue-os/bazzite | grep -E "\"$DEFAULT_BRANCH-[0-9]+\.[0-9]+|-$DEFAULT_BRANCH-[0-9]+" | sort -rV
else
echo "Listing images for $2"
skopeo list-tags docker://ghcr.io/ublue-os/bazzite | grep -E "\"$2-[0-9]+\.[0-9]+|-$2-[0-9]+" | sort -rV
function list_images() {
local _help="\
List images with a specified tag
INPUTS:
\$1: branch Branch we want to get tags from.
Fallbacks to \"$DEFAULT_BRANCH\"
"
if [[ $* =~ --help ]]; then
echo "$_help" && return
fi
local branch=${1:-$DEFAULT_BRANCH}
local regex='.Tags[]'
regex="$regex"\ ' | select(test("^PLACEHOLDER|^PLACEHOLDER-(?:\\d+\\.\\d+|\\d+)"))'
regex=${regex//PLACEHOLDER/$branch}
echo -e >&2 "Listing images for $branch\nThis can take a bit of time..."
skopeo list-tags docker://ghcr.io/ublue-os/bazzite | jq -r "$regex"
}

function current() {
local _help="\
Show currently active Bazzite image"
if [[ $* =~ --help ]]; then
echo "$_help" && return
fi

elif [[ "$1" == "rollback" ]]; then
rpm-ostree rollback
echo "Reboot for changes to take effect"
rpm-ostree status -vb
}

elif [[ "$1" == "current" ]]; then
# current image
rpm-ostree status | grep ●
# current version
rpm-ostree status | grep -A 5 "" | tail -n +2
function rollback() {
local _help="Rolls back to previously installed Bazzite image. alias for \"rpm-ostree rollback\""
if [[ $* =~ --help ]]; then
echo "$_help" && return
fi

elif [[ "$1" == "rebase" ]]; then
base_image=ostree-image-signed:docker://ghcr.io/ublue-os
rebase_target=$DEFAULT_IMAGE:$DEFAULT_BRANCH

if [ -z "$2" ]; then
rebase_target=$DEFAULT_IMAGE:$DEFAULT_BRANCH
else
if [ "$image" == "$branch" ]; then
# only branch was provided as an arg, use default image
rebase_target=$DEFAULT_IMAGE:$branch
else
rebase_target=$image:$branch
fi
rpm-ostree rollback && \
echo >&2 "Reboot for changes to take effect"
}

function rebase() {
local _help="\
Rebase/rollback to specified Bazzite image, Default is $DEFAULT_IMAGE:$DEFAULT_BRANCH
INPUTS:
\$1: branch Branch we want to rebase. Format must be
one of the following:
- ostree-image (ex.: 'ostree-image-signed:docker://ghcr.io/ublue-os/bazzite:stable')
- NAME:TAG (ex.: 'bazzite:stable-40')
- TAG (ex.: 'testing')
Fallbacks to \"$DEFAULT_BRANCH\"\
"
if [[ $* =~ --help ]]; then
local _help
echo "$_help" && return
fi
full_image_path=$base_image/$rebase_target

question=$(cat <<EOF
Rebasing to $full_image_path. Continue? [y/N]:
EOF
)
read -p "$question" yn
# Fetch our image reference prefix (ex.: ostree-image-signed:docker://ghcr.io/ublue-os)
# from rpm-ostree
local base_img_pfx
base_img_pfx=$(rpm-ostree status -b --json | jq -r '.deployments[]["container-image-reference"]')
base_img_pfx=${base_img_pfx///${DEFAULT_IMAGE}*/}

local img_ref # Final image ref string to rebase
local usr_inpt="$1"
case "$usr_inpt" in
"") echo >&2 "$_help"; return ;;
ostree-image-*)
# ostree-image
echo >&2 "Format detected"
img_ref=$usr_inpt
;;
*:*)
# IMG_NAME:TAG
echo >&2 "Format detected: IMG_NAME:TAG"
img_ref="$base_img_pfx"/"$usr_inpt"
;;
*)
# 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
case $yn in
[Yy]) echo "rebasing to $rebase_target" && rpm-ostree rebase $full_image_path && echo "Reboot for changes to take effect";;
*) echo "Unknown option, exiting.";;
# Finally, rebase
[yY]) rpm-ostree rebase "$img_ref" ;;
*) echo >&2 "Canceling..."; return ;;
esac
}

if [[ "$1" == "list" ]]; then
list_images "${@:2}"
exit

elif [[ "$1" == "rollback" ]]; then
rollback "${@:2}"
exit

elif [[ "$1" == "current" ]]; then
current "${@:2}"
exit

elif [[ "$1" == "rebase" ]]; then
rebase "${@:2}"
exit

# display the helptext
elif [[ "$1" == "-h" || "$1" == "--h" || "$1" == "-help" || "$1" == "--help" || "$1" == "help" || -z "$1" ]]; then
Expand Down
1 change: 1 addition & 0 deletions system_files/desktop/shared/usr/bin/brh

0 comments on commit e36a10b

Please sign in to comment.