Skip to content

Commit

Permalink
Merge pull request #52 from ChimeraOS/stable-testing-support
Browse files Browse the repository at this point in the history
Improve matching of different image update channels
  • Loading branch information
alkazar authored Oct 9, 2023
2 parents 7a1edba + 913b7a8 commit e38d815
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 73 deletions.
140 changes: 108 additions & 32 deletions __frzr-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,110 @@ set -e
set -o pipefail

get_img_url() {
CHANNEL=$1

result=$(jq '[
sort_by(.created_at) |
reverse |
.[] |
{ name: .name, prerelease: .prerelease, state: .assets[].state, url: .assets[].browser_download_url } |
select(.url|test("img")) |
select(.state=="uploaded")
]')

if [ "$CHANNEL" == "testing" ]; then
result=$(echo $result | jq '[ .[] | select(.name|test("UNSTABLE")|not) ]')
elif [ "$CHANNEL" == "stable" ]; then
result=$(echo $result | jq '[ .[] | select(.prerelease==false) ]')
elif [ "$CHANNEL" != "unstable" ]; then
result=$(echo $result | jq "[ .[] | select(.url|contains(\"-${CHANNEL}_\")) ]")
fi

echo $result | jq 'first | .url' | sed 's/"//g'
CHANNEL=$1

# Order by creation date in reverse
result=$(jq 'sort_by(.created_at) | reverse')

# Remove entries which have not been completed uploading
result=$(echo "${result}" | jq 'del(.[] | select(.assets[].state != "uploaded"))')

# Always check for stable date
if stable_release_date=$(echo "${result}" | jq -er '[ .[] |
select(.prerelease==false) ] |
first |
.created_at'
); then
# Check for stable url, this is the latest that have prerelease == false
stable_download_url=$(echo "${result}" | jq -r '[ .[] |
select(.prerelease==false) ] |
first |
.assets[] |
select(.browser_download_url | test("img")) |
.browser_download_url'
)
else
# No stable channel found, pick some (old) values
# For testing/ channel selection
stable_release_date="1970-01-01T00:00:00Z"
stable_download_url=""
fi


