summaryrefslogtreecommitdiff
path: root/fetch-images.sh
blob: 4f4884bdb3d31a43ac3d2950224ad0d3704719ae (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
29
30
31
32
33
#!/bin/sh
# startdate 2020-05-29 20:04
# After running this, be sure to do the sed.
#    sed -i -f fix-images-in-html.sed /mnt/public/www/issues/*.html
# Improve:
#    It is probably an artifact of the weird way the asset svgs are embedded, but I cannot get them to display at all even though they are downloaded successfully. I have seen this before, the little embedded images you cannot easily download and simply display.

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

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

INSERVER=https://git.devuan.org

cd "${INDIR}"

# could use this line to get all the assets, but they do not display regardless due to html weirdness
#orig_src="$( grep -oE '(\<src|xlink:href)="?\/[^"]*"' ${INGLOB} | grep -vE '\.js' | awk -F'"' '!x[$0]++{print $2}' )"
orig_src="$( grep -oE '\<src="?\/[^"]*"' ${INGLOB} | grep -vE '\.js' | awk -F'"' '!x[$2]++{print $2}' )"

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

echo "${orig_src}" | while read line ; do
   #echo "${line}" | awk -F'"' '{print $2}'
   getpath="${INSERVER}${line}"
   outdir="$( echo "${line}" | awk -F'/' '{print $2}' )"
   test ! -d "${outdir}" && mkdir -p "${outdir}"
   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