Skip to content

Commit a226a21

Browse files
authored
feat: update rebase-helper (#775)
* feat: update rebase-helper * update some texts, put stable (weekly) as default * fix: fix some texts
1 parent a189716 commit a226a21

1 file changed

Lines changed: 76 additions & 42 deletions

File tree

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

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
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-
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")
11+
IMAGE_REGISTRY="ghcr.io/${IMAGE_VENDOR}"
12+
ROOT_FS=$(findmnt -n -o FSTYPE /)
913

1014
#Check if composefs is enabled
1115
if findmnt / | grep -q 'composefs' && findmnt / | grep -q 'overlay'; then
@@ -14,52 +18,82 @@ else
1418
composefs_enabled=false
1519
fi
1620

17-
function list_tags(){
18-
skopeo list-tags docker://ghcr.io/ublue-os/"${IMAGE_NAME}" | grep -E --color=never -- "$FEDORA_VERSION-([0-9]+)" | sort -rV | head -n 31
21+
22+
function list_tags() {
23+
local filter="$1"
24+
skopeo list-tags "docker://${IMAGE_REGISTRY}/${IMAGE_NAME}" \
25+
| jq -r '.Tags[]' \
26+
| grep -E --color=never "$filter" \
27+
| sort -rV | head -n 31
1928
}
2029

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

6095
echo "Choose your action."
6196
option=$(Choose rebase cancel)
62-
6397
if [[ "$option" == "rebase" ]]; then
6498
rebase_helper || /usr/bin/ublue-rollback-helper
6599
else

0 commit comments

Comments
 (0)