# Filter channels by release naming conventions
if [[ "$CHANNEL" =~ ^[0-9]+\-?[0-9]*$ ]] ; then
# Check first for explicit version numbers between stable releases
# Useful for downgrading
result=$(echo "${result}" | jq -r "[ .[] |
select(.prerelease==false) |
select(.name|test(\" ${CHANNEL}\$\")) ] |
first |
.assets[] |
select(.browser_download_url | test(\"img\")) |
.browser_download_url"
)
elif [ "$CHANNEL" == "stable" ]; then
result=$stable_download_url
elif [ "$CHANNEL" == "testing" ]; then
# Testing channel have prerelease = true and no other tags
if testing_release_date=$(echo "${result}" | jq -er '[ .[] |
select(.prerelease==true) |
select(.name|test("\\[.*\\]")|not) ] |
first |
.created_at'
); then
testing_url=$(echo "${result}" | jq -r '[ .[] |
select(.prerelease==true) |
select(.name|test("\\[.*\\]")|not) ] |
first |
.assets[] |
select(.browser_download_url | test("img")) |
.browser_download_url'
)
if [ $(date -d $testing_release_date +%s) -le $(date -d $stable_release_date +%s) ]; then
result=$stable_download_url
else
result=$testing_url
fi
else
result=$stable_download_url
fi
else
# Match any release with CHANNEL as a tag (including unstable)
result=$(echo ${result} | jq "[ .[] | select(.prerelease==true) | select(.name|test(\"\\\[${CHANNEL}\\\]\" ; \"i\")) ]")
if unstable_release_date=$(echo "${result}" | jq -er "[ .[] |
select(.prerelease==true) |
select(.name|test(\"\\\[${CHANNEL}\\\]\" ; \"i\")) ] |
first |
.created_at"
); then
unstable_url=$(echo "${result}" | jq -r "[ .[] |
select(.prerelease==true) |
select(.name|test(\"\\\[${CHANNEL}\\\]\" ; \"i\")) ] |
first |
.assets[] |
select(.browser_download_url | test(\"img\")) |
.browser_download_url"
)
if [ $(date -d $unstable_release_date +%s) -le $(date -d $stable_release_date +%s) ]; then
result=$stable_download_url
else
result=$unstable_url
fi
else
result=$stable_download_url
fi
fi

echo $result
}

get_boot_cfg() {
local version=${1}
local amd_ucode=${2}
local intel_ucode=${3}
local additional_arguments=${4}

echo "title ${version}
linux /${version}/vmlinuz-linux
${amd_ucode}
Expand All @@ -47,7 +123,7 @@ get_deployment_to_delete() {
local deployment_path=${3}

local TO_BOOT=`get_next_boot_deployment ${current_version} ${boot_cfg_path}`

ls -1 ${deployment_path} | grep -v ${current_version} | grep -v ${TO_BOOT} | head -1 || echo
}

Expand All @@ -58,7 +134,7 @@ get_next_boot_deployment() {
local TO_BOOT='this-is-not-a-valid-version-string'
if [ -f "${boot_cfg_path}" ] && grep "^title" "${boot_cfg_path}" > /dev/null; then
TO_BOOT=`grep ^title ${boot_cfg_path} | sed 's/title //'`
fi
fi

echo ${TO_BOOT}
}
Expand Down Expand Up @@ -108,7 +184,7 @@ main() {
;;
esac
done

if [ ! -d /sys/firmware/efi/efivars ]; then
echo "Legacy BIOS installs are not supported. Aborting."
exit 1
Expand Down Expand Up @@ -137,7 +213,7 @@ main() {

DEPLOY_PATH=${MOUNT_PATH}/deployments
mkdir -p ${DEPLOY_PATH}

BOOT_CFG="${MOUNT_PATH}/boot/loader/entries/frzr.conf"
mkdir -p ${MOUNT_PATH}/boot/loader/entries

Expand Down Expand Up @@ -165,11 +241,11 @@ main() {
else
echo "WARNING: source wasn't specified"
fi

if [ "${local_install}" == true ]; then
mkdir tmp_source
mount -o rw -L FRZR_UPDATE /root/tmp_source
FILE_NAME=$(basename /root/tmp_source/*.img.tar.xz*)
FILE_NAME=$(basename /root/tmp_source/*.img.tar.xz*)
NAME=$(echo "${FILE_NAME}" | cut -f 1 -d '.')
SUBVOL="${DEPLOY_PATH}/${NAME}"
IMG_FILE="/root/tmp_source/${FILE_NAME}"
Expand Down Expand Up @@ -206,7 +282,7 @@ main() {
CHECKSUM=$(curl --http1.1 -L -s "${BASE_URL}/sha256sum.txt" | cut -f -1 -d ' ')
SUBVOL="${DEPLOY_PATH}/${NAME}"
IMG_FILE="${MOUNT_PATH}/${FILE_NAME}"

if [ -e ${SUBVOL} ]; then
echo "${NAME} already installed; aborting"
exit 7 # let Steam know there is no update available
Expand Down Expand Up @@ -248,7 +324,7 @@ main() {
else
tar xfO ${IMG_FILE} | btrfs receive --quiet ${DEPLOY_PATH}
fi

mkdir -p ${MOUNT_PATH}/boot/${NAME}
cp ${SUBVOL}/boot/vmlinuz-linux ${MOUNT_PATH}/boot/${NAME}
cp ${SUBVOL}/boot/initramfs-linux.img ${MOUNT_PATH}/boot/${NAME}
Expand Down Expand Up @@ -285,17 +361,17 @@ main() {
unset -f post_install
done
fi

# Export variables to be used by child processes for frzr-tweaks and frzr-initramfs
export MOUNT_PATH
export SUBVOL
export NAME

# Check if the FIRMWARE_OVERRIDE variable is set by the install media, if so enable firmware overrides
if [ -n "${FIRMWARE_OVERRIDE}" ]; then
echo "export USE_FIRMWARE_OVERRIDES=1" > ${MOUNT_PATH}/etc/device-quirks.conf
fi

# Run frzr-tweaks to execute the device-quirks to be supplied by the deployed images
frzr-tweaks

Expand Down
39 changes: 22 additions & 17 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,37 @@ check() {
echo
echo '== get_img_url'
echo '==== stable channel'
check 'should select the system image asset' $(cat test1.dat | get_img_url stable) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize latest stable asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer testing asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer unstable asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should select asset that is in `uploaded` state' $(cat test3a.dat | get_img_url unstable) 'chimeraos-1_0000001.img.tar.xz'
check 'should select the system image asset in stable' $(cat test1.dat | get_img_url stable) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize latest stable asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer testing asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer unstable asset' $(cat test2.dat | get_img_url stable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize uploaded stable asset over not-uploaded' $(cat test3a.dat | get_img_url stable) 'chimeraos-1_0000001.img.tar.xz'
check 'should handle non existing stable channel' $(cat test6.dat | get_img_url stable) ''

echo
echo '==== testing channel'
check 'should select the system image asset' $(cat test1.dat | get_img_url testing) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize stable asset over older testing asset' $(cat test2.dat | get_img_url testing) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer unstable asset' $(cat test2.dat | get_img_url testing) 'chimeraos-1_0000004.img.tar.xz'
check 'should select asset that is in `uploaded` state' $(cat test3b.dat | get_img_url unstable) 'chimeraos-1_0000001.img.tar.xz'
check 'should select the system image asset in testing' $(cat test1.dat | get_img_url testing) 'chimeraos-2_0000000.img.tar.xz'
check 'should prioritize stable asset over older testing asset' $(cat test2.dat | get_img_url testing) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over newer unstable asset' $(cat test2.dat | get_img_url testing) 'chimeraos-1_0000004.img.tar.xz'
check 'should return stable when no testing asset exists' $(cat test5.dat | get_img_url testing) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize uploaded testing asset over not-uploaded' $(cat test3b.dat | get_img_url testing) 'chimeraos-2_0000001.img.tar.xz'
check 'should handle non existing stable channel' $(cat test6.dat | get_img_url testing) 'chimeraos-1_0000001.img.tar.xz'

echo
echo '==== unstable channel'
check 'should select the system image asset' $(cat test1.dat | get_img_url unstable) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize stable asset over older testing asset' $(cat test2.dat | get_img_url unstable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over older unstable asset' $(cat test2.dat | get_img_url unstable) 'chimeraos-1_0000004.img.tar.xz'
check 'should select asset that is in `uploaded` state' $(cat test3c.dat | get_img_url unstable) 'chimeraos-1_0000001.img.tar.xz'
check 'should select the system image asset in unstable' $(cat test1.dat | get_img_url unstable) 'chimeraos-3_0000000.img.tar.xz'
check 'should prioritize stable asset over older testing asset' $(cat test2.dat | get_img_url unstable) 'chimeraos-1_0000004.img.tar.xz'
check 'should prioritize stable asset over older unstable asset' $(cat test2.dat | get_img_url unstable) 'chimeraos-1_0000004.img.tar.xz'
check 'should return stable when no unstable asset exists' $(cat test5.dat | get_img_url unstable) 'chimeraos-1_0000000.img.tar.xz'
check 'should prioritize uploaded unstable asset over not-uploaded' $(cat test3c.dat | get_img_url unstable) 'chimeraos-2_0000001.img.tar.xz'
check 'should handle non existing stable channel' $(cat test6.dat | get_img_url unstable) 'chimeraos-2_0000001.img.tar.xz'

echo
echo '==== direct'
check 'should select newest version by default' $(cat test4.dat | get_img_url stable) 'chimeraos-2_0000002.img.tar.xz'
check 'should be able to select older versions' $(cat test4.dat | get_img_url 1) 'chimeraos-1_0000001.img.tar.xz'
check 'should select latest matching asset' $(cat test4a.dat | get_img_url 1) 'chimeraos-1_0000002.img.tar.xz'
check 'should select asset that is in `uploaded` state' $(cat test4b.dat | get_img_url 1) 'chimeraos-1_0000001.img.tar.xz'
check 'should select newest version by default' $(cat test4.dat | get_img_url stable) 'chimeraos-2_0000002.img.tar.xz'
check 'should be able to select older versions' $(cat test4.dat | get_img_url 1) 'chimeraos-1_0000001.img.tar.xz'
check 'should be able to select older point versions' $(cat test4.dat | get_img_url 1-1) 'chimeraos-1-1_0000011.img.tar.xz'
check 'should select latest matching asset' $(cat test4a.dat | get_img_url 1) 'chimeraos-1_0000002.img.tar.xz'

echo
echo '== get_boot_cfg'
Expand Down
48 changes: 47 additions & 1 deletion test/test1.dat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"tag_name": "1_0000000",
"name": "ChimeraOS 1 (0000000)",
"name": "ChimeraOS 1",
"prerelease": false,
"created_at": "2022-05-05T03:31:40Z",
"assets": [
Expand All @@ -21,5 +21,51 @@
"browser_download_url": "sha256sum.txt"
}
]
},
{
"tag_name": "2_0000000",
"name": "ChimeraOS 2 (0000000)",
"prerelease": true,
"created_at": "2022-05-07T03:31:40Z",
"assets": [
{
"name": "build_info.txt",
"state": "uploaded",
"browser_download_url": "build_info.txt"
},
{
"name": "chimeraos-2_0000000.img.tar.xz",
"state": "uploaded",
"browser_download_url": "chimeraos-2_0000000.img.tar.xz"
},
{
"name": "sha256sum.txt",
"state": "uploaded",
"browser_download_url": "sha256sum.txt"
}
]
},
{
"tag_name": "3_0000000",
"name": "ChimeraOS 3 (0000000) [UNSTABLE]",
"prerelease": true,
"created_at": "2022-05-08T03:31:40Z",
"assets": [
{
"name": "build_info.txt",
"state": "uploaded",
"browser_download_url": "build_info.txt"
},
{
"name": "chimeraos-3_0000000.img.tar.xz",
"state": "uploaded",
"browser_download_url": "chimeraos-3_0000000.img.tar.xz"
},
{
"name": "sha256sum.txt",
"state": "uploaded",
"browser_download_url": "sha256sum.txt"
}
]
}
]
4 changes: 2 additions & 2 deletions test/test2.dat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"tag_name": "1_0000002",
"name": "ChimeraOS 1 (0000002)",
"prerelease": true,
"created_at": "2022-01-01T00:00:00Z",
"created_at": "2022-01-02T00:00:00Z",
"assets": [
{
"name": "chimeraos-1_0000002.img.tar.xz",
Expand All @@ -40,7 +40,7 @@
},
{
"tag_name": "1_0000004",
"name": "ChimeraOS 1 (0000004)",
"name": "ChimeraOS 1",
"prerelease": false,
"created_at": "2024-01-01T00:00:00Z",
"assets": [
Expand Down
Loading

0 comments on commit e38d815

Please sign in to comment.