Last active
August 20, 2019 19:50
-
-
Save ryenus/d4aaac85655e62165cf58acbfda55b59 to your computer and use it in GitHub Desktop.
/usr/local/opt/tomcat/bin/catalina
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export CATALINA_HOME="$(brew --prefix tomcat)/libexec" | |
export CATALINA_BASE="${CATALINA_BASE:-$(brew --prefix)/var/tomcat}" | |
catalina_init() { | |
if [ ! -e "$CATALINA_BASE/conf" ]; then | |
mkdir -p "$CATALINA_BASE" | |
cp -r "$CATALINA_HOME/conf" "$CATALINA_BASE/" | |
fi | |
if [ ! -e "$CATALINA_BASE/conf/Catalina/localhost/" ]; then | |
mkdir -p "$CATALINA_BASE/conf/Catalina/localhost/" | |
fi | |
for app in "$CATALINA_HOME/webapps"/*/; do | |
app_name=$(basename "$app") | |
context_file="$CATALINA_BASE/conf/Catalina/localhost/${app_name/ROOT/tomcat}.xml" | |
if [ ! -e "$context_file" ]; then | |
if [ -e "$app/META-INF/context.xml" ]; then | |
cp "$app/META-INF/context.xml" "$context_file" | |
sed -i "s,<Context,<Context docBase=\"\${catalina.home}/webapps/${app_name}\"," "$context_file" | |
else | |
printf '<?xml version="1.0" encoding="UTF-8"?>\n<Context docBase="${catalina.home}/webapps/%s" />\n' \ | |
"${app_name}" > "$context_file" | |
fi | |
fi | |
done | |
} | |
if [ ! -e "$CATALINA_BASE" ]; then | |
catalina_init | |
fi | |
"$CATALINA_HOME/bin/catalina.sh" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is to leverage
$CATALINA_BASE
to make sure previously deployed web apps are properly migrated after brew update tomcat.