]> git.openstreetmap.org Git - rails.git/blob - script/vagrant/setup/provision.sh
Merge remote-tracking branch 'upstream/pull/3285'
[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.7 libruby2.7 ruby2.7-dev \
20                      libmagickwand-dev libxml2-dev libxslt1-dev nodejs yarnpkg \
21                      apache2 apache2-dev build-essential git-core firefox-geckodriver \
22                      postgresql postgresql-contrib libpq-dev \
23                      libsasl2-dev imagemagick libffi-dev libgd-dev libarchive-dev libbz2-dev
24 gem2.7 install rake
25 gem2.7 install --version "~> 2.1.4" bundler
26
27 ## install the bundle necessary for openstreetmap-website
28 pushd /srv/openstreetmap-website
29 # do bundle install as a convenience
30 bundle install --retry=10 --jobs=2
31 # do yarn install as a convenience
32 bundle exec rake yarn:install
33 # create user and database for openstreetmap-website
34 db_user_exists=`sudo -u postgres psql postgres -tAc "select 1 from pg_roles where rolname='vagrant'"`
35 if [ "$db_user_exists" != "1" ]; then
36     sudo -u postgres createuser -s vagrant
37     sudo -u vagrant createdb -E UTF-8 -O vagrant openstreetmap
38     sudo -u vagrant createdb -E UTF-8 -O vagrant osm_test
39     # add btree_gist extension
40     sudo -u vagrant psql -c "create extension btree_gist" openstreetmap
41     sudo -u vagrant psql -c "create extension btree_gist" osm_test
42 fi
43
44
45 # install PostgreSQL functions
46 sudo -u vagrant psql -d openstreetmap -f db/functions/functions.sql
47 ################################################################################
48 # *IF* you want a vagrant image which supports replication (or perhaps you're
49 # using this script to provision some other server and want replication), then
50 # uncomment the following lines (until popd) and comment out the one above
51 # (functions.sql).
52 ################################################################################
53 #pushd db/functions
54 #sudo -u vagrant make
55 #sudo -u vagrant 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"
56 #popd
57
58
59 # set up sample configs
60 if [ ! -f config/database.yml ]; then
61     sudo -u vagrant cp config/example.database.yml config/database.yml
62 fi
63 touch config/settings.local.yml
64 # migrate the database to the latest version
65 sudo -u vagrant bundle exec rake db:migrate
66 popd