]> git.openstreetmap.org Git - nominatim.git/blob - vagrant-provision.sh
remove commented-out lines
[nominatim.git] / vagrant-provision.sh
1 #!/bin/bash
2
3
4 ## During 'vagrant provision' this script runs as root and the current
5 ## directory is '/root'
6 USERNAME=vagrant
7
8 ### 
9 ### maybe create ubuntu user
10 ### 
11
12 # if [[ ! `id -u $USERNAME` ]]; then
13 #   useradd $USERNAME --create-home --shell /bin/bash
14 #   
15 #   # give sudo power
16 #   echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-$USERNAME-user
17 #   chmod 0440 /etc/sudoers.d/99-$USERNAME-user
18 #   service sudo restart
19 #   
20 #   # add basic .profile
21 #   cp -r .ssh .profile .bashrc /home/$USERNAME/
22 #   chown -R $USERNAME /home/$USERNAME/.*
23 #   chgrp -R $USERNAME /home/$USERNAME/.*
24 #   
25 #   # now ideally login as $USERNAME and continue
26 #   su $USERNAME -l
27 # fi
28
29
30 sudo apt-get update -qq
31 sudo apt-get upgrade -y
32 sudo apt-get install -y build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev \
33                         libtool automake libproj-dev libboost-dev  libboost-system-dev \
34                         libboost-filesystem-dev libboost-thread-dev libexpat-dev
35 sudo apt-get autoremove -y
36
37 # get arrow-keys working in terminal (e.g. editing in vi)
38 echo 'stty sane' >> ~/.bash_profile
39 echo 'export TERM=linux' >> ~/.bash_profile
40 source ~/.bash_profile
41
42
43 ###
44 ### PostgreSQL 9.3 + PostGIS 2.1
45 ###
46
47 sudo apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib-9.3 postgresql-server-dev-9.3 
48 # already included: proj-bin libgeos-dev
49
50 # make sure OS-authenticated users (e.g. $USERNAME) can access
51 sudo sed -i "s/ident/trust/" /etc/postgresql/9.3/main/pg_hba.conf
52 sudo sed -i "s/md5/trust/"   /etc/postgresql/9.3/main/pg_hba.conf
53 sudo sed -i "s/peer/trust/"  /etc/postgresql/9.3/main/pg_hba.conf
54 sudo /etc/init.d/postgresql restart
55
56 # creates the role
57 sudo -u postgres createuser -s $USERNAME
58
59
60
61 ###
62 ### PHP for frontend
63 ###
64 sudo apt-get install -y php5 php5-pgsql php-pear php-db
65
66
67 # get rid of some warning
68 # where is the ini file? 'php --ini'
69 echo "date.timezone = 'Etc/UTC'" | sudo tee /etc/php5/cli/conf.d/99-timezone.ini > /dev/null
70
71
72
73 ###
74 ### Nominatim
75 ###
76 sudo apt-get install -y libprotobuf-c0-dev protobuf-c-compiler \
77                         libgeos-c1 libgeos++-dev \
78                         lua5.2 liblua5.2-dev
79
80 # git clone --recursive https://github.com/twain47/Nominatim.git
81
82
83 # now ideally login as $USERNAME and continue
84 su $USERNAME -l
85 cd /home/vagrant/Nominatim
86
87 # cd ~/Nominatim
88 ./autogen.sh
89 ./configure
90 make
91 chmod +x ./
92 chmod +x ./module
93
94
95 LOCALSETTINGS_FILE='settings/local.php'
96 if [[ -e "$LOCALSETTINGS_FILE" ]]; then
97   echo "$LOCALSETTINGS_FILE already exist, writing to settings/local-vagrant.php instead."
98   LOCALSETTINGS_FILE='settings/local-vagrant.php'
99 fi
100
101 # IP=`curl -s http://bot.whatismyipaddress.com`
102 IP=localhost
103 echo "<?php
104    // General settings
105    @define('CONST_Database_DSN', 'pgsql://@/nominatim');
106    // Paths
107    @define('CONST_Postgresql_Version', '9.3');
108    @define('CONST_Postgis_Version', '2.1');
109    // Website settings
110    @define('CONST_Website_BaseURL', 'http://$IP:8089/nominatim/');
111 " > $LOCALSETTINGS_FILE
112
113
114
115
116
117
118
119 ###
120 ### Setup Apache/website
121 ###
122
123 sudo -u postgres createuser -SDR www-data
124
125 echo '
126 Listen 8089
127 <VirtualHost *:8089>
128     # DirectoryIndex index.html
129     # ErrorDocument 403 /index.html
130
131     DocumentRoot "/var/www/"
132  
133     <Directory "/var/www/nominatim/">
134       Options FollowSymLinks MultiViews
135       AddType text/html   .php     
136     </Directory>
137 </VirtualHost>
138 ' | sudo tee /etc/apache2/sites-enabled/nominatim.conf > /dev/null
139
140
141 sudo apache2ctl graceful
142
143
144 sudo mkdir -m 755 /var/www/nominatim
145 sudo chown $USERNAME /var/www/nominatim
146 ./utils/setup.php --threads 1 --create-website /var/www/nominatim
147
148
149 # if you get 'permission denied for relation word', then try
150 # GRANT usage ON SCHEMA public TO "www-data";
151 # GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
152
153 ##
154 ## Test suite (Python)
155 ## https://github.com/twain47/Nominatim/tree/master/tests
156 ##
157 sudo apt-get install -y python-dev python-pip python-Levenshtein python-shapely \
158                         python-psycopg2 tidy python-nose python-tidylib
159 sudo pip install lettuce==0.2.18 six==1.7 haversine
160
161 ## Test suite (PHP)
162 ## https://github.com/twain47/Nominatim/tree/master/tests-php
163 sudo apt-get install -y phpunit
164
165