diff --git a/BashScripts/install-wkhtmltopdf.sh b/BashScripts/install-wkhtmltopdf.sh new file mode 100644 index 0000000..f05c9a8 --- /dev/null +++ b/BashScripts/install-wkhtmltopdf.sh @@ -0,0 +1,38 @@ +# Install using: sudo su -c "bash <(wget -qO- /url/to/install-wkhtmltopdf.sh)" +# https://wkhtmltopdf.org/ + +function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } + +# Make sure script is ran as root +if [[ $EUID -ne 0 ]]; then + exec sudo /bin/bash "$0" "$@" +fi +REALUSER=$(logname) +OS_VERSION=$(grep -oP 'VERSION_ID="\K[\d.]+' /etc/os-release) + +# apt update -qq 2>>install.log + +if [ $(version $OS_VERSION) -ge $(version "22.0.0") ]; then + echo "OS version 22 detected" + DEBURL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb" +elif [ $(version $OS_VERSION) -ge $(version "20.0.0") ]; then + echo "OS version 20 detected" + DEBURL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb" +elif [ $(version $OS_VERSION) -ge $(version "18.0.0") ]; then + echo "OS version 18 detected" + DEBURL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb" +elif [ $(version $OS_VERSION) -ge $(version "16.0.0") ]; then + echo "OS version 16 detected" + DEBURL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.deb" +else + echo "Invalid OS version detected" + exit 1 +fi + +TEMP_DEB="$(mktemp)" && +wget -O "$TEMP_DEB" "$DEBURL" && +dpkg -i "$TEMP_DEB" +apt --fix-broken install +rm -f "$TEMP_DEB" + +echo 'Installation complete'