<commit_before>#!/usr/bin/env bash


if [ -f ~/vagrant-bootstrap-done ]; then
  echo 'VM already bootstrapped, fine.'
  exit 0;
fi

echo 'Bootstrapping VM, this will take some time...'



echo '===== Updating the APT repository'

apt-get update



echo '===== Installing PostgreSQL 9.1'

apt-get -y install postgresql-9.1 postgresql-contrib-9.1



echo '===== Configure PostgreSQL to trust *everyone*'

# For now:
# Trust everyone, this is a dev/test machine only.
# First disable old `host` rules.

pg_hba=/etc/postgresql/9.1/main/pg_hba.conf
pg_hba_orig=/etc/postgresql/9.1/main/pg_hba.conf.orig

# Backup original pg_hba.conf.
if [ ! -f $pg_hba_orig ]; then
  mv $pg_hba $pg_hba_orig
fi

# Create new pg_hba.conf that trusts localhost.
if [ ! -f $pg_hba ]; then
  cat $pg_hba_orig | sed 's/^host  /#host /' > $pg_hba
  echo 'host    all             all              127.0.0.1/32           trust' >> $pg_hba
  service postgresql reload
fi



echo '===== Creating PostgreSQL databases and users'

psql -h 127.0.0.1 --username postgres -c "
  create user debiki_dev password '<PASSWORD>';
  create user debiki_test password '<PASSWORD>';
  create user debiki_test_evolutions password '<PASSWORD>';
  alter user debiki_dev set search_path to '\$user';
  alter user debiki_test set search_path to '\$user';
  alter user debiki_test_evolutions set search_path to '\$user';
  "

function create_database_and_schema {
  # Databases cannot be created via multi command strings.
  psql -h 127.0.0.1 --username postgres -c "create database $1 owner $1 encoding 'UTF8';"
  psql -h 127.0.0.1 --username postgres --dbname $1 -c "
    drop schema public;
    create schema authorization $1;
    "
}

create_database_and_schema "debiki_dev"
create_database_and_schema "debiki_test"
create_database_and_schema "debiki_test_evolutions"




echo '===== Installing Java 7 JDK and `unzip`'

apt-get -y install openjdk-7-jdk unzip



echo '===== Installing Play Framework 2.1.1'

play_parent=/opt/play
play_zip_file=play-2.1.1.zip
play_dir_name=play-2.1.1

if [ ! -f $play_parent/play-2.1.1/play ]; then
  mkdir -p $play_parent
  cd $play_parent
  rm $play_zip_file
  rm -fr $play_dir_name
  wget http://downloads.typesafe.com/play/2.1.1/$play_zip_file
  unzip $play_zip_file
  chmod a+x $play_dir_name/play
  chown --recursive vagrant:vagrant $play_parent
fi


echo '===== Installing Node.js v0.10.5 and Grunt'

node_dir_name=node-v0.10.5
node_zip_file=node-v0.10.5.tar.gz

if [ -z `which grunt` ]; then
  apt-get -y install build-essential python
  mkdir -p ~/dev/nodejs/
  cd ~/dev/nodejs/
  if [ ! -f $node_zip_file ]; then
    wget http://nodejs.org/dist/v0.10.5/$node_zip_file
  fi
  # In case any previous build is only somewhat completed, perhaps
  # better start from scratch? So remove directory.
  rm -fr $node_dir_name
  tar -xzf $node_zip_file
  cd $node_dir_name
  ./configure --prefix=/usr/local/
  make
  make install
  npm install -g grunt-cli
fi


echo '===== Installing NPM modules'

cd /vagrant
npm install



echo '===== Adding helpful aliases'

if [ -z "`grep 'alias play=' ~/.bashrc`" ]; then
  chown root /home/vagrant/.bashrc
  echo "
alias l='ls -CF'
alias l1='l -1'<commit_msg>Have Vagrant configure PostgreSQL to listen on all interfaces<commit_after>#!/usr/bin/env bash


if [ -f ~/vagrant-bootstrap-done ]; then
  echo 'VM already bootstrapped, fine.'
  exit 0;
fi

echo 'Bootstrapping VM, this will take some time...'



echo '===== Updating the APT repository'

apt-get update



echo '===== Installing PostgreSQL 9.1'

apt-get -y install postgresql-9.1 postgresql-contrib-9.1



