server/configs/nginx-chbase.sh

38 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
[ -f "/base_changed" ] && exit 0
[ -z "${FIC_BASEURL}" ] && exit 0
[ -z "${PATH_STATIC}" ] && { >&2 echo "PATH_STATIC not defined"; exit 1; }
[ -n "${CURRENT_BASE}" ] || CURRENT_BASE="/"
run() {
local NEWBASE=$1
local FILE=$2
if [ -d "${FILE}" ]
then
for f in "${FILE}/"*.html "${FILE}/"*.js "${FILE}/"*.css
do
run "${NEWBASE}" "${f}"
done
[ -d "${FILE}/js/" ] && run "${NEWBASE}" "${FILE}/js"
[ -d "${FILE}/views/" ] && run "${NEWBASE}" "${FILE}/views"
[ -d "${FILE}/_app/" ] && run "${NEWBASE}" "${FILE}/_app"
[ -d "${FILE}/_app/assets/pages/" ] && run "${NEWBASE}" "${FILE}/_app/assets/pages"
elif [ -f "${FILE}" ]
then
if [ "${FILE##*.}" == "css" ]
then
sed -ri "s@${CURRENT_BASE}_app/@${NEWBASE}_app/@g" ${FILE}
else
sed -ri "s@(href|src)=\"${CURRENT_BASE}@\1=\"${NEWBASE}@g;s@\\\$http.get\(\"${CURRENT_BASE}@\$http.get\(\"${NEWBASE}@g;s@\\\$http\((.*)\"${CURRENT_BASE}@\$http(\1\"${NEWBASE}@g;s@\"${CURRENT_BASE}_app@\"${NEWBASE}_app@g;s@\`${CURRENT_BASE}_app/\\\$@\`${NEWBASE}_app/\\\$@g;s@paths: \{\"base\":\"${CURRENT_BASE%/}\",\"assets\":\"${CURRENT_BASE%/}\"\},@paths: {\"base\":\"${NEWBASE%/}\",\"assets\":\"${NEWBASE%/}\"},@" ${FILE}
fi
fi
}
run "${FIC_BASEURL}" "${PATH_STATIC}"
touch "/base_changed"
exit 0