This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new e456e2d Add a script to allow downloading releases with curl, printf,
and sh
e456e2d is described below
commit e456e2d081d6267c7d900fa9f7599c014b3b4694
Author: Sean B. Palmer <[email protected]>
AuthorDate: Sat May 3 11:24:18 2025 +0100
Add a script to allow downloading releases with curl, printf, and sh
---
atr/routes/download.py | 16 ++++++++
atr/static/sh/download-urls.sh | 83 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
diff --git a/atr/routes/download.py b/atr/routes/download.py
index 4a49f1f..03160ec 100644
--- a/atr/routes/download.py
+++ b/atr/routes/download.py
@@ -33,6 +33,7 @@ import atr.routes as routes
import atr.routes.mapping as mapping
import atr.routes.root as root
import atr.util as util
+from atr import config
@routes.committer("/download/all/<project_name>/<version_name>")
@@ -73,6 +74,21 @@ async def path_empty(project_name: str, version_name: str)
-> response.Response
return await _download_or_list(project_name, version_name, ".")
[email protected]("/download/sh/<project_name>/<version_name>")
+async def sh_selected(project_name: str, version_name: str) ->
response.Response | quart.Response:
+ """Shell script to download a release."""
+ conf = config.get()
+ app_host = conf.APP_HOST
+ script_path = (pathlib.Path(__file__).parent /
"../static/sh/download-urls.sh").resolve()
+ async with aiofiles.open(script_path) as f:
+ content = await f.read()
+ download_urls_selected = util.as_url(urls_selected,
project_name=project_name, version_name=version_name)
+ download_path = util.as_url(path, project_name=project_name,
version_name=version_name, file_path="")
+ content = content.replace("[URL_OF_URLS]",
f"https://{app_host}{download_urls_selected}")
+ content = content.replace("[URLS_PREFIX]",
f"https://{app_host}{download_path}")
+ return quart.Response(content, mimetype="text/x-shellscript")
+
+
@routes.public("/download/urls/<project_name>/<version_name>")
async def urls_selected(project_name: str, version_name: str) ->
response.Response | quart.Response:
try:
diff --git a/atr/static/sh/download-urls.sh b/atr/static/sh/download-urls.sh
new file mode 100644
index 0000000..4aba10d
--- /dev/null
+++ b/atr/static/sh/download-urls.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+set -eu
+
+_url_of_urls="[URL_OF_URLS]"
+_urls_prefix="[URLS_PREFIX]"
+
+_hex_to_dec() {
+ case $1 in
+ 0) printf 0;;
+ 1) printf 1;;
+ 2) printf 2;;
+ 3) printf 3;;
+ 4) printf 4;;
+ 5) printf 5;;
+ 6) printf 6;;
+ 7) printf 7;;
+ 8) printf 8;;
+ 9) printf 9;;
+ a|A) printf 10;;
+ b|B) printf 11;;
+ c|C) printf 12;;
+ d|D) printf 13;;
+ e|E) printf 14;;
+ f|F) printf 15;;
+ esac
+}
+
+_hex2_to_oct() {
+ _a="${1%"${1#?}"}"
+ _b="${1#?}"
+ _a_dec=$(_hex_to_dec "$_a")
+ _b_dec=$(_hex_to_dec "$_b")
+ _total_dec=$((_a_dec * 16 + _b_dec))
+ printf "%o" "$_total_dec"
+}
+
+_url_decode() {
+ _u=$1
+ while [ "$_u" ]
+ do
+ case $_u in
+ %??*)
+ _hh=${_u#%}
+ _hh=${_hh%"${_hh#??}"}
+ case $_hh in
+ [0-9A-Fa-f][0-9A-Fa-f])
+ # shellcheck disable=SC2059
+ printf "\\$(_hex2_to_oct "$_hh")"
+ _u=${_u#%??}
+ continue
+ esac
+ ;;
+ esac
+ printf %c "${_u%"${_u#?}"}"
+ _u=${_u#?}
+ done
+}
+
+_curl() {
+ if [ -n "${CURL_EXTRA-}" ]
+ then
+ set -f
+ # shellcheck disable=SC2086
+ command curl $CURL_EXTRA "$@"
+ _code=$?
+ set +f
+ return "$_code"
+ else
+ command curl "$@"
+ fi
+}
+
+_curl -fsS "$_url_of_urls" | while IFS= read -r _url
+do
+ _rel_url_path=${_url#"$_urls_prefix"}
+ [ "$_rel_url_path" = "$_url" ] && continue
+
+ _rel_path=$(_url_decode "$_rel_url_path")
+ [ -z "$_rel_path" ] && continue
+
+ printf "Downloading %s to %s\n" "$_url" "$_rel_path"
+ _curl --create-dirs -fsS "$_url" -o "$_rel_path"
+done
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]