diff --git a/linux-setup.sh b/linux-setup.sh index 2b7b198..d892a48 100755 --- a/linux-setup.sh +++ b/linux-setup.sh @@ -247,6 +247,24 @@ install_watchman() { fi } +install_postgresql() { + # Instructions taken from + # https://pgdash.io/blog/postgres-11-getting-started.html + # Postgres 11 is not available in 18.04, so we need to add the pg apt repository. + curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc \ + | sudo apt-key add - + + sudo add-apt-repository -y "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -c -s`-pgdg main" + sudo apt-get update + sudo apt-get install -y postgresql-11 postgresql-contrib libpq-dev + + # Set up authentication to allow connections from the postgres user with no + # password. This matches the authentication setup that homebrew installs on + # a mac. Unlike a mac, we do not need to create a postgres user manually. + sudo cp -av postgresql/pg_hba.conf "/etc/postgresql/11/main/pg_hba.conf" + sudo service postgresql restart +} + setup_clock() { # This shouldn't be necessary, but it seems it is. if ! grep -q 3.ubuntu.pool.ntp.org /etc/ntp.conf; then @@ -288,5 +306,6 @@ install_protoc install_watchman setup_clock config_inotify +install_postgresql trap - EXIT diff --git a/mac-setup.sh b/mac-setup.sh index f644dbc..9d079c7 100755 --- a/mac-setup.sh +++ b/mac-setup.sh @@ -281,6 +281,25 @@ install_node() { fi } +install_postgresql() { + if ! brew ls postgresql >/dev/null 2>&1; then + info "Installing postgresql\n" + brew install postgresql@11 + else + success "postgresql already installed" + fi + + # We create a postgres user locally that we use in test and dev. + if ! psql \ + -tc "SELECT rolname from pg_catalog.pg_roles" postgres \ + | grep -c 'postgres' > /dev/null 2>&1 ; then + info "Creating postgres user for dev\n" + psql --quiet -c "CREATE ROLE postgres LOGIN SUPERUSER;" postgres; + else + success "postgres user already created" + fi +} + install_nginx() { info "Checking for nginx\n" if ! type nginx >/dev/null 2>&1; then @@ -343,7 +362,7 @@ install_protoc() { } install_watchman() { - if ! which watchman ; then + if ! which watchman >/dev/null 2>&1; then update "Installing watchman..." brew install watchman fi @@ -431,6 +450,7 @@ install_homebrew install_slack update_git install_node +install_postgresql install_nginx install_image_utils install_helpful_tools diff --git a/postgresql/pg_hba.conf b/postgresql/pg_hba.conf new file mode 100644 index 0000000..87f8388 --- /dev/null +++ b/postgresql/pg_hba.conf @@ -0,0 +1,13 @@ +# We allow any connection by the postgres user to local addresses, without a +# password. + +# TYPE DATABASE USER ADDRESS METHOD +# "local" is for Unix domain socket connections only +local all postgres trust + +# IPv4 local connections: +host all postgres 127.0.0.1/32 trust +# IPv6 local connections: +host all postgres ::1/128 trust + + diff --git a/setup.sh b/setup.sh index d99d5b5..e123586 100755 --- a/setup.sh +++ b/setup.sh @@ -318,6 +318,13 @@ download_db_dump() { fi } +create_pg_databases() { + if [ "$WEBAPP" = true ]; then + echo "Creating postgres databases" + ( cd "$REPOS_DIR/webapp" ; make pg_create ) + fi +} + # Make sure we store userinfo so we can pass appropriately when ka-cloning. update_userinfo() { echo "Updating your git user info" @@ -393,6 +400,7 @@ install_deps # pre-reqs: clone_repos, install_and_setup_gcloud install_hooks # pre-req: clone_repos setup_arc # pre-req: clone_repos download_db_dump # pre-req: install_deps +create_pg_databases # pre-req: install_deps echo