Created
April 17, 2012 18:51
-
-
Save jacaetevha/2408207 to your computer and use it in GitHub Desktop.
A Bash script that wraps FPM, allowing access to certain environment variables in an RPM post install script
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/bash | |
# get the actual directory for this script, resolving links and relative paths | |
SOURCE="${BASH_SOURCE[0]}" | |
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done | |
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | |
ARCH="${ARCH:-x86_64}" | |
RELEASE="${RELEASE:-`date +%Y_%m_%d_%H%M`}" | |
VERSION="${VERSION:-1.0}" | |
MAINTAINER="${MAINTAINER:[email protected]}" | |
PREFIX="${PREFIX:-/opt/servers/my_sweet_application}" | |
NAME="my-sweet-app" | |
mkdir -p $DIR/tmp | |
cat > $DIR/tmp/post_remove.sh <<EOF | |
rm -fR $PREFIX/some_known_directory | |
EOF | |
cat > $DIR/tmp/post_install.sh <<EOF | |
cd $PREFIX/some_known_directory/some_sub_directory | |
echo "PREFIX: $PREFIX" | |
IP=/sbin/ifconfig | grep '(192.168|10.1|10.2)' | cut -d: -f2 | cut -d' ' -f1 | |
# note that if you want to refer to environment variables | |
# that you set up within this script, you need to escape | |
# the dollar-sign | |
case \$IP in | |
192.168.201. ) | |
# local environment | |
export HOST="\$IP" | |
export PORT="4567" | |
export USER="foobar" | |
export PASSWORD="t0ps3cr*t" | |
export SCHEMA="app1" | |
;; | |
10.1.1. ) | |
# perhaps a QA environment | |
export HOST="\$IP" | |
export PORT="9000" | |
export USER="qa1" | |
export PASSWORD="qapasswordthatseasytoremember" | |
export SCHEMA="qa-app1" | |
;; | |
10.2.200.201 ) | |
# a prod environment | |
export HOST="\$IP" | |
export PORT="9001" | |
export USER="prod" | |
export PASSWORD="AlRj*7&5$0FaN_kE)" | |
export SCHEMA="prod-app1" | |
;; | |
10.2.200.202 ) | |
# a prod environment | |
export HOST="\$IP" | |
export PORT="9002" | |
export USER="prod" | |
export PASSWORD="AlRj*7&5$0FaN_kE)" | |
export SCHEMA="prod-app2" | |
;; | |
10.2.200.203 ) | |
# a prod environment | |
export HOST="\$IP" | |
export PORT="9003" | |
export USER="prod" | |
export PASSWORD="AlRj*7&5$0FaN_kE)" | |
export SCHEMA="prod-app2" | |
;; | |
10.2.200.204 ) | |
# a prod environment | |
export HOST="\$IP" | |
export PORT="9004" | |
export USER="prod" | |
export PASSWORD="AlRj*7&5$0FaN_kE)" | |
export SCHEMA="prod-app4" | |
;; | |
"" ) | |
echo "Strange! We're deploying to an unhandled IP range" | |
exit -1 | |
;; | |
esac | |
# Do other stuff, potentially using the environment variables | |
# that are already available to you. Don't forget that you also | |
# have some variables available to you from RPM (eg. \$BUILD_ROOT) | |
EOF | |
fpm -a $ARCH -s dir -t rpm -v $VERSION -n $NAME --iteration $RELEASE -m $MAINTAINER \ | |
--after-install $DIR/tmp/post_install.sh --after-remove $DIR/tmp/post_remove.sh \ | |
--vendor "Acme Corp" --license '(c) Acme Corp' --prefix $PREFIX/ -C $DIR/deployment/platform . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment