#!/usr/bin/with-contenv bash
echo '-------------------------'
echo '| Mylar3 theme.park Mod |'
echo '-------------------------'
APP_FILEPATH='/app/mylar3/data/interfaces/default'
if [ "${TP_HOTIO}" = true ]; then
echo 'Changing to Hotio file path!'
APP_FILEPATH='/app/data/interfaces/default'
fi
# Display variables for troubleshooting
echo -e "Variables set:\\n\
'APP_FILEPATH'=${APP_FILEPATH}\\n\
'TP_HOTIO'=${TP_HOTIO}\\n\
'TP_DOMAIN'=${TP_DOMAIN}\\n\
'TP_COMMUNITY_THEME'=${TP_COMMUNITY_THEME}\\n\
'TP_SCHEME'=${TP_SCHEME}\\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
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
sed_file(){
sed -i "s/<\/head>/<\/head> /g" $1
sed -i "s/<\/head>/<\/head> /g" $1
printf 'Stylesheet set to %s on %s\n\n' "${TP_THEME}" "$1"
}
# Adding stylesheets
echo '---------------------------------------'
echo '| Adding the stylesheet to html files |'
echo '---------------------------------------'
if ! grep -q "${TP_DOMAIN}/css/base" "${APP_FILEPATH}/index.html"; then
find ${APP_FILEPATH} -type f -iname *.html | while read fname
do
sed_file $fname
done
fi