]> git.openstreetmap.org Git - rails.git/blob - script/vagrant/setup/provision.sh
Merge branch 'pull/843' into titles
[rails.git] / script / vagrant / setup / provision.sh
1 #!/usr/bin/env bash
2
3 # abort on error
4 set -e
5
6 # set locale to UTF-8 compatible. apologies to non-english speakers...
7 locale-gen en_GB.utf8
8 update-locale LANG=en_GB.utf8 LC_ALL=en_GB.utf8
9 export LANG=en_GB.utf8
10 export LC_ALL=en_GB.utf8
11
12 # make sure we have up-to-date packages
13 apt-get update
14
15 # upgrade all packages
16 apt-get upgrade -y
17
18 # install packages as explained in INSTALL.md
19 apt-get install -y ruby2.3 libruby2.3 ruby2.3-dev \
20                      libmagickwand-dev libxml2-dev libxslt1-dev nodejs \
21                      apache2 apache2-dev build-essential git-core \
22                      postgresql postgresql-contrib libpq-dev postgresql-server-dev-all \
23                      libsasl2-dev imagemagick
24 gem2.3 install bundler
25
26 ## install the bundle necessary for openstreetmap-website
27 pushd /srv/openstreetmap-website
28 # do bundle install as a convenience
29 sudo -u ubuntu -H bundle install --retry=10 --jobs=2
30 # create user and database for openstreetmap-website
31 db_user_exists=`sudo -u postgres psql postgres -tAc "select 1 from pg_roles where rolname='ubuntu'"`
32 if [ "$db_user_exists" != "1" ]; then
33                 sudo -u postgres createuser -s ubuntu
34                 sudo -u ubuntu createdb -E UTF-8 -O ubuntu openstreetmap
35                 sudo -u ubuntu createdb -E UTF-8 -O ubuntu osm_test
36                 # add btree_gist extension
37                 sudo -u ubuntu psql -c "create extension btree_gist" openstreetmap
38                 sudo -u ubuntu psql -c "create extension btree_gist" osm_test
39 fi
40 # build and set up postgres extensions
41 pushd db/functions
42 sudo -u ubuntu make
43 sudo -u ubuntu psql openstreetmap -c "CREATE OR REPLACE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C STRICT"
44 sudo -u ubuntu psql openstreetmap -c "CREATE OR REPLACE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'tile_for_point' LANGUAGE C STRICT"
45 sudo -u ubuntu psql openstreetmap -c "CREATE OR REPLACE FUNCTION xid_to_int4(xid) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'xid_to_int4' LANGUAGE C STRICT"
46 popd
47 # set up sample configs
48 if [ ! -f config/database.yml ]; then
49                 sudo -u ubuntu cp config/example.database.yml config/database.yml
50 fi
51 if [ ! -f config/application.yml ]; then
52                 sudo -u ubuntu cp config/example.application.yml config/application.yml
53 fi
54 # migrate the database to the latest version
55 sudo -u ubuntu rake db:migrate
56 popd