forked from GeoNode/geonode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·234 lines (201 loc) · 6.53 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env bash
# GeoNode installer script
#
# using getopts
#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
while getopts 's:' OPTION
do
case $OPTION in
s)
stepflag=1
stepval="$OPTARG"
;;
?)
printf "Usage: %s: [-s value] configfile\n" $(basename $0) >&2
exit 2
;;
esac
done
shift $(($OPTIND - 1))
function setup_directories() {
mkdir -p $GEOSERVER_DATA_DIR
mkdir -p $GEONODE_WWW/static
mkdir -p $GEONODE_WWW/uploaded
mkdir -p $GEONODE_WWW/wsgi
mkdir -p $APACHE_SITES
mkdir -p $GEONODE_BIN
mkdir -p $GEONODE_ETC
mkdir -p $GEONODE_ETC/media
mkdir -p $GEONODE_ETC/templates
mkdir -p $GEONODE_SHARE
}
function reorganize_configuration() {
cp -rp $INSTALL_DIR/support/geonode.apache $APACHE_SITES/geonode.conf
cp -rp $INSTALL_DIR/support/geonode.wsgi $GEONODE_WWW/wsgi/
cp -rp $INSTALL_DIR/support/geonode.robots $GEONODE_WWW/robots.txt
cp -rp $INSTALL_DIR/support/geonode.binary $GEONODE_BIN/geonode
cp -rp $INSTALL_DIR/support/packages/*.* $GEONODE_SHARE
cp -rp $INSTALL_DIR/GeoNode*.zip $GEONODE_SHARE
cp -rp $INSTALL_DIR/support/geonode.updateip $GEONODE_BIN/geonode-updateip
cp -rp $INSTALL_DIR/support/geonode.admin $GEONODE_SHARE/admin.json
cp -rp $INSTALL_DIR/support/geonode.local_settings $GEONODE_ETC/local_settings.py
chmod +x $GEONODE_BIN/geonode
chmod +x $GEONODE_BIN/geonode-updateip
}
function preinstall() {
setup_directories
reorganize_configuration
}
function randpass() {
[ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
echo
}
function setup_postgres_once() {
su - postgres <<EOF
createdb -E UTF8 -l en_US.UTF8 -T template0 geonode
createdb -E UTF8 -l en_US.UTF8 -T template0 geonode_data
psql -d geonode_data -c 'CREATE EXTENSION postgis'
EOF
su - postgres -c "psql" <<EOF
CREATE ROLE geonode WITH LOGIN PASSWORD '$psqlpass' SUPERUSER INHERIT;
ALTER USER geonode WITH PASSWORD '$psqlpass';
EOF
}
function setup_postgres_every_time() {
true # nothing to do. when we setup DB migrations they'll probably go here.
}
function setup_django_once() {
sed -i "s/THE_SECRET_KEY/$secretkey/g" $GEONODE_ETC/local_settings.py
sed -i "s/THE_DATABASE_PASSWORD/$psqlpass/g" $GEONODE_ETC/local_settings.py
}
function setup_django_every_time() {
pip install pip==9.0.3 --quiet
pip install $GEONODE_SHARE/GeoNode-*.zip --no-dependencies --quiet
pip install $GEONODE_SHARE/jwcrypto-0.5.0-py2.py3-none-any.whl --no-dependencies --no-cache-dir --quiet
pip install $GEONODE_SHARE/xmltodict-0.10.2.tar.gz --no-dependencies --no-cache-dir --quiet
pip install $GEONODE_SHARE/lxml-3.6.2.tar.gz --no-dependencies --no-cache-dir --quiet
geonodedir=`python -c "import geonode;import os;print os.path.dirname(geonode.__file__)"`
ln -sf $GEONODE_ETC/local_settings.py $geonodedir/local_settings.py
# Set up logging symlink
mkdir -p $GEONODE_LOG
ln -sf /var/log/apache2/error.log $GEONODE_LOG/apache.log
export DJANGO_SETTINGS_MODULE=geonode.local_settings
# django-admin migrate account --settings=geonode.settings
geonode makemigrations --merge --verbosity 0
geonode makemigrations --verbosity 0
# geonode migrate auth --verbosity 0
# geonode migrate sites --verbosity 0
# geonode migrate people --verbosity 0
geonode migrate --verbosity 0
geonode loaddata $geonodedir/people/fixtures/sample_admin.json
geonode loaddata $geonodedir/base/fixtures/default_oauth_apps.json
geonode loaddata $geonodedir/base/fixtures/initial_data.json
geonode set_all_layers_alternate --verbosity 0
geonode collectstatic --noinput --verbosity 0
# Create an empty uploads dir
mkdir -p $GEONODE_WWW/uploaded
mkdir -p $GEONODE_WWW/uploaded/documents/
mkdir -p $GEONODE_WWW/uploaded/layers/
mkdir -p $GEONODE_WWW/uploaded/thumbs/
mkdir -p $GEONODE_WWW/uploaded/avatars/
mkdir -p $GEONODE_WWW/uploaded/people_group/
mkdir -p $GEONODE_WWW/uploaded/group/
# Apply the permissions to the newly created folders.
chown www-data -R $GEONODE_WWW
# Open up the permissions of the media folders so the python
# processes like updatelayers and collectstatic can write here
chmod 777 -R $GEONODE_WWW/uploaded
chmod 777 -R $GEONODE_WWW/static
}
function setup_apache_once() {
chown www-data -R $GEONODE_WWW
a2enmod proxy_http
sed -i '1d' $APACHE_SITES/geonode.conf
sed -i "1i WSGIDaemonProcess geonode user=www-data threads=15 processes=2" $APACHE_SITES/geonode.conf
$APACHE_SERVICE restart
sleep 15
$GEONODE_BIN/geonode-updateip -p localhost
$TOMCAT_SERVICE restart
sleep 30
}
function setup_apache_every_time() {
a2dissite 000-default
#FIXME: This could be removed if setup_apache_every_time is called after setup_apache_once
a2enmod proxy_http
a2ensite geonode
$APACHE_SERVICE restart
}
function one_time_setup() {
psqlpass=$(randpass 8 0)
secretkey=$(randpass 18 0)
setup_postgres_once
setup_django_once
# setup_apache_once # apache setup needs the every_time django setup since
# it uses that to get the sitedir location
}
function setup_geoserver() {
pushd ../
paver setup
popd
mv ../downloaded/geoserver.war $TOMCAT_WEBAPPS
$TOMCAT_SERVICE restart
}
function postinstall() {
setup_postgres_every_time
setup_django_every_time
setup_apache_every_time
}
function once() {
echo "Still need to implement the onetime setup."
exit 1
}
if [ $# -eq 1 ]
then
printf "Sourcing %s as the configuration file\n" $1
source $1
else
printf "Usage: %s: [-s value] configfile\n" $(basename $0) >&2
exit 2
fi
if [ "$stepflag" ]
then
printf "\tStep: '$stepval specified\n"
else
stepval="all"
echo "heh"
fi
case $stepval in
pre)
echo "Running GeoNode preinstall ..."
preinstall
;;
once)
echo "Running GeoNode initial configuration ..."
one_time_setup
;;
post)
echo "Running GeoNode postinstall ..."
postinstall
;;
setup_apache_once)
echo "Configuring Apache ..."
setup_apache_once
;;
all)
echo "Running GeoNode installation ..."
preinstall
one_time_setup
setup_geoserver
postinstall
setup_apache_once
;;
*)
printf "\tValid values for step parameter are: 'pre', 'post','all'\n"
printf "\tDefault value for step is 'all'\n"
;;
esac