<commit_before>#!/bin/bash

function install()
{
    # Clean Up

    rm -rf "${tomcatInstallFolder}"
    mkdir -p "${tomcatInstallFolder}"

    # Install

    unzipRemoteFile "${tomcatDownloadURL}" "${tomcatInstallFolder}"

    # Config Server

    local serverConfigData=(
        8009 "${tomcatAJPPort}"
        8005 "${tomcatCommandPort}"
        8080 "${tomcatHTTPPort}"
        8443 "${tomcatHTTPSPort}"
    )

    createFileFromTemplate "${tomcatInstallFolder}/conf/server.xml" "${tomcatInstallFolder}/conf/server.xml" "${serverConfigData[@]}"

    # Config Profile

    local profileConfigData=('__INSTALL_FOLDER__' "${tomcatInstallFolder}")

    createFileFromTemplate "${appPath}/../files/profile/tomcat.sh" '/etc/profile.d/tomcat.sh' "${profileConfigData[@]}"

    # Config Upstart

    if [[ "$(isEmptyString "${tomcatJDKFolder}")" = 'true' ]]
    then
        local tomcatJDKFolder="${jdkInstallFolder}"
    fi

    local upstartConfigData=(
        '__INSTALL_FOLDER__' "${tomcatInstallFolder}"
        '__JDK_FOLDER__' "${tomcatJDKFolder}"
        '__UID__' "${tomcatUID}"
        '__GID__' "${tomcatGID}"
    )

    createFileFromTemplate "${appPath}/../files/upstart/tomcat.conf" "/etc/init/${tomcatServiceName}.conf" "${upstartConfigData[@]}"

    # Start

    addSystemUser "${tomcatUID}" "${tomcatGID}"
    chown -R "${tomcatUID}":"${tomcatGID}" "${tomcatInstallFolder}"
    start "${tomcatServiceName}"

    # Display Version

    info "\n$("${tomcatInstallFolder}/bin/version.sh")"
}

function main()
{
    appPath="$(cd "$(dirname "${0}")" && pwd)"

    source "${appPath}/../../../lib/util.bash" || exit 1
    source "${appPath}/../attributes/default.bash" || exit 1
    source "${appPath}/../../jdk/attributes/default.bash" || exit 1

    checkRequireDistributor

    header 'INSTALLING TOMCAT'

    checkRequireRootUser
    checkRequirePort "${tomcatAJPPort}" "${tomcatCommandPort}" "${tomcatHTTPPort}" "${tomcatHTTPSPort}"

    install
    installCleanUp

    displayOpenPorts<commit_msg>auto install jdk<commit_after>#!/bin/bash

function installDependencies()
{
    if [[ "$(existCommand 'java')" = 'false' ]]
    then
        "${appPath}/../../jdk/recipes/install.bash"
    fi
}

function install()
{
    # Clean Up

    rm -rf "${tomcatInstallFolder}"
    mkdir -p "${tomcatInstallFolder}"

    # Install

    unzipRemoteFile "${tomcatDownloadURL}" "${tomcatInstallFolder}"

    # Config Server

    local serverConfigData=(
        8009 "${tomcatAJPPort}"
        8005 "${tomcatCommandPort}"
        8080 "${tomcatHTTPPort}"
        8443 "${tomcatHTTPSPort}"
    )

    createFileFromTemplate "${tomcatInstallFolder}/conf/server.xml" "${tomcatInstallFolder}/conf/server.xml" "${serverConfigData[@]}"

    # Config Profile

    local profileConfigData=('__INSTALL_FOLDER__' "${tomcatInstallFolder}")

    createFileFromTemplate "${appPath}/../files/profile/tomcat.sh" '/etc/profile.d/tomcat.sh' "${profileConfigData[@]}"

    # Config Upstart

    if [[ "$(isEmptyString "${tomcatJDKFolder}")" = 'true' ]]
    then
        local tomcatJDKFolder="${jdkInstallFolder}"
    fi

    local upstartConfigData=(
        '__INSTALL_FOLDER__' "${tomcatInstallFolder}"
        '__JDK_FOLDER__' "${tomcatJDKFolder}"
        '__UID__' "${tomcatUID}"
        '__GID__' "${tomcatGID}"
    )

    createFileFromTemplate "${appPath}/../files/upstart/tomcat.conf" "/etc/init/${tomcatServiceName}.conf" "${upstartConfigData[@]}"

    # Start

    addSystemUser "${tomcatUID}" "${tomcatGID}"
    chown -R "${tomcatUID}":"${tomcatGID}" "${tomcatInstallFolder}"
    start "${tomcatServiceName}"

    # Display Version

    info "\n$("${tomcatInstallFolder}/bin/version.sh")"
}

function main()
{
    appPath="$(cd "$(dirname "${0}")" && pwd)"

    source "${appPath}/../../../lib/util.bash" || exit 1
    source "${appPath}/../attributes/default.bash" || exit 1
    source "${appPath}/../../jdk/attributes/default.bash" || exit 1

    checkRequireDistributor

    header 'INSTALLING TOMCAT'

    checkRequireRootUser
    checkRequirePort "${tomcatAJPPort}" "${tomcatCommandPort}" "${tomcatHTTPPort}" "${tomcatHTTPSPort}"

    installDependencies
    install
    installCleanUp

    displayOpenPorts
{'fraction_non_alphanumeric': 0.17185642975992393, 'fraction_numerical': 0.009507962918944617, 'mean_word_length': 3.568946796959826, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4653121', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1302, 'n_words': 229}