From bb92bc2bef10a1d043b3903953f5fb2be8d48d22 Mon Sep 17 00:00:00 2001 From: gilbN Date: Sun, 27 Jun 2021 00:11:16 +0200 Subject: [PATCH] vuetorrent mod --- vuetorrent/Dockerfile | 7 ++ vuetorrent/root/etc/cont-init.d/98-themepark | 114 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 vuetorrent/Dockerfile create mode 100644 vuetorrent/root/etc/cont-init.d/98-themepark diff --git a/vuetorrent/Dockerfile b/vuetorrent/Dockerfile new file mode 100644 index 00000000..32b48e23 --- /dev/null +++ b/vuetorrent/Dockerfile @@ -0,0 +1,7 @@ +FROM scratch + + +LABEL maintainer="GilbN" +LABEL app="VueTorrent" +#copy local files. +COPY root/ / \ No newline at end of file diff --git a/vuetorrent/root/etc/cont-init.d/98-themepark b/vuetorrent/root/etc/cont-init.d/98-themepark new file mode 100644 index 00000000..2e561b60 --- /dev/null +++ b/vuetorrent/root/etc/cont-init.d/98-themepark @@ -0,0 +1,114 @@ +#!/usr/bin/with-contenv bash +APP_FILEPATH='/config/qBittorrent/qBittorrent.conf' +if [ "${TP_HOTIO}" = true ]; then + echo 'Changing to Hotio file path!' + APP_FILEPATH='/config/config/qBittorrent.conf' +fi +# Display variables for troubleshooting +echo -e "Variables set:\\n\ +'TP_DOMAIN'=${TP_DOMAIN}\\n\ +'TP_THEME'=${TP_THEME}\\n" + +# Set default +if [[ -z ${TP_DOMAIN} ]]; then + echo 'No domain set, defaulting to theme-park.dev' + TP_DOMAIN='theme-park.dev' +fi + +case ${TP_DOMAIN} in + *"github.io"*) + echo "Switching to github.io URL style" + TP_DOMAIN="${TP_DOMAIN}\/theme.park" + ;; +esac + +if [[ -z ${TP_THEME} ]]; then + echo 'No theme set, defaulting to organizr-dark' + TP_THEME='organizr-dark' +fi +RELEASE_FILEPATH='/vuetorrent/release.json' +NEEDS_UPDATE=false +CURRENT_RELEASE=$(curl -s https://api.github.com/repos/WDaan/VueTorrent/releases/latest | jq -r ".assets[]") + +# =============================================== +install_deps() { + if ! [[ -x "$(command -v jq)" ]]; then + echo '-------------------------' + echo '| Installing jq package |' + echo '-------------------------' + apt-get update && + apt-get install -y jq + fi +} +check_updates() { + if [[ ! -d ./vuetorrent ]]; then + NEEDS_UPDATE=true + elif [[ ! -f $RELEASE_FILEPATH ]]; then + NEEDS_UPDATE=true + else + old_date=$(date -d $(cat "${RELEASE_FILEPATH}" | jq -r ".updated_at") +%s) + new_date=$(date -d $(echo $CURRENT_RELEASE | jq -r ".updated_at") +%s) + if [ $new_date -gt $old_date ]; then + NEEDS_UPDATE=true + fi + fi +} +update_ui() { + printf '\nDownloading qBittorrent webui to "/vuetorrent"..please wait\n' + curl -L $(echo $CURRENT_RELEASE | jq -r ".browser_download_url") --output /tmp/vuetorrent.zip + printf '\nDownload finished\n\n' + if [[ -d /vuetorrent ]]; then + rm -rf /vuetorrent + fi + # mkdir -p /vuetorrent + unzip -q /tmp/vuetorrent.zip -d / + echo $CURRENT_RELEASE >"${RELEASE_FILEPATH}" +} +# =============================================== + +echo '-----------------------------------------' +echo '| qBittorrent vuetorrent theme.park Mod |' +echo '-----------------------------------------' + +install_deps +check_updates + +if [ "$NEEDS_UPDATE" = true ]; then + echo '---------------------------------------' + echo '| Downloading WebUI files from github |' + echo '---------------------------------------' + update_ui +else + echo ' WebUI files are up-to-date!' +fi + +# Adding stylesheets +if ! grep -q "${TP_DOMAIN}" /vuetorrent/public/index.html; then + echo '---------------------------------------------------------' + echo '| Adding the stylesheet to /vuetorrent/public/index.html |' + echo '---------------------------------------------------------' + sed -i "s/<\/body>/<\/body> /g" /vuetorrent/public/index.html + printf 'Stylesheet set to %s on public index.html\n' "${TP_THEME}" +fi + +if ! grep -q "WebUI\\\RootFolder" "${APP_FILEPATH}"; then + echo '--------------------------------------' + echo '| Adding WebUI\RootFolder=/vuetorrent |' + echo '--------------------------------------' + sed -i -e '$aWebUI\\RootFolder=/vuetorrent' "${APP_FILEPATH}" +fi + +if ! grep -q "WebUI\\\AlternativeUIEnabled" "${APP_FILEPATH}"; then + echo '------------------------------------------' + echo '| Adding WebUI\AlternativeUIEnabled=true |' + echo '------------------------------------------' + sed -i -e '$aWebUI\\AlternativeUIEnabled=true' "${APP_FILEPATH}" +fi + +if ! grep -q "WebUI\\\RootFolder=/vuetorrent" "${APP_FILEPATH}" || ! grep -q "WebUI\\\AlternativeUIEnabled=true" "${APP_FILEPATH}"; then + echo '-------------------------------------------------------' + echo '| Updating RootFolder and AlternativeUIEnabled values |' + echo '-------------------------------------------------------' + sed -i "s/WebUI\\\AlternativeUIEnabled=.*$/WebUI\\\AlternativeUIEnabled=true/g" "${APP_FILEPATH}" + sed -i "s/WebUI\\\RootFolder=.*$/WebUI\\\RootFolder=\/vuetorrent/g" "${APP_FILEPATH}" +fi \ No newline at end of file