| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# List of scripts to fetch and store locally |
| 4 |
whattofetch=( |
| 5 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/excanvas.js" |
| 6 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/excanvas.min.js" |
| 7 |
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js" |
| 8 |
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" |
| 9 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js" |
| 10 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js" |
| 11 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.pie.js" |
| 12 |
"https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.pie.min.js" |
| 13 |
"https://cdnjs.cloudflare.com/ajax/libs/flot.tooltip/0.9.0/jquery.flot.tooltip.js" |
| 14 |
"https://cdnjs.cloudflare.com/ajax/libs/flot.tooltip/0.9.0/jquery.flot.tooltip.min.js" |
| 15 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" |
| 16 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js" |
| 17 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/images/marker-icon.png" |
| 18 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/images/marker-shadow.png" |
| 19 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.4.1/MarkerCluster.css" |
| 20 |
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.4.1/leaflet.markercluster.js" |
| 21 |
) |
| 22 |
|
| 23 |
showhelp() |
| 24 |
{ |
| 25 |
echo "Syntax: $0 directory" |
| 26 |
echo "where directory is the directory in which you want to store the downloaded files." |
| 27 |
echo "" |
| 28 |
echo "This will download the Javascript- and Font-files used by the default" |
| 29 |
echo "templates in mirrorbits. You can then self-host that directory tree on" |
| 30 |
echo "your webserver instead of using external CDNs." |
| 31 |
echo "You then need to set the LocalJSPath option in your mirrorbits config to" |
| 32 |
echo "point at the web-accessible path to that directory." |
| 33 |
} |
| 34 |
|
| 35 |
getlocalfilename () |
| 36 |
{ |
| 37 |
local sfn="$1" |
| 38 |
lfn=${sfn#https://cdnjs.cloudflare.com/ajax/libs} |
| 39 |
} |
| 40 |
|
| 41 |
downloadfile () |
| 42 |
{ |
| 43 |
curl=`which curl` |
| 44 |
if [ ${#curl} -ge 4 ] ; then |
| 45 |
$curl -L --output "$2" "$1" |
| 46 |
return |
| 47 |
fi |
| 48 |
wget=`which wget` |
| 49 |
if [ ${#wget} -ge 4 ] ; then |
| 50 |
$wget --output-document="$2" "$1" |
| 51 |
return |
| 52 |
fi |
| 53 |
echo "ERROR: Neither curl nor wget were found in path. Please install either curl or wget." |
| 54 |
exit 1 |
| 55 |
} |
| 56 |
|
| 57 |
if [ "$#" -ne 1 ] ; then |
| 58 |
showhelp |
| 59 |
exit 1 |
| 60 |
fi |
| 61 |
if [ "$1" == "--help" -o "$1" == "-h" ] ; then |
| 62 |
showhelp |
| 63 |
exit 0 |
| 64 |
fi |
| 65 |
localdir="$1" |
| 66 |
if [ ! -d "$localdir" ] ; then |
| 67 |
echo "Target directory ${localdir} does not exist or is not a directory." |
| 68 |
showhelp |
| 69 |
exit 1 |
| 70 |
fi |
| 71 |
|
| 72 |
unzip=`which unzip` |
| 73 |
if [ ${#unzip} -lt 5 ] ; then |
| 74 |
echo "ERROR: unzip was not found in path. Please install unzip." |
| 75 |
exit 1 |
| 76 |
fi |
| 77 |
for sf in ${whattofetch[@]}; do |
| 78 |
lfn="/void/void/void/void/" |
| 79 |
getlocalfilename "$sf" |
| 80 |
# lfn is now filled. |
| 81 |
tf="${localdir}${lfn}" |
| 82 |
if [ -e "$tf" ] ; then |
| 83 |
echo "No need to fetch $sf to $tf, it already exists." |
| 84 |
else |
| 85 |
tdn=`dirname "${tf}"` |
| 86 |
if [ ! -e "$tdn" ] ; then |
| 87 |
mkdir -p "$tdn" |
| 88 |
fi |
| 89 |
downloadfile "$sf" "$tf" |
| 90 |
fi |
| 91 |
done |
| 92 |
|
| 93 |
# The font stuff is a bit more messy. |
| 94 |
|
| 95 |
# For the Lato font, we rely on a service that's packing the mess into |
| 96 |
# a ZIP file for us. |
| 97 |
if [ ! -e "${localdir}/fonts" ] ; then |
| 98 |
mkdir -p "${localdir}/fonts" |
| 99 |
fi |
| 100 |
downloadfile "https://google-webfonts-helper.herokuapp.com/api/fonts/lato?download=zip&subsets=latin&variants=900,regular" "${localdir}/fonts/lato-font-900and400.zip" |
| 101 |
unzip "${localdir}/fonts/lato-font-900and400.zip" -d "${localdir}/fonts/" |
| 102 |
rm -f "${localdir}/fonts/lato-font-900and400.zip" |
| 103 |
|
| 104 |
# For fontawesome, we download and unpack the whole ZIP as well. |
| 105 |
# Downloading individual files will not work here, as depending on the |
| 106 |
# browser random other files will be included. |
| 107 |
if [ ! -e "${localdir}/font-awesome" ] ; then |
| 108 |
mkdir -p "${localdir}/font-awesome" |
| 109 |
fi |
| 110 |
if [ -e "${localdir}/font-awesome/4.7.0" ] ; then |
| 111 |
# Only download and extract if that directory isn't there yet, as we |
| 112 |
# have to use a 'mv' command here that would fail if the target already |
| 113 |
# existed. |
| 114 |
echo "Note: Skipping font-awesome download and extraction, it seems to be in place already." |
| 115 |
echo "To force redownload and extraction, remove '${localdir}/font-awesome/4.7.0'" |
| 116 |
else |
| 117 |
downloadfile "https://fontawesome.com/v4.7.0/assets/font-awesome-4.7.0.zip" "${localdir}/font-awesome-4.7.0.zip" |
| 118 |
unzip "${localdir}/font-awesome-4.7.0.zip" -d "${localdir}/font-awesome" |
| 119 |
rm -f "${localdir}/font-awesome-4.7.0.zip" |
| 120 |
mv "${localdir}/font-awesome/font-awesome-4.7.0" "${localdir}/font-awesome/4.7.0" |
| 121 |
fi |
| 122 |
|