Last active
October 19, 2021 16:16
-
-
Save UniversalSuperBox/0b170cc90c84bbb70f66474f849319ed to your computer and use it in GitHub Desktop.
Grabs an image from a system-image-server channel for a given device with a given tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Fetches and prepares a certain tag from system server | |
# First argument: Channel, like '16.04/arm64/android9/stable' | |
# Second argument: Device, like 'yggdrasil' | |
# Third argument: Destination directory | |
# Fourth argument: Image tag, like 'OTA-16' | |
# The files created in the destination directory can be pushed to /cache/recovery/ on an Ubuntu Touch device. | |
# Once the files are in place, booting UBports recovery will cause installation to begin. | |
URL='https://system-image.ubports.com' | |
CHANNEL="$1" | |
DEVICE="$2" | |
OUTPUT="$3" | |
TAG="$4" | |
mkdir -p "$OUTPUT" || true | |
download_file_and_asc() { | |
wget "$1" -P "$2" | |
wget "$1.asc" -P "$2" | |
} | |
# Gets the latest image from the system-image server | |
latest_image=$(wget -qO- "${URL}/${CHANNEL}/${DEVICE}/index.json" | jq ".images | map(select(.type == \"full\")) | sort_by(.version) | map(select(.version_detail | contains(\"${TAG}\"))) | .[-1]") | |
# Gets a list of files to download | |
files=$(echo "${latest_image}" | jq --raw-output '.files[].path') | |
# Downloads master and signing keyrings | |
download_file_and_asc "${URL}/gpg/image-signing.tar.xz" "$OUTPUT" | |
download_file_and_asc "${URL}/gpg/image-master.tar.xz" "$OUTPUT" | |
# Start to generate ubuntu_command file | |
echo '# Generated by fetch-and-prepare-image-version' > "$OUTPUT/ubuntu_command" | |
cat << EOF >> "$OUTPUT/ubuntu_command" | |
format system | |
load_keyring image-master.tar.xz image-master.tar.xz.asc | |
load_keyring image-signing.tar.xz image-signing.tar.xz.asc | |
mount system | |
EOF | |
# Download and fill ubuntu_command | |
for file_path in ${files}; do | |
file=$(basename ${file_path}) | |
download_file_and_asc "${URL}/${file_path}" "$OUTPUT" | |
echo "update $file $file.asc" >> "$OUTPUT/ubuntu_command" | |
done | |
# End ubuntu_command | |
echo 'unmount system' >> "$OUTPUT/ubuntu_command" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment