Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Seperate functions for fetching and downloading images #1

Draft
wants to merge 3 commits into
base: fix/channels
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions scripts/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,44 @@

install_dir="${data_dir}/installation_files"

fetch_and_download_latest_images() {
fetch_latest_images() {
index_url=${1}
latest_images="$(fetch "${URL}""${index_url}" | jq '.images | map(select(.type == "full")) | sort_by(.version) | .[-1]'))"
downloadable_files="$(echo "${latest_images}" | jq -r '.files[].path')"

echo "${downloadable_files}" | while read -r files; do
ret=$(echo "${downloadable_files}")
if [ "${ret}" != "" ]; then
echo ${ret}
fi
}

download_latest_images() {
index_url=${1}
images=$(fetch_latest_images "${index_url}")

for files in "${images}"; do
file=$(basename "${files}")
fetch_persistent_files "${URL}${files}" "${install_dir}/${file}"
echo "update $file $file.asc" >> "${install_dir}/ubuntu_command"
wget "${URL}${files}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have used the same logic that's in fetch to choose between wget and curl

done

echo "unmount system" >> "${install_dir}/ubuntu_command"
}

create_inital_ubuntu_command() {
create_ubuntu_command() {
echo "format system
$( [ -z ${wipe:+true} ] || echo "format data")
load_keyring image-master.tar.xz image-master.tar.xz.asc
load_keyring image-signing.tar.xz image-signing.tar.xz.asc
mount system" > "${install_dir}/ubuntu_command"
}

fill_ubuntu_command() {
index_url=${1}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

="${1}"

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

="${1}"

Also resolved.

ubuntu_command_file="${install_dir}/ubuntu_command"
images=$(fetch_latest_images "${index_url}")

echo "${images}" | while read -r files; do
file=$(basename "${files}")
echo "update $file $file.asc" >> "${ubuntu_command_file}"
done

echo "unmount system" >> "${ubuntu_command_file}"
}
4 changes: 2 additions & 2 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ -n "${UTILS_SH}" ] && return; UTILS_SH=0; # like #ifndef guard in C

URL=https://system-image.ubports.com
URL="https://system-image.ubports.com"

cache_home="${XDG_CACHE_HOME}"
data_home="${XDG_DATA_HOME}"
Expand All @@ -17,7 +17,7 @@ data_dir="${data_home}/ubports-installer-cli"

fetch() {
url=${1}
cached="${cache_dir}/${url}"
cached="${cache_dir}/$(basename "${url}")"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break horribly, there is no guarantee the filenames that will be fetched are unique. The cache directory is not supposed to be pretty, having full URLs there doesn't hurt anything.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break horribly, there is no guarantee the filenames that will be fetched are unique. The cache directory is not supposed to be pretty, having full URLs there doesn't hurt anything.

The old one actually breaks worse, for example when it downloads the channels.json from https://system-image.ubports.com, the command manages to separate the link, 'https:' becomes a directory in which '/system-image.ubports.com' exists and then finally comes the channels.json.
And it won't refetch the file anyway, so I don't see how it breaks...?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not breaking, that's the way it's supposed to work and there is nothing wrong with that - like I said, the directory structure is not supposed to be pretty. And what I mean is that you can for example download the channels list for one device, but since you used basename if you try to do it for another it will use the cached one and you will download files for a wrong device.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see, yeah I see how it breaks now


if [ -z "${NO_CACHE}" ]; then
if [ -e "${cached}" ]; then
Expand Down
9 changes: 8 additions & 1 deletion ubcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,11 @@ if [ -z "${image_index_url}" ]; then
exit 3
fi

fetch_and_download_latest_images "${image_index_url}"
latest_images=$(fetch_latest_images "${image_index_url}")
if [ -z "${latest_images}" ]; then
printf "$(ct 'red' true)ERROR:$(ct 'red') images for device"
printf "$(ct 'orange') ${device}$(ct 'red') on channel"
printf "$(ct 'orange') ${channel}$(ct 'red') not found!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear colors after printing (just $(ct))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear colors after printing (just $(ct))

Resolved.

fi

download_latest_images "${image_index_url}"