Skip to content

Commit df40f6f

Browse files
committed
feat(bluefin): update rollback-helper script
1 parent 5e1c445 commit df40f6f

1 file changed

Lines changed: 68 additions & 77 deletions

File tree

system_files/shared/usr/bin/ublue-rollback-helper

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,89 @@
22

33
#shellcheck disable=1091
44
source /usr/lib/ujust/ujust.sh
5+
56
IMAGE_INFO="/usr/share/ublue-os/image-info.json"
6-
IMAGE_NAME=$(jq -r '."image-name"' < $IMAGE_INFO)
7-
IMAGE_TAG=$(jq -r '."image-tag"' < $IMAGE_INFO)
8-
IMAGE_VENDOR=$(jq -r '."image-vendor"' < $IMAGE_INFO)
9-
FEDORA_VERSION=$(jq -r '."fedora-version"' < $IMAGE_INFO)
7+
IMAGE_NAME=$(jq -r '."image-name"' < "$IMAGE_INFO")
8+
IMAGE_TAG=$(jq -r '."image-tag"' < "$IMAGE_INFO")
9+
IMAGE_VENDOR=$(jq -r '."image-vendor"' < "$IMAGE_INFO")
10+
FEDORA_VERSION=$(jq -r '."fedora-version"' < "$IMAGE_INFO")
1011
IMAGE_REGISTRY="ghcr.io/${IMAGE_VENDOR}"
12+
ROOT_FS=$(findmnt -n -o FSTYPE /)
1113

12-
#Check if composefs is enabled
14+
# ComposeFS detection
1315
if findmnt / | grep -q 'composefs' && findmnt / | grep -q 'overlay'; then
1416
composefs_enabled=true
1517
else
1618
composefs_enabled=false
1719
fi
1820

19-
function list_tags(){
20-
skopeo list-tags "docker://${IMAGE_REGISTRY}/${IMAGE_NAME}" | grep -E --color=never -- "$FEDORA_VERSION-([0-9]+)" | sort -rV | head -n 31
21+
function list_tags() {
22+
local filter="$1"
23+
skopeo list-tags "docker://${IMAGE_REGISTRY}/${IMAGE_NAME}" \
24+
| jq -r '.Tags[]' \
25+
| grep -E --color=never "$filter" \
26+
| sort -rV | head -n 31
2127
}
2228

23-
function rebase_helper(){
24-
base_image="${IMAGE_REGISTRY}/${IMAGE_NAME}"
25-
echo "Which Tag would you like to rebase to?"
26-
27-
if [[ "$composefs_enabled" == "true" ]]; then
28-
CHANNELS=(latest stable stable-daily)
29-
echo "The default selection is latest, stable (weekly builds) and stable-daily (daily builds) are for enthusiasts, and latest is for testers"
30-
echo "Note: Since you are on Fedora 42+, you will not be able to rollback to the GTS version."
31-
elif [[ "$composefs_enabled" == "false" ]]; then
32-
CHANNELS=(latest stable stable-daily gts)
33-
echo "The default selection is gts, stable (weekly builds) and stable-daily (daily builds) are for enthusiasts, and latest is for testers"
34-
fi
35-
36-
for channel in "${CHANNELS[@]}"; do
37-
if [[ "$channel" == "gts" ]]; then
38-
version=$(( ${VERSIONS_LIST[0]} - 1 ))
39-
elif [[ "$channel" == "stable-daily" ]]; then
40-
version="${VERSIONS_LIST[1]}"
41-
else
42-
version=$(skopeo inspect --no-tags docker://ghcr.io/ublue-os/bluefin-dx:$channel | jq -r '.Labels["org.opencontainers.image.version"]' | sed 's/.*-//' | cut -c 1-2)
43-
fi
44-
VERSIONS_LIST+=("$version")
45-
CHANNELS_F+=("$channel (F$version)")
46-
done
47-
48-
choose_target=$(Choose date "${CHANNELS_F[@]}" cancel)
49-
if [[ "$choose_target" != "date" && "$choose_target" != "cancel" ]]; then
50-
choose_target=${choose_target%% *}
51-
rebase_target="${base_image}:${choose_target}"
52-
elif [[ "$choose_target" == "date" ]]; then
53-
# shellcheck disable=SC2207
54-
echo "Warning: This will pin you to a specific version, do not forget to rebase back to a channel to resume receiving updates."
55-
valid_tags=( $(list_tags | sed 's/\"//g' | sed 's/,//g'))
56-
target_tag=$(Choose cancel "${valid_tags[@]}")
57-
if grep -Eq "$FEDORA_VERSION-([0-9]+)" <<< "${target_tag}"; then
58-
# target_tag=${target_tag:1:-2}
59-
rebase_target="${base_image}:$target_tag"
60-
else
61-
return 1
62-
fi
63-
64-
else
65-
return 1
66-
fi
67-
if [[ "$choose_target" =~ "gts" && "$IMAGE_TAG" != "$choose_target" ]]; then
68-
echo "Warning rolling back Major Fedora Versions may not work"
69-
fi
70-
if [[ "$choose_target" != "gts" && "$IMAGE_TAG" = "gts" ]]; then
71-
echo "Rebase to a non-GTS version is a one-way operation, you will not be able to rollback to GTS."
72-
echo "Is this what you want to do?"
73-
if [[ $(Confirm) -ne "0" ]]; then
74-
return 1
75-
fi
76-
fi
77-
78-
echo "Rebase Target is ${rebase_target}"
79-
echo "Confirm Rebase"
80-
if [[ $(Confirm) -ne "0" ]]; then
81-
return 1
82-
fi
83-
84-
if /usr/bin/grep "^LockLayering=true" /etc/rpm-ostreed.conf &> /dev/null; then
85-
pkexec bootc switch --enforce-container-sigpolicy "${rebase_target}"
86-
return 0
87-
fi
29+
function rebase_helper() {
30+
echo "Current image: ${IMAGE_NAME}:${IMAGE_TAG} (Fedora ${FEDORA_VERSION})"
31+
echo "Root filesystem: ${ROOT_FS}"
32+
echo
33+
34+
# Step 1: Choose image variant
35+
echo "Select your Bluefin image:"
36+
IMAGE_OPTIONS=("bluefin" "bluefin-dx" "cancel")
37+
selected_image=$(Choose "${IMAGE_OPTIONS[@]}")
38+
[[ "$selected_image" == "cancel" ]] && exit 0
39+
40+
IMAGE_NAME="$selected_image"
41+
base_image="${IMAGE_REGISTRY}/${IMAGE_NAME}"
42+
43+
# Step 2: Channel Selection
44+
declare -a CHANNELS
45+
CHANNELS=(latest stable stable-daily)
46+
echo "Available channels: latest, stable (weekly builds), stable-daily (daily builds)"
47+
echo "latest is for testers. stable/stable-daily are for enthusiasts."
48+
49+
channel_selected=$(Choose "${CHANNELS[@]}" cancel)
50+
[[ "$channel_selected" == "cancel" ]] && exit 0
51+
52+
rebase_target="${base_image}:${channel_selected}"
53+
54+
# Step 3: Date selection (scoped to channel)
55+
echo "Would you like to pin to a specific build date?"
56+
date_choice=$(Choose "no" "yes" cancel)
57+
[[ "$date_choice" == "cancel" ]] && return 1
58+
59+
if [[ "$date_choice" == "yes" ]]; then
60+
echo "Fetching available tags for channel: $channel_selected..."
61+
filter="${channel_selected}-[0-9]{8}"
62+
63+
valid_tags=( $(list_tags "$filter") )
64+
[[ "${#valid_tags[@]}" -eq 0 ]] && { echo "No tags found for filter: $filter"; return 1; }
65+
66+
selected_tag=$(Choose cancel "${valid_tags[@]}")
67+
[[ "$selected_tag" == "cancel" ]] && return 1
68+
69+
rebase_target="${base_image}:${selected_tag}"
70+
fi
71+
72+
echo "Rebase target: ${rebase_target}"
73+
echo "Confirm rebase?"
74+
[[ $(Confirm) -ne 0 ]] && return 1
75+
76+
if grep -q "^LockLayering=true" /etc/rpm-ostreed.conf; then
77+
pkexec bootc switch --enforce-container-sigpolicy "${rebase_target}"
78+
else
8879
rpm-ostree rebase ostree-image-signed:docker://"${rebase_target}"
89-
return 0
80+
fi
9081
}
9182

92-
echo "Choose your action."
83+
# Entry point
84+
echo "Choose your action:"
9385
option=$(Choose rebase cancel)
94-
9586
if [[ "$option" == "rebase" ]]; then
96-
rebase_helper || /usr/bin/ublue-rollback-helper
87+
rebase_helper || /usr/bin/ublue-rollback-helper
9788
else
98-
exit 0
89+
exit 0
9990
fi

0 commit comments

Comments
 (0)