Skip to content

Instantly share code, notes, and snippets.

@ryenus
Last active August 20, 2019 19:50
Show Gist options
  • Save ryenus/d4aaac85655e62165cf58acbfda55b59 to your computer and use it in GitHub Desktop.
Save ryenus/d4aaac85655e62165cf58acbfda55b59 to your computer and use it in GitHub Desktop.

Revisions

  1. ryenus revised this gist Aug 20, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion catalina.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/sh

    export CATALINA_HOME="$(brew --prefix tomcat)/libexec"
    export CATALINA_BASE="$(brew --prefix)/var/tomcat"
    export CATALINA_BASE="${CATALINA_BASE:-$(brew --prefix)/var/tomcat}"

    catalina_init() {
    if [ ! -e "$CATALINA_BASE/conf" ]; then
  2. ryenus created this gist Aug 20, 2019.
    36 changes: 36 additions & 0 deletions catalina.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/bin/sh

    export CATALINA_HOME="$(brew --prefix tomcat)/libexec"
    export 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" "$@"