echo '===== Configuring PostgreSQL to trust *everyone*'

# For now:
# Trust everyone, this is a dev/test machine only.
# First disable old `host` rules.

pg_hba=/etc/postgresql/9.1/main/pg_hba.conf
pg_hba_orig=/etc/postgresql/9.1/main/pg_hba.conf.orig

# Backup original pg_hba.conf.
if [ ! -f $pg_hba_orig ]; then
  mv $pg_hba $pg_hba_orig
fi

# Create new pg_hba.conf that trusts localhost.
if [ ! -f $pg_hba ]; then
  cat $pg_hba_orig | sed 's/^host  /#host /' > $pg_hba
  echo 'host    all             all              127.0.0.1/32           trust' >> $pg_hba
  service postgresql reload
fi



echo '===== Configuring PostgreSQL to listen on all interfaces'

# read -r -d '' pgsql_cmd <<'EOF'
pgsql_conf=/etc/postgresql/9.1/main/postgresql.conf
if [ ! -f $pgsql_conf.orig ]; then
  mv $pgsql_conf $pgsql_conf.orig
fi

if [ ! -f $pgsql_conf ]; then
  cat $pgsql_conf.orig \
    | sed -r "s/^#(listen_addresses = )'localhost'/\1'*'\t/" \
    > $pgsql_conf
fi
#EOF
#sudo sh -c "$pgsql_cmd"  # if want to test as non-root user



echo '===== Creating PostgreSQL databases and users'

psql -h 127.0.0.1 --username postgres -c "
  create user debiki_dev password '<PASSWORD>';
  create user debiki_test password '<PASSWORD>';
  create user debiki_test_evolutions password '<PASSWORD>';
  alter user debiki_dev set search_path to '\$user';
  alter user debiki_test set search_path to '\$user';
  alter user debiki_test_evolutions set search_path to '\$user';
  "

function create_database_and_schema {
  # Databases cannot be created via multi command strings.
  psql -h 127.0.0.1 --username postgres -c "create database $1 owner $1 encoding 'UTF8';"
  psql -h 127.0.0.1 --username postgres --dbname $1 -c "
    drop schema public;
    create schema authorization $1;
    "
}

create_database_and_schema "debiki_dev"
create_database_and_schema "debiki_test"
create_database_and_schema "debiki_test_evolutions"




echo '===== Installing Java 7 JDK and `unzip`'

apt-get -y install openjdk-7-jdk unzip



echo '===== Installing Play Framework 2.1.1'

play_parent=/opt/play
play_zip_file=play-2.1.1.zip
play_dir_name=play-2.1.1

if [ ! -f $play_parent/play-2.1.1/play ]; then
  mkdir -p $play_parent
  cd $play_parent
  rm $play_zip_file
  rm -fr $play_dir_name
  wget http://downloads.typesafe.com/play/2.1.1/$play_zip_file
  unzip -q $play_zip_file
  chmod a+x $play_dir_name/play
  chown --recursive vagrant:vagrant $play_parent
fi


echo '===== Installing Node.js v0.10.5 and Grunt'

node_dir_name=node-v0.10.5
node_zip_file=node-v0.10.5.tar.gz

if [ -z `which grunt` ]; then
  apt-get -y install build-essential python
  mkdir -p ~/dev/nodejs/
  cd ~/dev/nodejs/
  if [ ! -f $node_zip_file ]; then
    wget http://nodejs.org/dist/v0.10.5/$node_zip_file
  fi
  # In case any previous build is only somewhat completed, perhaps
  # better start from scratch? So remove directory.
  rm -fr $node_dir_name
  tar -xzf $node_zip_file
  cd $node_dir_name
  ./configure --prefix=/usr/local/
  make
  make install
  npm install -g grunt-cli
fi


echo '===== Installing NPM modules'

cd /vagrant
npm install



echo '===== Adding helpful aliases'

if [ -z "`grep 'alias play=' ~/.bashrc`" ]; then
  chown root /home/vagrant/.bashrc
  echo "
alias l='ls -CF'
alias lal='ls -al'
{'fraction_non_alphanumeric': 0.12656751239428404, 'fraction_numerical': 0.022601341498979296, 'mean_word_length': 3.402439024390244, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '368941', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2559, 'n_words': 718}