2018-07-03 00:20:47 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
export PGDATA="/etc/postgresql/10/main"
|
2018-07-05 23:23:09 +02:00
|
|
|
export APP_USER="explain"
|
|
|
|
export APP_PASS="explain"
|
2018-08-01 00:23:50 +02:00
|
|
|
export BASEDIR="/vagrant"
|
|
|
|
|
|
|
|
### This script *can* be run on a Docker Ubuntu VM if desired.
|
|
|
|
### To do so, additional commands need to be run:
|
|
|
|
# apt-get update
|
|
|
|
# apt-get -y -qq install make curl libclone-perl lsb-release sudo
|
|
|
|
# sed -i "s/exit.*/exit 0/" /usr/sbin/policy-rc.d
|
|
|
|
# export BASEDIR="/explain"
|
2018-07-03 00:20:47 +02:00
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
# Set username in explain.json
|
2018-08-01 00:23:50 +02:00
|
|
|
sed -i "s/\"username\" : \"explain\"/\"username\" : \"${APP_USER}\"/" ${BASEDIR}/explain.json
|
|
|
|
sed -i "s/\"password\" : \"explain\"/\"password\" : \"${APP_PASS}\"/" ${BASEDIR}/explain.json
|
2018-07-05 23:21:03 +02:00
|
|
|
|
|
|
|
# Install dependencies
|
2018-07-03 00:20:47 +02:00
|
|
|
curl -s -L cpanmin.us | perl - -n Mojolicious
|
2018-08-01 00:23:50 +02:00
|
|
|
apt-get -y -qq install wget ca-certificates cpanminus libmojolicious-perl libmail-sender-perl libdate-simple-perl libemail-valid-perl libxml-simple-perl libdbd-pg-perl
|
2018-07-11 18:55:59 +02:00
|
|
|
|
|
|
|
# Install Pg::Explain
|
2018-07-03 00:20:47 +02:00
|
|
|
cpanm -q Pg::Explain
|
2018-07-05 23:21:03 +02:00
|
|
|
|
|
|
|
# Install Postgres
|
|
|
|
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
|
|
|
|
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
|
|
|
sudo apt-get -y -qq update
|
|
|
|
sudo apt-get -y -qq upgrade
|
|
|
|
sudo apt-get -y -qq install postgresql-10
|
|
|
|
sed -i -e "s/peer/trust/" ${PGDATA}/pg_hba.conf
|
2018-07-03 00:20:47 +02:00
|
|
|
sudo -u postgres psql -tc "select pg_reload_conf()"
|
|
|
|
|
2018-07-05 23:21:03 +02:00
|
|
|
# Create database
|
2018-07-03 00:20:47 +02:00
|
|
|
createdb -U postgres explain
|
2018-07-05 23:21:03 +02:00
|
|
|
|
|
|
|
# Create user
|
|
|
|
psql -qU postgres explain -c "CREATE USER ${APP_USER} WITH PASSWORD '${APP_PASS}'"
|
|
|
|
|
|
|
|
# Apply patches
|
2018-08-01 00:23:50 +02:00
|
|
|
psql -q -f ${BASEDIR}/sql/create.sql -U postgres explain
|
2018-07-05 23:21:03 +02:00
|
|
|
for i in `seq -f "%03g" 1 10`
|
|
|
|
do
|
2018-08-01 00:23:50 +02:00
|
|
|
psql -q -f ${BASEDIR}/sql/patch-${i}.sql -U postgres explain
|
2018-07-05 23:21:03 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# Apply grants
|
|
|
|
psql -qU postgres explain -c "GRANT ALL ON plans, users TO ${APP_USER}"
|
|
|
|
psql -qU postgres explain -c "GRANT ALL ON SCHEMA plans TO ${APP_USER}"
|
|
|
|
for x in `echo {0..9} {A..Z} {a..z}`
|
|
|
|
do
|
|
|
|
psql -qU postgres explain -c "GRANT ALL PRIVILEGES ON plans.\"part_${x}\" TO ${APP_USER}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Done
|
2018-07-03 00:20:47 +02:00
|
|
|
echo "Your Vagrant box is all set up. Use 'vagrant ssh' to log in, then call '/vagrant/explain.pl daemon' to start the service"
|