Skip to content
Snippets Groups Projects
Commit 064995ac authored by Kristian Klausen's avatar Kristian Klausen :tada:
Browse files

Add wget helper function so we can remove duplicate code

parent 782d4040
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,14 @@ ALBS_RANGE_DOWNLOAD_CHUNK="${ALBS_RANGE_DOWNLOAD_CHUNK:-$(date +%-d)}"
ALBS_RANGE_DOWNLOAD_CHUNKS="${ALBS_RANGE_DOWNLOAD_CHUNKS:-10}"
ALBS_RANGE_DOWNLOAD_CHUNK="$((ALBS_RANGE_DOWNLOAD_CHUNK % ALBS_RANGE_DOWNLOAD_CHUNKS + 1))"
function wget() {
local user_agent
user_agent="albs ($(git rev-parse --short HEAD); https://gitlab.archlinux.org/archlinux/archlinux-bugs-snapshotter)"
command wget --max-redirect 0 \
--user-agent="${user_agent}" \
--no-verbose "${@}"
}
function get_newest_task_id() {
wget --output-document=- "https://bugs.archlinux.org/index.php?project=0&status[]=&changedfrom=2021-04-01" | grep --perl-regexp --only-matching --max-count 1 "(?<=task)[0-9]+"
}
......@@ -26,8 +34,6 @@ function _download() {
cd "${dir}"
fi
local user_agent
user_agent="albs ($(git rev-parse --short HEAD); https://gitlab.archlinux.org/archlinux/archlinux-bugs-snapshotter)"
wget --recursive \
--include-directories="user,themes,ajax,javascript" \
--page-requisites \
......@@ -36,9 +42,6 @@ function _download() {
--span-hosts \
--no-host-directories \
--domains=archlinux.org,ajax.googleapis.com \
--max-redirect 0 \
--user-agent="${user_agent}" \
--no-verbose \
--wait="${ALBS_DOWNLOAD_WAIT}" \
--input-file=<(printf "%s\n" "${@}") || [[ ${?} = 8 ]] # 8 Server issued an error response.
}
......@@ -50,7 +53,7 @@ function download() {
_download "${array[@]}"
else
# broken?
export -f _download
export -f wget _download
time echo "${1}" | xargs --max-procs=5 --max-args=200 bash -c "_download \"\${@}\""
mkdir final
for d in */; do
......@@ -73,12 +76,7 @@ function download_attachment() {
mkdir -p "attachments/${1}/"{tmp,${2}}
cd "attachments/${1}/tmp"
local user_agent
user_agent="albs ($(git rev-parse --short HEAD); https://gitlab.archlinux.org/archlinux/archlinux-bugs-snapshotter)"
wget --content-disposition \
--max-redirect 0 \
--user-agent="${user_agent}" \
--no-verbose \
"https://bugs.archlinux.org/?getfile=${2}" || { [[ ${?} = 3 ]] && echo "Error downloading attachment: ${2}" && cd .. && rmdir tmp "${2}" && cd ../../ && return; }
local files=(*)
filename="${files[0]}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment