-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·121 lines (99 loc) · 3.62 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
#! /bin/bash
set -e
#######EDIT ACCORDING TO YOUR NEEDS or pass the values as arguments example:
# ./install.sh /path_to/qgis_project myurl.local false true false
# Ask for qgis projects dir - the one where your .qgs files are
QGISPROJECTSDIR=/var/www/html/GIAP-Wyrys/nowytarg/PROJEKTY
# The url where the web client will be available
QGISURL=mapy.uslugi.giap.pl/
# Allows using shorter urls like
# QGISURL/maps/mymap and QGISURL/wms/mymap
ENABLEURLREWRITE=true
#Puts the vhost file in /etc/apache2/sites-available/default
OVERRIDEDEFAULTVHOST=false
#calls apachectl restart
RESTARTAPACHE=true
AUTOACCEPT=${6-false}
###UNLIKELY YOU WILL NEED TO EDIT FROM HERE ON###
# parse the options
if [ $# -eq 0 ]; then
echo "Using default values."
echo "You can edit th script according to your needs or pass the values as arguments example:"
echo "./install.sh /path_to/qgis_project myurl.local false"
echo
fi
echo "#####Using following configuration:############"
echo "QGISPROJECTSDIR: $QGISPROJECTSDIR"
echo "QGISURL: $QGISURL"
echo "ENABLEURLREWRITE: $ENABLEURLREWRITE"
echo "OVERRIDEDEFAULTVHOST: $OVERRIDEDEFAULTVHOST"
echo "RESTARTAPACHE: $RESTARTAPACHE"
echo "###############################################"
echo
if [ "$AUTOACCEPT" = false ]; then
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y ) echo "Installing..."; AUTOACCEPTAPT='-y';;
* ) echo "User aborted"; exit 1;;
esac
else
AUTOACCEPTAPT=''
fi
#install the server
apt-get install $AUTOACCEPTAPT qgis-server apache2 libapache2-mod-fcgid libapache2-mod-php5 locate sed
a2enmod php5
a2enmod fcgid
#Get the QGIS web client root dir
ROOTDIR=$( cd "$( dirname "$0" )" && pwd )
# search qgis server installation usually in /usr/lib/cgi-bin
if hash /usr/lib/cgi-bin/qgis_mapserv.fcgi 2>/dev/null; then
QGISSERVERDIR=/usr/lib/cgi-bin
else
QGISSERVERDIR=`updatedb && dirname $(locate --limit 1 qgis_mapserv.fcgi)`
fi
#####STOP EDITING#####
#create apache config file
cd $ROOTDIR/apache-conf
cp qgis-web-client.conf.tmpl qgis-web-client.conf
sed -i "s|<qgis-web-client.localhost>|$QGISURL|g" qgis-web-client.conf
sed -i "s|<absolute-path-to-qgis-web-client>|$ROOTDIR|g" qgis-web-client.conf
sed -i "s|<absolute-path-to-qgis_mapserv.fcgi-folder>|$QGISSERVERDIR|g" qgis-web-client.conf
sed -i "s|<absolute-path-to-qgis-server-projects>|$QGISPROJECTSDIR|g" qgis-web-client.conf
#Autodetect the apache server major.minor version
# now is Apache/2.4
APACHEVERSION=$(echo `apachectl -v` | grep -E -o 'Apache/[[:digit:]].[[:digit:]]');
# now is x.x
APACHEVERSION=${APACHEVERSION:7:3}
echo "Detected apache $APACHEVERSION"
#We are in apache 2.4+ land
if [[ $APACHEVERSION > 2.3 ]]; then
sed -i "s|#<ENABLE_FOR_APACHE_2_4>||g" qgis-web-client.conf
fi
#Urlrewrite
if [ "$ENABLEURLREWRITE" = true ]; then
a2enmod rewrite
sed -i "s|#<REMOVE_TO_ENABLE_URL_REWRITE>||g" qgis-web-client.conf
cd $ROOTDIR/site/js
sed -i "s|var serverAndCGI = \"/cgi-bin/qgis_mapserv.fcgi\"|var serverAndCGI = \"/wms\"|g" GlobalOptions.js
fi
#fixup php config
cd $ROOTDIR/site
sed -i "s|<absolute-path-to-qgis-server-projects>|$QGISPROJECTSDIR|g" index.php
#install the configuration
if [ "$OVERRIDEDEFAULTVHOST" = true ]; then
ln -sf $ROOTDIR/apache-conf/qgis-web-client.conf /etc/apache2/sites-available/default
a2ensite default
else
ln -s $ROOTDIR/apache-conf/qgis-web-client.conf /etc/apache2/sites-available/
a2ensite qgis-web-client.conf
fi
if [ "$RESTARTAPACHE" = true ]; then
apachectl restart
fi
if [ "$OVERRIDEDEFAULTVHOST" = true ]; then
url='localhost'
else
echo 127.0.0.1 $QGISURL >> /etc/hosts
url=$QGISURL
fi
echo "Web client reachable at: " http://$url