theme.park/docker-mods/radarr/root/etc/cont-init.d/98-themepark
deathbybandaid c75dc1edb4 2024-11-09
2024-11-09 11:58:36 -05:00

92 lines
2.9 KiB
Plaintext

#!/command/with-contenv bash
echo '---------------------------'
echo '| Radarr theme.park Mod |'
echo '---------------------------'
# Display variables for troubleshooting
echo -e "Variables set:\\n\
'TP_DOMAIN'=${TP_DOMAIN}\\n\
'TP_COMMUNITY_THEME'=${TP_COMMUNITY_THEME}\\n\
'TP_SCHEME'=${TP_SCHEME}\\n\
'TP_ADDON'=${TP_ADDON}\\n\
'TP_THEME'=${TP_THEME}\\n"
APP_FILEPATH='/app/radarr/bin/UI/index.html'
LOGIN_FILEPATH='/app/radarr/bin/UI/login.html'
APP_ICON_FILEPATH='/app/radarr/bin/UI/Content/Images/Icons'
if [ "${TP_HOTIO}" = true ]; then
echo 'Changing to Hotio file path!'
APP_FILEPATH='/app/bin/UI/index.html'
LOGIN_FILEPATH='/app/bin/UI/login.html'
APP_ICON_FILEPATH='/app/bin/UI/Content/Images/Icons'
fi
# Set default
if [[ -z ${TP_DOMAIN} ]]; then
echo 'No domain set, defaulting to theme-park.dev'
TP_DOMAIN='theme-park.dev'
fi
if [[ -z ${TP_SCHEME} ]]; then
echo 'No scheme set, defaulting to https'
TP_SCHEME='https'
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
# Function to download files for a given addon
download_favicon_files() {
local addon=$1
local urls=$(curl -s "${TP_SCHEME}://${TP_DOMAIN}/themes.json" | jq -r ".addons.radarr[\"$addon\"].files[]?")
for url in $urls; do
# Remove the query parameters from the URL
clean_url="${url%%\?*}"
wget -O "${APP_ICON_FILEPATH}/$(basename "${clean_url}")" "${clean_url}"
printf 'Downloaded favicon: %s\n' "${clean_url}"
done
}
# Adding stylesheets
if ! grep -q "${TP_DOMAIN}/css/base" "${APP_FILEPATH}"; then
echo '---------------------------'
echo '| Adding the stylesheets |'
echo '---------------------------'
url_base="${TP_SCHEME}://${TP_DOMAIN}"
sheets="<link rel='stylesheet' href='${url_base}/css/base/radarr/radarr-base.css'>"
sheets="${sheets} <link rel='stylesheet' href='${url_base}/css/${THEME_TYPE}/${TP_THEME}.css'>"
printf 'Stylesheet set to %s\n' "${TP_THEME}"
if [[ -n ${TP_ADDON} ]]; then
for addon in $(echo "$TP_ADDON" | tr "|" " "); do
sheets="${sheets} <link rel='stylesheet' href='${url_base}/css/addons/radarr/${addon}/${addon}.css'>"
# If the addon variable has "favicon" in it, download all the favicon files from the themes.json file.
if [[ ${addon} == *"favicon"* ]]; then
echo 'Downloading favicon files...'
download_favicon_files "$addon"
fi
printf 'Added custom addon: %s\n\n' "${addon}"
done
fi
sed -i "s!</body>!${sheets}</body>!g" "${APP_FILEPATH}"
sed -i "s!</body>!${sheets}</body>!g" "${LOGIN_FILEPATH}"
printf 'Stylesheets inserted.'
fi