Enhance-Add bdr option

added --use-postgres-bdr
converted postgres.sh to use colours and arguments
This commit is contained in:
mafoo 2016-11-28 09:41:15 +00:00
parent 0a6f0ed346
commit 3aea573e60
2 changed files with 28 additions and 17 deletions

View File

@ -3,7 +3,7 @@
#Process command line options only if we haven't been processed once #Process command line options only if we haven't been processed once
if [ -z "$CPU_CHECK" ]; then if [ -z "$CPU_CHECK" ]; then
export script_name=`basename "$0"` export script_name=`basename "$0"`
ARGS=$(getopt -n '$script_name' -o h -l help,use-switch-source,use-switch-package-all,use-switch-master,use-switch-package-unofficial-arm,use-system-master,no-cpu-check -- "$@") ARGS=$(getopt -n '$script_name' -o h -l help,use-switch-source,use-switch-package-all,use-switch-master,use-switch-package-unofficial-arm,use-system-master,use-postgres-bdr,no-cpu-check -- "$@")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
error "Failed parsing options." error "Failed parsing options."
@ -15,6 +15,7 @@ if [ -z "$CPU_CHECK" ]; then
export USE_SWITCH_PACKAGE_UNOFFICIAL_ARM=false export USE_SWITCH_PACKAGE_UNOFFICIAL_ARM=false
export USE_SWITCH_MASTER=false export USE_SWITCH_MASTER=false
export USE_SYSTEM_MASTER=false export USE_SYSTEM_MASTER=false
export USE_POSTGRES_BDR=false
export CPU_CHECK=true export CPU_CHECK=true
HELP=false HELP=false
@ -24,6 +25,7 @@ if [ -z "$CPU_CHECK" ]; then
--use-switch-package-all ) export USE_SWITCH_PACKAGE_ALL=true; shift ;; --use-switch-package-all ) export USE_SWITCH_PACKAGE_ALL=true; shift ;;
--use-switch-master ) export USE_SWITCH_MASTER=true; shift ;; --use-switch-master ) export USE_SWITCH_MASTER=true; shift ;;
--use-system-master ) export USE_SYSTEM_MASTER=true; shift ;; --use-system-master ) export USE_SYSTEM_MASTER=true; shift ;;
--use-postgres-bdr ) export USE_POSTGRES_BDR=true; shift ;;
--no-cpu-check ) export CPU_CHECK=false; shift ;; --no-cpu-check ) export CPU_CHECK=false; shift ;;
-h | --help ) HELP=true; shift ;; -h | --help ) HELP=true; shift ;;
-- ) shift; break ;; -- ) shift; break ;;
@ -38,6 +40,7 @@ if [ -z "$CPU_CHECK" ]; then
warning " --use-switch-package-unofficial-arm if your system is arm and you are using packages, use the unofficial arm repo" warning " --use-switch-package-unofficial-arm if your system is arm and you are using packages, use the unofficial arm repo"
warning " --use-switch-master will use master branch/packages for the switch instead of ${green}(default:stable)" warning " --use-switch-master will use master branch/packages for the switch instead of ${green}(default:stable)"
warning " --use-system-master will use master branch/packages for the system instead of ${green}(default:stable)" warning " --use-system-master will use master branch/packages for the system instead of ${green}(default:stable)"
warning " --use-postgres-bdr will install postgress-bdr from the 2nd quadrant repo ${green}(default:no)"
warning " --no-cpu-check disable the cpu check ${green}(default:check)" warning " --no-cpu-check disable the cpu check ${green}(default:check)"
exit; exit;
fi fi

View File

@ -1,22 +1,28 @@
#!/bin/sh #!/bin/sh
#move to script directory so all relative paths work
cd "$(dirname "$0")"
. ./colors.sh
. ./arguments.sh
#send a message #send a message
echo "Install PostgreSQL" verbose "Installing PostgreSQL"
#generate a random password #generate a random password
password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64) password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64)
#Postgres if [ $USE_POSTGRES_BDR = true ]; then
echo "Install PostgreSQL and create the database and users\n" verbose "Installing PostgreSQL BDR support from 2ndquadrant"
apt-get install -y --force-yes sudo postgresql echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' >> /etc/apt/sources.list.d/postgresql.list
echo 'deb http://packages.2ndquadrant.com/bdr/apt/ jessie-2ndquadrant main' >> /etc/apt/sources.list.d/2ndquadrant.list
#Add PostgreSQL and BDR REPO /usr/bin/wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
#echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' >> /etc/apt/sources.list.d/postgresql.list /usr/bin/wget --quiet -O - http://packages.2ndquadrant.com/bdr/apt/AA7A6805.asc | apt-key add -
#echo 'deb http://packages.2ndquadrant.com/bdr/apt/ jessie-2ndquadrant main' >> /etc/apt/sources.list.d/2ndquadrant.list apt-get update && apt-get upgrade -y
#/usr/bin/wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add - apt-get install -y --force-yes sudo postgresql-bdr-9.4 postgresql-bdr-9.4-bdr-plugin postgresql-bdr-contrib-9.4
#/usr/bin/wget --quiet -O - http://packages.2ndquadrant.com/bdr/apt/AA7A6805.asc | apt-key add - else
#apt-get update && apt-get upgrade -y apt-get install -y --force-yes sudo postgresql
#apt-get install -y --force-yes sudo postgresql-bdr-9.4 postgresql-bdr-9.4-bdr-plugin postgresql-bdr-contrib-9.4 fi
#systemd #systemd
systemctl daemon-reload systemctl daemon-reload
@ -25,6 +31,8 @@ systemctl restart postgresql
#init.d #init.d
#/usr/sbin/service postgresql restart #/usr/sbin/service postgresql restart
verbose "Creating the database and users"
#move to /tmp to prevent a red herring error when running sudo with psql #move to /tmp to prevent a red herring error when running sudo with psql
cwd=$(pwd) cwd=$(pwd)
cd /tmp cd /tmp
@ -45,8 +53,8 @@ server_address=$(hostname -I)
#Show database password #Show database password
echo "" echo ""
echo "" echo ""
echo "PostgreSQL" verbose "PostgreSQL configuration :-"
echo " Database name: fusionpbx" verbose " Database name: ${yellow}fusionpbx"
echo " Database username: fusionpbx" verbose " Database username: ${yellow}fusionpbx"
echo " Database password: $password" verbose " Database password: ${yellow}$password"
echo "" echo ""