Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active August 29, 2015 14:12
Show Gist options
  • Save tuxfight3r/28c2c7367a9d315ff24b to your computer and use it in GitHub Desktop.
Save tuxfight3r/28c2c7367a9d315ff24b to your computer and use it in GitHub Desktop.
Bash hash trick with compgen for rpmbuilds
#Declare Variables
cat > cas <<EOF
#CAS TEST CONFIG
# Vars starting with APP_ are used to replace contents in skeletons files
APP_HTTP_PORT=12385
APP_HTTPS_PORT=12386
APP_AJP_PORT=12387
APP_HTTP_MAX_THREADS=150
APP_HTTP_MIN_SPARE_THREADS=25
APP_JMX_READER_USER=reader
APP_JMX_READER_PASSWORD=s3cr3t
APP_JMX_ADMIN_USER=admin
APP_JMX_ADMIN_PASSWORD=s3cr3t
EOF
#Shell Script to build hash
cat > skel_test.sh <<EOF
#!/bin/bash
source cas
ALL_VARS=$(compgen -A variable | grep APP_)
for RES_KEY in $ALL_VARS; do
eval RES_VAL=\$${RES_KEY}
XREPLACE="$XREPLACE | sed 's|@${RES_KEY}@|$RES_VAL|g'"
done
for XFILE in server.xml.skel jmxremote.access.skel ; do
DXFILE=${XFILE%.skel}
eval "cat ${XFILE} $XREPLACE > ${DXFILE}"
done
EOF
#Sample files where contents to be replaced.
cat > jmxremote.access.skel <<EOF
# JMX Access Control file
#
monitorRole readonly
controlRole readwrite \
create javax.management.monitor.*,javax.management.timer.* \
unregister
@APP_JMX_READER_USER@ readonly
@APP_JMX_ADMIN_USER@ readwrite
EOF
cat > server.xml.skel <<EOF
<Connector port="@APP_HTTP_PORT@" protocol="HTTP/1.1"
connectionTimeout="20000" maxThreads="@APP_HTTP_MAX_THREADS@" minSpareThreads="@APP_HTTP_MIN_SPARE_THREADS@"
redirectPort="@APP_HTTPS_PORT@" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="@APP_HTTP_PORT@" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="@APP_HTTPS_PORT@" />
-->
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment