summaryrefslogtreecommitdiff
path: root/fetch-css.sh
blob: 06718c284d9b05020d0150b3ab758e565a901dc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
# Startdate: 2020-05-29 20:18

INDIR=/mnt/public/www/issues
INGLOB=*.html

SEDSCRIPT=/mnt/public/work/devuan/fix-css-in-html.sed

# OUTDIR will be made in INDIR, because of the `cd` below.
OUTDIR=css
test ! -d "${OUTDIR}" && mkdir -p "${OUTDIR}"

INSERVER=https://git.devuan.org

cd "${INDIR}"

orig_css="$( sed -n -r -e 's/^.*<link.*(href="[^"]+\.css").*/\1/p' ${INGLOB} | awk -F'"' '!x[$2]++{print $2}' )"

cat /dev/null > "${SEDSCRIPT}"

echo "${orig_css}" | while read line ; do
   getpath="${INSERVER}${line}"
   targetfile="${OUTDIR}/$( basename "${line}" )"
   test -n "${DEBUG}" && echo "process ${getpath} and save to ${targetfile}" 1>&2
   test -z "${DRYRUN}" && wget --quiet --content-disposition -O "${targetfile}" "${getpath}"
   # dynamically build a sed script
   echo "s:${line}:${targetfile##/}:g;" | tee -a "${SEDSCRIPT}"
done
bgstack15