1
0
mirror of https://github.com/gilbN/theme.park.git synced 2024-11-04 10:12:31 +01:00
theme.park/docker-mods/vuetorrent/root/etc/cont-init.d/98-themepark
2021-11-01 23:32:05 +01:00

139 lines
5.0 KiB
Plaintext

#!/usr/bin/with-contenv bash
APP_FILEPATH='/config/qBittorrent/qBittorrent.conf'
INDEX_FILEPATH='/vuetorrent/public/index.html'
if [ "${TP_HOTIO}" = true ]; then
echo 'Changing to Hotio file paths!'
APP_FILEPATH='/config/config/qBittorrent.conf'
INDEX_FILEPATH='/app/vuetorrent/public/index.html'
fi
# Backup config
if [[ ! -f "${APP_FILEPATH}.bak" ]]; then
echo "Creating qBittorrent.conf backup in /config."
cp -p ${APP_FILEPATH} "${APP_FILEPATH}.bak"
fi
# Restore qBittorrent.conf
if [ "${TP_DISABLE_THEME}" = true ]; then
echo "Restoring backup of qBittorrent.conf"
sed -i "s/WebUI\\\AlternativeUIEnabled=.*$/WebUI\\\AlternativeUIEnabled=false/g" "${APP_FILEPATH}";
exit 0
fi
# Display variables for troubleshooting
echo -e "Variables set:\\n\
'TP_DOMAIN'=${TP_DOMAIN}\\n\
'TP_COMMUNITY_THEME'=${TP_COMMUNITY_THEME}\\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
THEME_TYPE='theme-options'
if [ "${TP_COMMUNITY_THEME}" = true ]; then
THEME_TYPE='community-theme-options'
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'
TP_THEME='organizr'
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 '-----------------------------------------'
if [[ -z ${TP_HOTIO} ]]; then
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
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
fi
# Adding stylesheets
if ! grep -q "${TP_DOMAIN}/css/base" "${INDEX_FILEPATH}"; then
echo '---------------------------------------------------------'
echo '| Adding the stylesheet to /vuetorrent/public/index.html |'
echo '---------------------------------------------------------'
sed -i "s/<\/body>/<link rel='stylesheet' href='https:\/\/${TP_DOMAIN}\/css\/base\/vuetorrent\/vuetorrent-base.css'><\/body> /g" "${INDEX_FILEPATH}"
sed -i "s/<\/body>/<link rel='stylesheet' href='https:\/\/${TP_DOMAIN}\/css\/${THEME_TYPE}\/${TP_THEME}.css'><\/body> /g" "${INDEX_FILEPATH}"
printf 'Stylesheet set to %s on public index.html\n' "${TP_THEME}"
fi