diff --git a/__frzr-deploy b/__frzr-deploy index e7592f9..edf1c33 100644 --- a/__frzr-deploy +++ b/__frzr-deploy @@ -4,26 +4,102 @@ 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() { @@ -31,7 +107,7 @@ get_boot_cfg() { local amd_ucode=${2} local intel_ucode=${3} local additional_arguments=${4} - + echo "title ${version} linux /${version}/vmlinuz-linux ${amd_ucode} @@ -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 } @@ -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} } @@ -108,7 +184,7 @@ main() { ;; esac done - + if [ ! -d /sys/firmware/efi/efivars ]; then echo "Legacy BIOS installs are not supported. Aborting." exit 1 @@ -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 @@ -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}" @@ -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 @@ -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} @@ -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 diff --git a/test/run.sh b/test/run.sh index b03733e..7d30f75 100755 --- a/test/run.sh +++ b/test/run.sh @@ -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' diff --git a/test/test1.dat b/test/test1.dat index 176544e..9d999a0 100644 --- a/test/test1.dat +++ b/test/test1.dat @@ -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": [ @@ -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" + } + ] } ] diff --git a/test/test2.dat b/test/test2.dat index 0376917..ccb6ec1 100644 --- a/test/test2.dat +++ b/test/test2.dat @@ -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", @@ -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": [ diff --git a/test/test3b.dat b/test/test3b.dat index 1619f76..52402d0 100644 --- a/test/test3b.dat +++ b/test/test3b.dat @@ -1,9 +1,9 @@ [ { - "tag_name": "1_0000001", + "tag_name": "1_0000000", "name": "ChimeraOS 1 (0000001)", - "prerelease": true, - "created_at": "2021-01-01T00:00:00Z", + "prerelease": false, + "created_at": "2020-01-01T00:00:00Z", "assets": [ { "name": "chimeraos-1_0000001.img.tar.xz", @@ -13,15 +13,28 @@ ] }, { - "tag_name": "1_0000002", - "name": "ChimeraOS 1 (0000002)", + "tag_name": "2_0000001", + "name": "ChimeraOS 2 (0000001)", + "prerelease": true, + "created_at": "2021-01-01T00:00:00Z", + "assets": [ + { + "name": "chimeraos-2_0000001.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-2_0000001.img.tar.xz" + } + ] + }, + { + "tag_name": "2_0000002", + "name": "ChimeraOS 2 (0000002)", "prerelease": true, "created_at": "2022-01-01T00:00:00Z", "assets": [ { - "name": "chimeraos-1_0000002.img.tar.xz", + "name": "chimeraos-2_0000002.img.tar.xz", "state": "not-uploaded", - "browser_download_url": "chimeraos-1_0000002.img.tar.xz" + "browser_download_url": "chimeraos-2_0000002.img.tar.xz" } ] } diff --git a/test/test3c.dat b/test/test3c.dat index 7e2994b..f2edea3 100644 --- a/test/test3c.dat +++ b/test/test3c.dat @@ -1,9 +1,9 @@ [ { - "tag_name": "1_0000001", - "name": "ChimeraOS 1 (0000001) [UNSTABLE]", - "prerelease": true, - "created_at": "2021-01-01T00:00:00Z", + "tag_name": "1_0000000", + "name": "ChimeraOS 1 (0000001)", + "prerelease": false, + "created_at": "2020-01-01T00:00:00Z", "assets": [ { "name": "chimeraos-1_0000001.img.tar.xz", @@ -13,15 +13,28 @@ ] }, { - "tag_name": "1_0000002", - "name": "ChimeraOS 1 (0000002) [UNSTABLE]", + "tag_name": "2_0000001", + "name": "ChimeraOS 2 (0000001) [UNSTABLE]", + "prerelease": true, + "created_at": "2021-01-01T00:00:00Z", + "assets": [ + { + "name": "chimeraos-2_0000001.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-2_0000001.img.tar.xz" + } + ] + }, + { + "tag_name": "2_0000002", + "name": "ChimeraOS 2 (0000002) [UNSTABLE]", "prerelease": true, "created_at": "2022-01-01T00:00:00Z", "assets": [ { - "name": "chimeraos-1_0000002.img.tar.xz", + "name": "chimeraos-2_0000002.img.tar.xz", "state": "not-uploaded", - "browser_download_url": "chimeraos-1_0000002.img.tar.xz" + "browser_download_url": "chimeraos-2_0000002.img.tar.xz" } ] } diff --git a/test/test4.dat b/test/test4.dat index e8e00ca..51deabe 100644 --- a/test/test4.dat +++ b/test/test4.dat @@ -1,7 +1,7 @@ [ { "tag_name": "1_0000001", - "name": "ChimeraOS 1 (0000001)", + "name": "ChimeraOS 1", "prerelease": false, "created_at": "2021-01-01T00:00:00Z", "assets": [ @@ -12,11 +12,24 @@ } ] }, + { + "tag_name": "1-1_0000011", + "name": "ChimeraOS 1-1", + "prerelease": false, + "created_at": "2021-01-01T10:00:00Z", + "assets": [ + { + "name": "chimeraos-1-1_0000011.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-1-1_0000011.img.tar.xz" + } + ] + }, { "tag_name": "2_0000002", - "name": "ChimeraOS 2 (0000002)", + "name": "ChimeraOS 2", "prerelease": false, - "created_at": "2022-01-01T00:00:00Z", + "created_at": "2022-01-02T00:00:00Z", "assets": [ { "name": "chimeraos-2_0000002.img.tar.xz", diff --git a/test/test4a.dat b/test/test4a.dat index e5fefdc..013687b 100644 --- a/test/test4a.dat +++ b/test/test4a.dat @@ -1,7 +1,7 @@ [ { "tag_name": "1_0000002", - "name": "ChimeraOS 1 (0000002)", + "name": "ChimeraOS 1", "prerelease": false, "created_at": "2022-01-01T00:00:00Z", "assets": [ @@ -14,7 +14,7 @@ }, { "tag_name": "1_0000001", - "name": "ChimeraOS 1 (0000001)", + "name": "ChimeraOS 1", "prerelease": false, "created_at": "2021-01-01T00:00:00Z", "assets": [ @@ -27,7 +27,7 @@ }, { "tag_name": "2_0000002", - "name": "ChimeraOS 2 (0000002)", + "name": "ChimeraOS 2", "prerelease": false, "created_at": "2022-01-01T00:00:00Z", "assets": [ diff --git a/test/test5.dat b/test/test5.dat new file mode 100644 index 0000000..3776d38 --- /dev/null +++ b/test/test5.dat @@ -0,0 +1,25 @@ +[ + { + "tag_name": "1_0000000", + "name": "ChimeraOS 1", + "prerelease": false, + "created_at": "2022-05-05T03:31:40Z", + "assets": [ + { + "name": "build_info.txt", + "state": "uploaded", + "browser_download_url": "build_info.txt" + }, + { + "name": "chimeraos-1_0000000.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-1_0000000.img.tar.xz" + }, + { + "name": "sha256sum.txt", + "state": "uploaded", + "browser_download_url": "sha256sum.txt" + } + ] + } +] diff --git a/test/test6.dat b/test/test6.dat new file mode 100644 index 0000000..06fa0a3 --- /dev/null +++ b/test/test6.dat @@ -0,0 +1,28 @@ +[ + { + "tag_name": "1_0000001", + "name": "ChimeraOS 1 (0000001)", + "prerelease": true, + "created_at": "2021-01-01T00:00:00Z", + "assets": [ + { + "name": "chimeraos-1_0000001.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-1_0000001.img.tar.xz" + } + ] + }, + { + "tag_name": "2_0000002", + "name": "ChimeraOS 2 (0000002) [UNSTABLE]", + "prerelease": true, + "created_at": "2022-01-01T00:00:00Z", + "assets": [ + { + "name": "chimeraos-2_0000001.img.tar.xz", + "state": "uploaded", + "browser_download_url": "chimeraos-2_0000001.img.tar.xz" + } + ] + } +]