summaryrefslogtreecommitdiffstats
path: root/tools/update-verify/release/common/cached_download.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /tools/update-verify/release/common/cached_download.sh
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/update-verify/release/common/cached_download.sh')
-rw-r--r--tools/update-verify/release/common/cached_download.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/update-verify/release/common/cached_download.sh b/tools/update-verify/release/common/cached_download.sh
new file mode 100644
index 0000000000..0f340af828
--- /dev/null
+++ b/tools/update-verify/release/common/cached_download.sh
@@ -0,0 +1,42 @@
+# this library works like a wrapper around wget, to allow downloads to be cached
+# so that if later the same url is retrieved, the entry from the cache will be
+# returned.
+
+pushd `dirname $0` &>/dev/null
+cache_dir="$(pwd)/cache"
+popd &>/dev/null
+
+# to clear the entire cache, recommended at beginning and end of scripts that call it
+clear_cache () {
+ rm -rf "${cache_dir}"
+}
+
+# creates an empty cache, should be called once before downloading anything
+function create_cache () {
+ mkdir "${cache_dir}"
+ touch "${cache_dir}/urls.list"
+}
+
+# download method - you pass a filename to save the file under, and the url to call
+cached_download () {
+ local output_file="${1}"
+ local url="${2}"
+
+ if fgrep -x "${url}" "${cache_dir}/urls.list" >/dev/null; then
+ echo "Retrieving '${url}' from cache..."
+ local line_number="$(fgrep -nx "${url}" "${cache_dir}/urls.list" | sed 's/:.*//')"
+ cp "${cache_dir}/obj_$(printf "%05d\n" "${line_number}").cache" "${output_file}"
+ else
+ echo "Downloading '${url}' and placing in cache..."
+ rm -f "${output_file}"
+ $retry wget -O "${output_file}" --progress=dot:mega --server-response "${url}" 2>&1
+ local exit_code=$?
+ if [ "${exit_code}" == 0 ]; then
+ echo "${url}" >> "${cache_dir}/urls.list"
+ local line_number="$(fgrep -nx "${url}" "${cache_dir}/urls.list" | sed 's/:.*//')"
+ cp "${output_file}" "${cache_dir}/obj_$(printf "%05d\n" "${line_number}").cache"
+ else
+ return "${exit_code}"
+ fi
+ fi
+}