start of deployment script
#!/usr/bin/env bash
VERSION="0.0.1"
CONFIG=./deploy.conf
WD=.
#
# Output usage information.
#
usage() {
cat <<-EOF
Usage: deploy [options] [command]
Options:
-C, --chdir <path> change the working directory to <path>
-c, --config <path> set config path defaults to ./deploy.conf
-V, --version output program version
-h, --help output help information
Commands:
config [key] output config file or [key]
EOF
}
#
# Abort with <msg>
#
abort() {
echo $@ 1>&2
exit 1
}
#
# Log <msg>.
#
log() {
echo "... $@"
}
#
# Set configuration file <path>.
#
set_config_path() {
test -f $1 || abort 'invalid --config path'
CONFIG=$1
}
#
# Get config value by <key>.
#
config_get() {
local key=$1
test -n "$key" && grep "^$key" $CONFIG | cut -d ' ' -f 2
exit 0
}
#
# Output version.
#
version() {
echo $VERSION && exit 1
}
#
# Output config or [key].
#
config() {
if test $# -eq 0; then
cat $CONFIG
exit 0
else
config_get $1
fi
}
#
# Deploy.
#
deploy() {
echo
log deploying $WD
local url="`config_get user`@`config_get addr`"
log to $url
local key=`config_get key`
test "$WD" != "." && cd $WD && log cd $WD
local tag=`git describe --tags`
log release $tag
echo
}
test $# -eq 0 && deploy && exit 0
# parse argv
while test $# -ne 0; do
arg=$1; shift
case $arg in
-h|--help) usage ;;
-V|--version) version ;;
-c|--config) set_config_path $1 ;;
-C|--chdir) WD=$1 ;;
config) config $@ ;;
esac
done
deploy
key ~/.whateves.pem
user deployer-of-doom
addr n.n.n.n