Manage options

This commit is contained in:
Benjamin Renard 2015-04-27 16:24:21 +02:00
parent 3a062b2852
commit 9686f82b22

View file

@ -19,11 +19,78 @@
PG_USER=postgres PG_USER=postgres
PSQL_BIN=/usr/bin/psql PSQL_BIN=/usr/bin/psql
PG_MAIN=/var/lib/postgresql/9.1/main PG_MAIN=/var/lib/postgresql/9.1/main
RECOVERY_CONF=$PG_MAIN/recovery.conf if [ -f /etc/redhat-release ]
then
PG_MAIN=/var/lib/pgsql/9.1/data
fi
RECOVERY_CONF_FILENAME=recovery.conf
RECOVERY_CONF=""
PG_DEFAULT_PORT=5432 PG_DEFAULT_PORT=5432
DEBUG=0 DEBUG=0
[ "$1" == "-d" ] && DEBUG=1
function usage () {
cat << EOF
Usage : $0 [-d] [-h] [options]
-u pg_user Specify Postgres user (Default : $PG_USER)
-b psql_bin Specify psql binary path (Default : $PSQL_BIN)
-m pg_main Specify Postgres main directory path
(Default : $PG_MAIN)
-r recovery_conf Specify Postgres recovery configuration file path
(Default : $PG_MAIN/$RECOVERY_CONF_FILENAME)
-p pg_port Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT)
-d Debug mode
-h Show this message
EOF
exit 0
}
while getopts "hu:b:m:r:p:d" OPTION
do
case $OPTION in
u)
PG_USER=$OPTARG
;;
b)
PSQL_BIN=$OPTARG
;;
m)
PG_MAIN=$OPTARG
;;
r)
RECOVERY_CONF=$OPTARG
;;
p)
PG_DEFAULT_PORT=$OPTARG
;;
d)
DEBUG=1
;;
h)
usage
;;
\?)
echo -n "Unkown option"
usage
esac
done
# Check PG_USER
[ -z "$PG_USER" ] && echo "UNKNOWN : Postgres user not specify" && exit 3
id "$PG_USER" > /dev/null 2>&1
[ $? -ne 0 ] && echo "UNKNOWN : Invalid Postgres user ($PG_USER)" && exit 3
# Check PSQL_BIN
[ ! -x "$PSQL_BIN" ] && echo "UNKNOWN : Invalid psql bin path ($PSQL_BIN)" && exit 3
# Check PG_MAIN
[ ! -d "$PG_MAIN/" ] && echo "UNKNOWN : Invalid Postgres main directory path ($PG_MAIN)" && exit 3
# Check RECOVERY_CONF
[ -z "$RECOVERY_CONF" ] && RECOVERY_CONF="$PG_MAIN/$RECOVERY_CONF_FILENAME"
# Check PG_DEFAULT_PORT
[ $( echo "$PG_DEFAULT_PORT"|grep -c -E '^[0-9]*$' ) -ne 1 ] && "UNKNOWN : Postgres default master TCP port must be an integer." && exit 3
function psql_get () { function psql_get () {
echo "$1"|su - $PG_USER -c "$PSQL_BIN -t -P format=unaligned" echo "$1"|su - $PG_USER -c "$PSQL_BIN -t -P format=unaligned"
@ -36,6 +103,13 @@ function debug() {
fi fi
} }
debug "Running options :
PG_USER = $PG_USER
PSQL_BIN = $PSQL_BIN
PG_MAIN = $PG_MAIN
RECOVERY_CONF = $RECOVERY_CONF
PG_DEFAULT_PORT = $PG_DEFAULT_PORT"
# Postgres is running ? # Postgres is running ?
if [ $DEBUG -eq 0 ] if [ $DEBUG -eq 0 ]
then then