Merge branch 'master' into overpass
[rails.git] / script / vagrant / setup / provision.sh
1 #!/usr/bin/env bash
2
3 # set locale to UTF-8 compatible. apologies to non-english speakers...
4 update-locale LANG=en_GB.utf8 LC_ALL=en_GB.utf8
5 locale-gen
6 export LANG=en_GB.utf8
7 export LC_ALL=en_GB.utf8
8
9 # make sure we have up-to-date packages
10 apt-get update
11
12 ## vagrant grub-pc fix from: https://gist.github.com/jrnickell/6289943
13 # parameters
14 echo "grub-pc grub-pc/kopt_extracted boolean true" | debconf-set-selections
15 echo "grub-pc grub2/linux_cmdline string" | debconf-set-selections
16 echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | debconf-set-selections
17 echo "grub-pc grub-pc/install_devices_failed_upgrade boolean true" | debconf-set-selections
18 echo "grub-pc grub-pc/install_devices_disks_changed multiselect /dev/sda" | debconf-set-selections
19 # vagrant grub fix
20 dpkg-reconfigure -f noninteractive grub-pc
21
22 # upgrade all packages
23 apt-get upgrade -y
24
25 # install packages as explained in INSTALL.md
26 apt-get install -y ruby1.9.1 libruby1.9.1 ruby1.9.1-dev ri1.9.1 \
27     libmagickwand-dev libxml2-dev libxslt1-dev nodejs \
28     apache2 apache2-threaded-dev build-essential git-core \
29     postgresql postgresql-contrib libpq-dev postgresql-server-dev-all \
30     libsasl2-dev
31 gem1.9.1 install bundle
32
33 ## install the bundle necessary for openstreetmap-website
34 pushd /srv/openstreetmap-website
35 # do bundle install as a convenience
36 sudo -u vagrant -H bundle install
37 # create user and database for openstreetmap-website
38 db_user_exists=`sudo -u postgres psql postgres -tAc "select 1 from pg_roles where rolname='vagrant'"`
39 if [ "$db_user_exists" != "1" ]; then
40                 sudo -u postgres createuser -s vagrant
41                 sudo -u vagrant -H createdb -E UTF-8 -O vagrant openstreetmap
42                 sudo -u vagrant -H createdb -E UTF-8 -O vagrant osm_test
43                 # add btree_gist extension
44                 sudo -u vagrant -H psql -c "create extension btree_gist" openstreetmap
45 fi
46 # build and set up postgres extensions
47 pushd db/functions
48 sudo -u vagrant make
49 sudo -u vagrant psql openstreetmap -c "drop function if exists maptile_for_point(int8, int8, int4)"
50 sudo -u vagrant psql openstreetmap -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C STRICT"
51 popd
52 # set up sample configs
53 if [ ! -f config/database.yml ]; then
54                 sudo -u vagrant cp config/example.database.yml config/database.yml
55 fi
56 if [ ! -f config/application.yml ]; then
57                 sudo -u vagrant cp config/example.application.yml config/application.yml
58 fi
59 # migrate the database to the latest version
60 sudo -u vagrant rake db:migrate
61 popd