DCD-545: Remove old script entrypoint and template helper.

This commit is contained in:
Steve Smith 2019-08-13 11:34:56 +10:00
parent 8f9469c9ac
commit 03151b3770
2 changed files with 0 additions and 228 deletions

View File

@ -1,129 +0,0 @@
#!/bin/bash
set -euo pipefail
function log {
echo '[Entrypoint]' $*
}
######################################################################
# Generate server.xml for Tomcat. We lower-case these vars to be
# compatible with the Ansible templates in
# https://bitbucket.org/atlassian/dc-deployments-automation
# Previous names for parameters, preserved for backwards compatability
: ${CATALINA_CONNECTOR_PROXYNAME:=}
: ${CATALINA_CONNECTOR_PROXYPORT:=}
: ${CATALINA_CONNECTOR_SCHEME:=http}
: ${CATALINA_CONNECTOR_SECURE:=false}
: ${CATALINA_CONTEXT_PATH:=}
: ${CATALINA_OPTS:=}
export CATALINA_OPTS
# Use new var name, or previous var name, or default...
export atl_proxy_name=${ATL_PROXY_NAME:=$CATALINA_CONNECTOR_PROXYNAME}
export atl_proxy_port=${ATL_PROXY_PORT:=$CATALINA_CONNECTOR_PROXYPORT}
export atl_tomcat_secure=${ATL_TOMCAT_SECURE:=$CATALINA_CONNECTOR_SECURE}
export atl_tomcat_scheme=${ATL_TOMCAT_SCHEME:=$CATALINA_CONNECTOR_SCHEME}
export atl_tomcat_contextpath=${ATL_TOMCAT_CONTEXTPATH:=$CATALINA_CONTEXT_PATH}
export atl_tomcat_port=${ATL_TOMCAT_PORT:=8090}
export atl_tomcat_mgmt_port=${ATL_TOMCAT_MGMT_PORT:=8000}
export atl_tomcat_maxthreads=${ATL_TOMCAT_MAXTHREADS:=200}
export atl_tomcat_minsparethreads=${ATL_TOMCAT_MINSPARETHREADS:=10}
export atl_tomcat_connectiontimeout=${ATL_TOMCAT_CONNECTIONTIMEOUT:=20000}
export atl_tomcat_enablelookups=${ATL_TOMCAT_ENABLELOOKUPS:=false}
export atl_tomcat_protocol=${ATL_TOMCAT_PROTOCOL:=HTTP/1.1}
export atl_tomcat_redirectport=${ATL_TOMCAT_REDIRECTPORT:=8443}
export atl_tomcat_acceptcount=${ATL_TOMCAT_ACCEPTCOUNT:=10}
log "Generating ${CONFLUENCE_INSTALL_DIR}/conf/server.xml"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/server.xml.j2 \
> ${CONFLUENCE_INSTALL_DIR}/conf/server.xml
######################################################################
# Confluence config files
log "Generating ${CONFLUENCE_HOME}/confluence.cfg.xml"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.head.xml.j2 \
> ${CONFLUENCE_HOME}/confluence.cfg.xml
: ${ATL_JDBC_URL:=}
if [[ ! -z "$ATL_JDBC_URL" ]]; then
declare -A databases=(
["mysql-driver"]="com.mysql.jdbc.Driver"
["mysql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.MySQLDialect"
["postgresql-driver"]="org.postgresql.Driver"
["postgresql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.PostgreSQLDialect"
["mssql-driver"]="com.microsoft.sqlserver.jdbc.SQLServerDriver"
["mssql-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.SQLServerDialect"
["oracle12c-driver"]="oracle.jdbc.driver.OracleDriver"
["oracle12c-dialect"]="com.atlassian.confluence.impl.hibernate.dialect.OracleDialect"
)
# Must be supplied
export atl_jdbc_url=${ATL_JDBC_URL}
export atl_jdbc_user=${ATL_JDBC_USER}
export atl_jdbc_password=${ATL_JDBC_PASSWORD}
export atl_db_choice=${ATL_DB_TYPE}
export atl_db_driver=${databases[${atl_db_choice}"-driver"]}
export atl_db_dialect=${databases[${atl_db_choice}"-dialect"]}
# Defaults, can be overridden
export atl_db_poolmaxsize=${ATL_DB_POOLMAXSIZE:=100}
export atl_db_poolminsize=${ATL_DB_POOLMINSIZE:=20}
export atl_db_timeout=${ATL_DB_TIMEOUT:=30}
export atl_db_idletestperiod=${ATL_DB_IDLETESTPERIOD:=100}
export atl_db_maxstatements=${ATL_DB_MAXSTATEMENTS:=0}
export atl_db_validate=${ATL_DB_VALIDATE:=false}
export atl_db_acquireincrement=${ATL_DB_ACQUIREINCREMENT:=1}
export atl_db_validationquery=${ATL_DB_VALIDATIONQUERY:=select 1}
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.db.xml.j2 \
>> ${CONFLUENCE_HOME}/confluence.cfg.xml
fi
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence.cfg.tail.xml.j2 \
>> ${CONFLUENCE_HOME}/confluence.cfg.xml
chown ${RUN_USER}.${RUN_GROUP} ${CONFLUENCE_HOME}/confluence.cfg.xml
chmod 0640 ${CONFLUENCE_HOME}/confluence.cfg.xml
# The default is two weeks, in seconds, same as the seraph default.
export atl_autologin_cookie_age=${ATL_AUTOLOGIN_COOKIE_AGE:=1209600}
log "Generating ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/seraph-config.xml"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/seraph-config.xml.j2 \
> ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/seraph-config.xml
export atl_product_home=${CONFLUENCE_HOME}
log "Generating ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties"
/opt/atlassian/bin/templater.sh \
/opt/atlassian/etc/confluence-init.properties.j2 \
> ${CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties
# Start Confluence as the correct user
if [ "${UID}" -eq 0 ]; then
echo "User is currently root. Will change directory ownership to ${RUN_USER}:${RUN_GROUP}, then downgrade permission to ${RUN_USER}"
PERMISSIONS_SIGNATURE=$(stat -c "%u:%U:%a" "${CONFLUENCE_HOME}")
EXPECTED_PERMISSIONS=$(id -u ${RUN_USER}):${RUN_USER}:700
if [ "${PERMISSIONS_SIGNATURE}" != "${EXPECTED_PERMISSIONS}" ]; then
chmod -R 700 "${CONFLUENCE_HOME}" &&
chown -R "${RUN_USER}:${RUN_GROUP}" "${CONFLUENCE_HOME}"
fi
# Now drop privileges
exec su -s /bin/bash "${RUN_USER}" -c "$CONFLUENCE_INSTALL_DIR/bin/start-confluence.sh $@"
else
exec "$CONFLUENCE_INSTALL_DIR/bin/start-confluence.sh" "$@"
fi

View File

@ -1,99 +0,0 @@
#!/bin/bash
# Replaces all {{VAR}} by the $VAR value in a template file and outputs it
# Use with -h to output all variables
# Original from https://github.com/lavoiesl/bash-templater/commit/265e91f31affdb2fdc56e011592ba21e1b95ba74
# MIT License: https://github.com/lavoiesl/bash-templater/blob/265e91f31affdb2fdc56e011592ba21e1b95ba74/LICENSE
if [[ ! -f "$1" ]]; then
echo "Usage: VAR=value $0 template" >&2
exit 1
fi
template="$1"
vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//')
if [[ -z "$vars" ]]; then
echo "Warning: No variable was found in $template, syntax is {{VAR}}" >&2
cat $template
exit
fi
var_value() {
var="${1}"
eval echo \$"${var}"
}
##
# Escape custom characters in a string
# Example: escape "ab'\c" '\' "'" ===> ab\'\\c
#
function escape_chars() {
local content="${1}"
shift
for char in "$@"; do
content="${content//${char}/\\${char}}"
done
echo "${content}"
}
function echo_var() {
local var="${1}"
local content="${2}"
local escaped="$(escape_chars "${content}" "\\" '"')"
echo "${var}=\"${escaped}\""
}
declare -a replaces
replaces=()
# Reads default values defined as {{VAR=value}} and delete those lines
# There are evaluated, so you can do {{PATH=$HOME}} or {{PATH=`pwd`}}
# You can even reference variables defined in the template before
defaults=$(grep -oE '^\{\{[A-Za-z0-9_]+=.+\}\}$' "${template}" | sed -e 's/^{{//' -e 's/}}$//')
IFS=$'\n'
for default in $defaults; do
var=$(echo "${default}" | grep -oE "^[A-Za-z0-9_]+")
current="$(var_value "${var}")"
# Replace only if var is not set
if [[ -n "$current" ]]; then
eval "$(echo_var "${var}" "${current}")"
else
eval "${default}"
fi
# remove define line
replaces+=("-e")
replaces+=("/^{{${var}=/d")
vars="${vars} ${var}"
done
vars="$(echo "${vars}" | tr " " "\n" | sort | uniq)"
if [[ "$2" = "-h" ]]; then
for var in $vars; do
value="$(var_value "${var}")"
echo_var "${var}" "${value}"
done
exit 0
fi
# Replace all {{VAR}} by $VAR value
for var in $vars; do
value="$(var_value "${var}")"
if [[ -z "$value" ]]; then
echo "Warning: $var is not defined and no default is set, replacing by empty" >&2
fi
# Escape slashes
value="$(escape_chars "${value}" "\\" '/' ' ')";
replaces+=("-e")
replaces+=("s/{{\s*${var}\s*}}/${value}/g")
done
sed "${replaces[@]}" "${template}"