-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: fix/channels
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}" | ||
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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}" | ||
|
@@ -17,7 +17,7 @@ data_dir="${data_home}/ubports-installer-cli" | |
|
||
fetch() { | ||
url=${1} | ||
cached="${cache_dir}/${url}" | ||
cached="${cache_dir}/$(basename "${url}")" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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!" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear colors after printing (just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Resolved. |
||
fi | ||
|
||
download_latest_images "${image_index_url}" |
There was a problem hiding this comment.
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 betweenwget
andcurl