1 |
#!/bin/sh
|
1 |
#!/bin/sh
|
2 |
|
2 |
|
3 |
#########################################################
|
3 |
#########################################################
|
4 |
#
|
4 |
#
|
5 |
# Installation script for SURFmap.
|
5 |
# Installation script for SURFmap.
|
6 |
#
|
6 |
#
|
7 |
# Copyright (C) 2013 INVEA-TECH a.s.
|
7 |
# Copyright (C) 2013 INVEA-TECH a.s.
|
8 |
# Author(s): Rick Hofstede <r.j.hofstede@utwente.nl>
|
8 |
# Author(s): Rick Hofstede <r.j.hofstede@utwente.nl>
|
9 |
# Pavel Celeda <celeda@invea-tech.com>
|
9 |
# Pavel Celeda <celeda@invea-tech.com>
|
10 |
#
|
10 |
#
|
11 |
# LICENSE TERMS - 3-clause BSD license
|
11 |
# LICENSE TERMS - 3-clause BSD license
|
12 |
#
|
12 |
#
|
13 |
# $Id: install.sh 626 2014-06-22 07:48:21Z rickhofstede $
|
13 |
# $Id: install.sh 626 2014-06-22 07:48:21Z rickhofstede $
|
14 |
#
|
14 |
#
|
15 |
#########################################################
|
15 |
#########################################################
|
16 |
|
16 |
|
17 |
SURFMAP_VER=3.3
|
17 |
SURFMAP_VER=3.3
|
18 |
SURFMAP_REL=SURFmap_v${SURFMAP_VER}.tar.gz
|
18 |
SURFMAP_REL=SURFmap_v${SURFMAP_VER}.tar.gz
|
19 |
TMP_DIR=SURFmap
|
19 |
TMP_DIR=SURFmap
|
20 |
GEO_DB=GeoLiteCity.dat.gz
|
20 |
GEO_DB=GeoLiteCity.dat.gz
|
21 |
GEOv6_DB=GeoLiteCityv6.dat.gz
|
21 |
GEOv6_DB=GeoLiteCityv6.dat.gz
|
22 |
|
22 |
|
23 |
err () {
|
23 |
err () {
|
24 |
printf "ERROR: ${*}\n"
|
24 |
printf "ERROR: ${*}\n"
|
25 |
exit 1
|
25 |
exit 1
|
26 |
}
|
26 |
}
|
27 |
|
27 |
|
28 |
err_line () {
|
28 |
err_line () {
|
29 |
echo "-----"
|
29 |
echo "-----"
|
30 |
printf "ERROR: ${*}\n"
|
30 |
printf "ERROR: ${*}\n"
|
31 |
exit 1
|
31 |
exit 1
|
32 |
}
|
32 |
}
|
33 |
|
33 |
|
34 |
FRONTEND_ONLY=0 # Install/update frontend only
|
34 |
FRONTEND_ONLY=0 # Install/update frontend only
|
35 |
BACKEND_ONLY=0 # Install/update backend only
|
35 |
BACKEND_ONLY=0 # Install/update backend only
|
36 |
NFSEN_CONF_OVERWRITE="" # Overwrite path to nfsen.conf (i.e., don't determine path automatically)
|
36 |
NFSEN_CONF_OVERWRITE="" # Overwrite path to nfsen.conf (i.e., don't determine path automatically)
|
37 |
|
37 |
|
38 |
# http://wiki.bash-hackers.org/howto/getopts_tutorial
|
38 |
# http://wiki.bash-hackers.org/howto/getopts_tutorial
|
39 |
while getopts ":fbn:" opt; do
|
39 |
while getopts ":fbn:" opt; do
|
40 |
case $opt in
|
40 |
case $opt in
|
41 |
f)
|
41 |
f)
|
42 |
FRONTEND_ONLY=1
|
42 |
FRONTEND_ONLY=1
|
43 |
;;
|
43 |
;;
|
44 |
b)
|
44 |
b)
|
45 |
BACKEND_ONLY=1
|
45 |
BACKEND_ONLY=1
|
46 |
;;
|
46 |
;;
|
47 |
n)
|
47 |
n)
|
48 |
NFSEN_CONF_OVERWRITE=$OPTARG
|
48 |
NFSEN_CONF_OVERWRITE=$OPTARG
|
49 |
;;
|
49 |
;;
|
50 |
\?)
|
50 |
\?)
|
51 |
err "Invalid option: -$OPTARG"
|
51 |
err "Invalid option: -$OPTARG"
|
52 |
exit 1
|
52 |
exit 1
|
53 |
;;
|
53 |
;;
|
54 |
:)
|
54 |
:)
|
55 |
err "Option -$OPTARG requires an argument. Exiting..."
|
55 |
err "Option -$OPTARG requires an argument. Exiting..."
|
56 |
exit 1
|
56 |
exit 1
|
57 |
;;
|
57 |
;;
|
58 |
esac
|
58 |
esac
|
59 |
done
|
59 |
done
|
60 |
|
60 |
|
61 |
if [ $FRONTEND_ONLY = 1 -a $BACKEND_ONLY = 1 ]; then
|
61 |
if [ $FRONTEND_ONLY = 1 -a $BACKEND_ONLY = 1 ]; then
|
62 |
err "You have specified two excluding options (-f and -b)."
|
62 |
err "You have specified two excluding options (-f and -b)."
|
63 |
fi
|
63 |
fi
|
64 |
|
64 |
|
65 |
# Determine (based on combination of input parameters) whether frontend has to be installed
|
65 |
# Determine (based on combination of input parameters) whether frontend has to be installed
|
66 |
if [ $FRONTEND_ONLY = 1 ] || [ $FRONTEND_ONLY = 0 -a $BACKEND_ONLY = 0 ]; then
|
66 |
if [ $FRONTEND_ONLY = 1 ] || [ $FRONTEND_ONLY = 0 -a $BACKEND_ONLY = 0 ]; then
|
67 |
INSTALL_FRONTEND=1
|
67 |
INSTALL_FRONTEND=1
|
68 |
else
|
68 |
else
|
69 |
INSTALL_FRONTEND=0
|
69 |
INSTALL_FRONTEND=0
|
70 |
fi
|
70 |
fi
|
71 |
|
71 |
|
72 |
# Determine (based on combination of input parameters) whether backend has to be installed
|
72 |
# Determine (based on combination of input parameters) whether backend has to be installed
|
73 |
if [ $BACKEND_ONLY = 1 ] || [ $FRONTEND_ONLY = 0 -a $BACKEND_ONLY = 0 ]; then
|
73 |
if [ $BACKEND_ONLY = 1 ] || [ $FRONTEND_ONLY = 0 -a $BACKEND_ONLY = 0 ]; then
|
74 |
INSTALL_BACKEND=1
|
74 |
INSTALL_BACKEND=1
|
75 |
else
|
75 |
else
|
76 |
INSTALL_BACKEND=0
|
76 |
INSTALL_BACKEND=0
|
77 |
fi
|
77 |
fi
|
78 |
|
78 |
|
79 |
echo "SURFmap installation script"
|
79 |
echo "SURFmap installation script"
|
80 |
echo "---------------------------"
|
80 |
echo "---------------------------"
|
81 |
|
81 |
|
82 |
# Discover NfSen configuration
|
82 |
# Discover NfSen configuration
|
83 |
NFSEN_VARFILE=/tmp/nfsen-tmp.conf
|
83 |
NFSEN_VARFILE=/tmp/nfsen-tmp.conf
|
84 |
if [ ! -n "$(ps axo command | grep [n]fsend | grep -v nfsend-comm)" ]; then
|
84 |
if [ ! -n "$(ps axo command | grep [n]fsend | grep -v nfsend-comm)" ]; then
|
85 |
err "NfSen - nfsend not running; cannot detect nfsen.conf location. Exiting..."
|
85 |
err "NfSen - nfsend not running; cannot detect nfsen.conf location. Exiting..."
|
86 |
fi
|
86 |
fi
|
87 |
|
87 |
|
88 |
NFSEN_LIBEXECDIR=$(cat $(ps axo command= | grep -vE "(nfsend-comm|grep)" | grep -Eo "[^ ]+nfsend") | grep libexec | cut -d'"' -f2 | head -n 1)
|
88 |
NFSEN_LIBEXECDIR=$(cat $(ps axo command= | grep -vE "(nfsend-comm|grep)" | grep -Eo "[^ ]+nfsend") | grep libexec | cut -d'"' -f2 | head -n 1)
|
89 |
|
89 |
|
90 |
if [ -z "${NFSEN_CONF_OVERWRITE}" ]; then
|
90 |
if [ -z "${NFSEN_CONF_OVERWRITE}" ]; then
|
91 |
NFSEN_CONF=$(cat ${NFSEN_LIBEXECDIR}/NfConf.pm | grep \/nfsen.conf | cut -d'"' -f2)
|
91 |
NFSEN_CONF=$(cat ${NFSEN_LIBEXECDIR}/NfConf.pm | grep \/nfsen.conf | cut -d'"' -f2)
|
92 |
else
|
92 |
else
|
93 |
NFSEN_CONF=$NFSEN_CONF_OVERWRITE
|
93 |
NFSEN_CONF=$NFSEN_CONF_OVERWRITE
|
94 |
fi
|
94 |
fi
|
95 |
|
95 |
|
96 |
# Parse nfsen.conf file
|
96 |
# Parse nfsen.conf file
|
97 |
cat ${NFSEN_CONF} | grep -v \# | egrep '\$BASEDIR|\$BINDIR|\$LIBEXECDIR|\$HTMLDIR|\$FRONTEND_PLUGINDIR|\$BACKEND_PLUGINDIR|\$WWWGROUP|\$WWWUSER|\$USER' | tr -d ';' | tr -d ' ' | cut -c2- | sed 's,/",",g' > ${NFSEN_VARFILE}
|
97 |
cat ${NFSEN_CONF} | grep -v \# | egrep '\$BASEDIR|\$BINDIR|\$LIBEXECDIR|\$HTMLDIR|\$FRONTEND_PLUGINDIR|\$BACKEND_PLUGINDIR|\$WWWGROUP|\$WWWUSER|\$USER' | tr -d ';' | tr -d ' ' | cut -c2- | sed 's,/",",g' > ${NFSEN_VARFILE}
|
98 |
. ${NFSEN_VARFILE}
|
98 |
. ${NFSEN_VARFILE}
|
99 |
rm -rf ${NFSEN_VARFILE}
|
99 |
rm -rf ${NFSEN_VARFILE}
|
100 |
|
100 |
|
101 |
SURFMAP_CONF=${FRONTEND_PLUGINDIR}/SURFmap/config.php
|
101 |
SURFMAP_CONF=${FRONTEND_PLUGINDIR}/SURFmap/config.php
|
102 |
|
102 |
|
103 |
# Check permissions to install SURFmap - you must be ${USER} or root
|
103 |
# Check permissions to install SURFmap - you must be ${USER} or root
|
104 |
if [ "$(id -u)" != "$(id -u ${USER})" ] && [ "$(id -u)" != "0" ]; then
|
104 |
if [ "$(id -u)" != "$(id -u ${USER})" ] && [ "$(id -u)" != "0" ]; then
|
105 |
err "You do not have sufficient permissions to install SURFmap on this machine!"
|
105 |
err "You do not have sufficient permissions to install SURFmap on this machine!"
|
106 |
fi
|
106 |
fi
|
107 |
|
107 |
|
108 |
if [ "$(id -u)" = "$(id -u ${USER})" ]; then
|
108 |
if [ "$(id -u)" = "$(id -u ${USER})" ]; then
|
109 |
WWWUSER=${USER} # we are installing as normal user
|
109 |
WWWUSER=${USER} # we are installing as normal user
|
110 |
fi
|
110 |
fi
|
111 |
|
111 |
|
112 |
# Download files from Web
|
112 |
# Download files from Web
|
113 |
if [ $(uname) = "FreeBSD" -o $(uname) = "OpenBSD" ]; then
|
113 |
if [ $(uname) = "FreeBSD" -o $(uname) = "OpenBSD" ]; then
|
114 |
RETRIEVE_TOOL="fetch"
|
114 |
RETRIEVE_TOOL="fetch"
|
115 |
else
|
115 |
else
|
116 |
RETRIEVE_TOOL="wget"
|
116 |
RETRIEVE_TOOL="wget"
|
117 |
fi
|
117 |
fi
|
118 |
|
118 |
|
119 |
|
119 |
|
120 |
# Move one directory-level up, if necessary, to be consistent with the case in which the tar-ball is unpacked (else-clause)
|
120 |
# Move one directory-level up, if necessary, to be consistent with the case in which the tar-ball is unpacked (else-clause)
|
121 |
if [ -f install.sh ]; then
|
121 |
if [ -f install.sh ]; then
|
122 |
cd ..
|
122 |
cd ..
|
123 |
fi
|
123 |
fi
|
124 |
|
124 |
|
125 |
# Check PHP dependencies
|
125 |
# Check PHP dependencies
|
126 |
PHP_JSON=$(php -m | grep 'json' 2> /dev/null)
|
126 |
PHP_JSON=$(php -m | grep 'json' 2> /dev/null)
|
127 |
PHP_MBSTRING=$(php -m 2> /dev/null | grep 'mbstring')
|
127 |
PHP_MBSTRING=$(php -m 2> /dev/null | grep 'mbstring')
|
128 |
PHP_PDOSQLITE=$(php -m 2> /dev/null | grep 'pdo_sqlite$') # The dollar-sign ($) makes sure that 'pdo_sqlite2' is not accepted
|
128 |
PHP_PDOSQLITE=$(php -m 2> /dev/null | grep 'pdo_sqlite$') # The dollar-sign ($) makes sure that 'pdo_sqlite2' is not accepted
|
129 |
PHP_SOCKETS=$(php -m 2> /dev/null | grep '^sockets$')
|
129 |
PHP_SOCKETS=$(php -m 2> /dev/null | grep '^sockets$')
|
130 |
PHP_XML=$(php -m 2> /dev/null | grep '^xml$')
|
130 |
PHP_XML=$(php -m 2> /dev/null | grep '^xml$')
|
131 |
|
131 |
|
132 |
if [ "$PHP_JSON" != "json" ]; then
|
132 |
if [ "$PHP_JSON" != "json" ]; then
|
133 |
err "The PHP 'JSON' module is missing.\nDon't forget to restart your Web server after installing the package."
|
133 |
err "The PHP 'JSON' module is missing.\nDon't forget to restart your Web server after installing the package."
|
134 |
elif [ "$PHP_MBSTRING" != "mbstring" ]; then
|
134 |
elif [ "$PHP_MBSTRING" != "mbstring" ]; then
|
135 |
err "The PHP 'mbstring' module is missing.\nDon't forget to restart your Web server after installing the package."
|
135 |
err "The PHP 'mbstring' module is missing.\nDon't forget to restart your Web server after installing the package."
|
136 |
elif [ "$PHP_PDOSQLITE" != "pdo_sqlite" ]; then
|
136 |
elif [ "$PHP_PDOSQLITE" != "pdo_sqlite" ]; then
|
137 |
err "The PHP PDO SQLite v3 module is missing.\nDon't forget to restart your Web server after installing the package."
|
137 |
err "The PHP PDO SQLite v3 module is missing.\nDon't forget to restart your Web server after installing the package."
|
138 |
elif [ "$PHP_SOCKETS" != "sockets" ]; then
|
138 |
elif [ "$PHP_SOCKETS" != "sockets" ]; then
|
139 |
err "The PHP 'sockets' module is missing.\nDon't forget to restart your Web server after installing the package."
|
139 |
err "The PHP 'sockets' module is missing.\nDon't forget to restart your Web server after installing the package."
|
140 |
elif [ "$PHP_XML" != "xml" ]; then
|
140 |
elif [ "$PHP_XML" != "xml" ]; then
|
141 |
err "The PHP 'xml' module is missing.\nDon't forget to restart your Web server after installing the package."
|
141 |
err "The PHP 'xml' module is missing.\nDon't forget to restart your Web server after installing the package."
|
142 |
fi
|
142 |
fi
|
143 |
###################################################################################################
|
143 |
###################################################################################################
|
144 |
# Backup old SURFmap installation
|
144 |
# Backup old SURFmap installation
|
145 |
SURFMAP_BACKUPDIR_FRONTEND=${FRONTEND_PLUGINDIR}/SURFmap-$(date +%s)
|
145 |
SURFMAP_BACKUPDIR_FRONTEND=${FRONTEND_PLUGINDIR}/SURFmap-$(date +%s)
|
146 |
SURFMAP_BACKUPDIR_BACKEND=${BACKEND_PLUGINDIR}/SURFmap-$(date +%s)
|
146 |
SURFMAP_BACKUPDIR_BACKEND=${BACKEND_PLUGINDIR}/SURFmap-$(date +%s)
|
147 |
if [ $INSTALL_FRONTEND = 1 -a -d ${FRONTEND_PLUGINDIR}/SURFmap ]; then
|
147 |
if [ $INSTALL_FRONTEND = 1 -a -d ${FRONTEND_PLUGINDIR}/SURFmap ]; then
|
148 |
echo "Backing up existing SURFmap (frontend) installation to ${SURFMAP_BACKUPDIR_FRONTEND}"
|
148 |
echo "Backing up existing SURFmap (frontend) installation to ${SURFMAP_BACKUPDIR_FRONTEND}"
|
149 |
mv ${FRONTEND_PLUGINDIR}/SURFmap ${SURFMAP_BACKUPDIR_FRONTEND}
|
149 |
mv ${FRONTEND_PLUGINDIR}/SURFmap ${SURFMAP_BACKUPDIR_FRONTEND}
|
150 |
fi
|
150 |
fi
|
151 |
if [ $INSTALL_BACKEND = 1 -a -d ${BACKEND_PLUGINDIR}/SURFmap ]; then
|
151 |
if [ $INSTALL_BACKEND = 1 -a -d ${BACKEND_PLUGINDIR}/SURFmap ]; then
|
152 |
echo "Backing up existing SURFmap (backend) installation to ${SURFMAP_BACKUPDIR_BACKEND}"
|
152 |
echo "Backing up existing SURFmap (backend) installation to ${SURFMAP_BACKUPDIR_BACKEND}"
|
153 |
mv ${BACKEND_PLUGINDIR}/SURFmap ${SURFMAP_BACKUPDIR_BACKEND}
|
153 |
mv ${BACKEND_PLUGINDIR}/SURFmap ${SURFMAP_BACKUPDIR_BACKEND}
|
154 |
fi
|
154 |
fi
|
155 |
|
155 |
|
156 |
# Install backend and frontend plugin files
|
156 |
# Install backend and frontend plugin files
|
157 |
echo "Installing SURFmap ${SURFMAP_VER} to ${FRONTEND_PLUGINDIR}/SURFmap"
|
157 |
echo "Installing SURFmap ${SURFMAP_VER} to ${FRONTEND_PLUGINDIR}/SURFmap"
|
158 |
if [ $INSTALL_FRONTEND = 1 ]; then
|
158 |
if [ $INSTALL_FRONTEND = 1 ]; then
|
159 |
cp -r ./${TMP_DIR}/frontend/* ${FRONTEND_PLUGINDIR}
|
159 |
cp -r ./${TMP_DIR}/frontend/* ${FRONTEND_PLUGINDIR}
|
160 |
fi
|
160 |
fi
|
161 |
if [ $INSTALL_BACKEND = 1 ]; then
|
161 |
if [ $INSTALL_BACKEND = 1 ]; then
|
162 |
cp -r ./${TMP_DIR}/backend/* ${BACKEND_PLUGINDIR}
|
162 |
cp -r ./${TMP_DIR}/backend/* ${BACKEND_PLUGINDIR}
|
163 |
fi
|
163 |
fi
|
164 |
##################################################################################################################################################
|
164 |
##################################################################################################################################################
|
165 |
# Deleting temporary files
|
165 |
# Deleting temporary files
|
166 |
# rm -rf ${TMP_DIR}
|
166 |
# rm -rf ${TMP_DIR}
|
167 |
rm -rf ${GEO_DB}
|
167 |
# rm -rf ${GEO_DB}
|
168 |
rm -rf ${GEOv6_DB}
|
168 |
# rm -rf ${GEOv6_DB}
|
169 |
|
169 |
|
170 |
# Check whether an old SURFmap version was found and ask whether frontend configuration and data structures should be retained
|
170 |
# Check whether an old SURFmap version was found and ask whether frontend configuration and data structures should be retained
|
171 |
if [ $INSTALL_FRONTEND = 1 -a -d ${SURFMAP_BACKUPDIR_FRONTEND} ]; then
|
171 |
if [ $INSTALL_FRONTEND = 1 -a -d ${SURFMAP_BACKUPDIR_FRONTEND} ]; then
|
172 |
OLD_VER=$(cat ${SURFMAP_BACKUPDIR_FRONTEND}/version.php | grep -m1 \$version | awk '{print $3}' | cut -d"\"" -f2)
|
172 |
OLD_VER=$(cat ${SURFMAP_BACKUPDIR_FRONTEND}/version.php | grep -m1 \$version | awk '{print $3}' | cut -d"\"" -f2)
|
173 |
if [ ${OLD_VER} = ${SURFMAP_VER} ]; then
|
173 |
if [ ${OLD_VER} = ${SURFMAP_VER} ]; then
|
174 |
while true; do
|
174 |
while true; do
|
175 |
read -p "Do you wish to keep the frontend configuration and data structures from your previous installation [y,n] (default: y)? " input
|
175 |
read -p "Do you wish to keep the frontend configuration and data structures from your previous installation [y,n] (default: y)? " input
|
176 |
case $input in
|
176 |
case $input in
|
177 |
[Nn]* ) break;;
|
177 |
[Nn]* ) break;;
|
178 |
* ) echo "Copying backend configuration and data structures from previous installation..."
|
178 |
* ) echo "Copying backend configuration and data structures from previous installation..."
|
179 |
cp ${SURFMAP_BACKUPDIR_FRONTEND}/config.php ${FRONTEND_PLUGINDIR}/SURFmap/;
|
179 |
cp ${SURFMAP_BACKUPDIR_FRONTEND}/config.php ${FRONTEND_PLUGINDIR}/SURFmap/;
|
180 |
cp ${SURFMAP_BACKUPDIR_FRONTEND}/db/* ${FRONTEND_PLUGINDIR}/SURFmap/db/;
|
180 |
cp ${SURFMAP_BACKUPDIR_FRONTEND}/db/* ${FRONTEND_PLUGINDIR}/SURFmap/db/;
|
181 |
break;;
|
181 |
break;;
|
182 |
esac
|
182 |
esac
|
183 |
done
|
183 |
done
|
184 |
fi
|
184 |
fi
|
185 |
fi
|
185 |
fi
|
186 |
|
186 |
|
187 |
# Set permissions - owner and group
|
187 |
# Set permissions - owner and group
|
188 |
echo "Setting plugin file permissions - user \"${USER}\" and group \"${WWWGROUP}\""
|
188 |
echo "Setting plugin file permissions - user \"${USER}\" and group \"${WWWGROUP}\""
|
189 |
if [ $INSTALL_FRONTEND = 1 ]; then
|
189 |
if [ $INSTALL_FRONTEND = 1 ]; then
|
190 |
chown -R ${USER}:${WWWGROUP} ${FRONTEND_PLUGINDIR}/SURFmap*
|
190 |
chown -R ${USER}:${WWWGROUP} ${FRONTEND_PLUGINDIR}/SURFmap*
|
191 |
chmod -R g+w ${FRONTEND_PLUGINDIR}/SURFmap/db
|
191 |
chmod -R g+w ${FRONTEND_PLUGINDIR}/SURFmap/db
|
192 |
fi
|
192 |
fi
|
193 |
if [ $INSTALL_BACKEND = 1 ]; then
|
193 |
if [ $INSTALL_BACKEND = 1 ]; then
|
194 |
chown -R ${USER}:${WWWGROUP} ${BACKEND_PLUGINDIR}/SURFmap*
|
194 |
chown -R ${USER}:${WWWGROUP} ${BACKEND_PLUGINDIR}/SURFmap*
|
195 |
fi
|
195 |
fi
|
196 |
|
196 |
|
197 |
# Update plugin configuration file - config.php. We use ',' as sed delimiter instead of escaping all '/' to '\/'.
|
197 |
# Update plugin configuration file - config.php. We use ',' as sed delimiter instead of escaping all '/' to '\/'.
|
198 |
echo "Updating plugin configuration file ${SURFMAP_CONF}"
|
198 |
echo "Updating plugin configuration file ${SURFMAP_CONF}"
|
199 |
|
199 |
|
200 |
# Check for proxy and update config.php accordingly
|
200 |
# Check for proxy and update config.php accordingly
|
201 |
PROXY=$(env | grep -i http_proxy | awk '{ START=index($0,"=")+1; print substr($0,START) }')
|
201 |
PROXY=$(env | grep -i http_proxy | awk '{ START=index($0,"=")+1; print substr($0,START) }')
|
202 |
if [ "$PROXY" != "" ]; then
|
202 |
if [ "$PROXY" != "" ]; then
|
203 |
echo "HTTP proxy detected"
|
203 |
echo "HTTP proxy detected"
|
204 |
sed -i.tmp "s,config\['use_proxy'\] = 0,config\['use_proxy'\] = 1,g" ${SURFMAP_CONF}
|
204 |
sed -i.tmp "s,config\['use_proxy'\] = 0,config\['use_proxy'\] = 1,g" ${SURFMAP_CONF}
|
205 |
|
205 |
|
206 |
PROXY_IP_PORT=$(echo ${PROXY} | awk '{ FROM=index($0,"//")+2; print substr($0,FROM) }')
|
206 |
PROXY_IP_PORT=$(echo ${PROXY} | awk '{ FROM=index($0,"//")+2; print substr($0,FROM) }')
|
207 |
PROXY_IP=$(echo ${PROXY_IP_PORT} | awk '{ TO=index($0,":")-1; print substr($0,0,TO) }')
|
207 |
PROXY_IP=$(echo ${PROXY_IP_PORT} | awk '{ TO=index($0,":")-1; print substr($0,0,TO) }')
|
208 |
PROXY_PORT=$(echo ${PROXY_IP_PORT} | awk '{ FROM=index($0,":")+1; print substr($0,FROM) }')
|
208 |
PROXY_PORT=$(echo ${PROXY_IP_PORT} | awk '{ FROM=index($0,":")+1; print substr($0,FROM) }')
|
209 |
|
209 |
|
210 |
OLD_PROXY_IP=$(grep "$config\['proxy_ip'\]" ${SURFMAP_CONF} | cut -d'"' -f2)
|
210 |
OLD_PROXY_IP=$(grep "$config\['proxy_ip'\]" ${SURFMAP_CONF} | cut -d'"' -f2)
|
211 |
OLD_PROXY_PORT=$(grep "$config\['proxy_port'\]" ${SURFMAP_CONF} | awk '{ FROM=index($0,"=")+2; TO=index($0,";"); print substr($0,FROM,TO-FROM) }')
|
211 |
OLD_PROXY_PORT=$(grep "$config\['proxy_port'\]" ${SURFMAP_CONF} | awk '{ FROM=index($0,"=")+2; TO=index($0,";"); print substr($0,FROM,TO-FROM) }')
|
212 |
|
212 |
|
213 |
sed -i.tmp "s,${OLD_PROXY_IP},${PROXY_IP},g" ${SURFMAP_CONF}
|
213 |
sed -i.tmp "s,${OLD_PROXY_IP},${PROXY_IP},g" ${SURFMAP_CONF}
|
214 |
sed -i.tmp "s,${OLD_PROXY_PORT},${PROXY_PORT},g" ${SURFMAP_CONF}
|
214 |
sed -i.tmp "s,${OLD_PROXY_PORT},${PROXY_PORT},g" ${SURFMAP_CONF}
|
215 |
fi
|
215 |
fi
|
216 |
|
216 |
|
217 |
# Get my location information
|
217 |
# Get my location information
|
218 |
cd ${FRONTEND_PLUGINDIR}/SURFmap/setup
|
218 |
cd ${FRONTEND_PLUGINDIR}/SURFmap/setup
|
219 |
MY_LOC=$(php retrievelocation.php | grep config_data | cut -d'>' -f2 | cut -d'<' -f1)
|
219 |
MY_LOC=$(php retrievelocation.php | grep config_data | cut -d'>' -f2 | cut -d'<' -f1)
|
220 |
echo "Geocoding plugin location - ${MY_LOC}"
|
220 |
echo "Geocoding plugin location - ${MY_LOC}"
|
221 |
|
221 |
|
222 |
cd - > /dev/null
|
222 |
cd - > /dev/null
|
223 |
|
223 |
|
224 |
# Fill my location in plugin configuration file
|
224 |
# Fill my location in plugin configuration file
|
225 |
if [ "${MY_LOC}" != "(UNKNOWN),(UNKNOWN),(UNKNOWN),(UNKNOWN),(UNKNOWN)" ]; then
|
225 |
if [ "${MY_LOC}" != "(UNKNOWN),(UNKNOWN),(UNKNOWN),(UNKNOWN),(UNKNOWN)" ]; then
|
226 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 6)
|
226 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 6)
|
227 |
sed -i.tmp "s/${OLDENTRY}/$(echo ${MY_LOC} | cut -d',' -f1)/g" ${SURFMAP_CONF}
|
227 |
sed -i.tmp "s/${OLDENTRY}/$(echo ${MY_LOC} | cut -d',' -f1)/g" ${SURFMAP_CONF}
|
228 |
|
228 |
|
229 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 10)
|
229 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 10)
|
230 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f2)
|
230 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f2)
|
231 |
if [ "${NEWENTRY}" = "(UNKNOWN)" ]; then
|
231 |
if [ "${NEWENTRY}" = "(UNKNOWN)" ]; then
|
232 |
NEWENTRY=""
|
232 |
NEWENTRY=""
|
233 |
fi
|
233 |
fi
|
234 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
234 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
235 |
|
235 |
|
236 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 14)
|
236 |
OLDENTRY=$(grep internal_domains ${SURFMAP_CONF} | cut -d'"' -f 14)
|
237 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f3)
|
237 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f3)
|
238 |
if [ "${NEWENTRY}" = "(UNKNOWN)" ]; then
|
238 |
if [ "${NEWENTRY}" = "(UNKNOWN)" ]; then
|
239 |
NEWENTRY=""
|
239 |
NEWENTRY=""
|
240 |
fi
|
240 |
fi
|
241 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
241 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
242 |
|
242 |
|
243 |
OLDENTRY=$(grep "$config\['map_center'\]" ${SURFMAP_CONF} | cut -d'"' -f2)
|
243 |
OLDENTRY=$(grep "$config\['map_center'\]" ${SURFMAP_CONF} | cut -d'"' -f2)
|
244 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f4,5)
|
244 |
NEWENTRY=$(echo ${MY_LOC} | cut -d',' -f4,5)
|
245 |
if [ "${NEWENTRY}" != "(UNKNOWN),(UNKNOWN)" ]; then
|
245 |
if [ "${NEWENTRY}" != "(UNKNOWN),(UNKNOWN)" ]; then
|
246 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
246 |
sed -i.tmp "s/${OLDENTRY}/${NEWENTRY}/g" ${SURFMAP_CONF}
|
247 |
fi
|
247 |
fi
|
248 |
fi
|
248 |
fi
|
249 |
|
249 |
|
250 |
# Enable plugin
|
250 |
# Enable plugin
|
251 |
OLDENTRY=$(grep \@plugins ${NFSEN_CONF})
|
251 |
OLDENTRY=$(grep \@plugins ${NFSEN_CONF})
|
252 |
|
252 |
|
253 |
if grep "SURFmap" ${NFSEN_CONF} > /dev/null; then
|
253 |
if grep "SURFmap" ${NFSEN_CONF} > /dev/null; then
|
254 |
echo "Found 'SURFmap' in ${NFSEN_CONF}; assuming it is already configured"
|
254 |
echo "Found 'SURFmap' in ${NFSEN_CONF}; assuming it is already configured"
|
255 |
else
|
255 |
else
|
256 |
echo "Updating NfSen configuration file ${NFSEN_CONF}"
|
256 |
echo "Updating NfSen configuration file ${NFSEN_CONF}"
|
257 |
|
257 |
|
258 |
# Check whether we are running Linux of BSD (BSD sed does not support inserting new lines (\n))
|
258 |
# Check whether we are running Linux of BSD (BSD sed does not support inserting new lines (\n))
|
259 |
if [ $(uname) = "Linux" ]; then
|
259 |
if [ $(uname) = "Linux" ]; then
|
260 |
sed -i.tmp "/SURFmap/d" ${NFSEN_CONF}
|
260 |
sed -i.tmp "/SURFmap/d" ${NFSEN_CONF}
|
261 |
sed -i.tmp "s/${OLDENTRY}/${OLDENTRY}\n \[ 'live', 'SURFmap' ],/g" ${NFSEN_CONF}
|
261 |
sed -i.tmp "s/${OLDENTRY}/${OLDENTRY}\n \[ 'live', 'SURFmap' ],/g" ${NFSEN_CONF}
|
262 |
else # Something else (we assume *BSD)
|
262 |
else # Something else (we assume *BSD)
|
263 |
sed -i.tmp "s/${OLDENTRY}/${OLDENTRY}\ \[ 'live', 'SURFmap' ],/g" ${NFSEN_CONF}
|
263 |
sed -i.tmp "s/${OLDENTRY}/${OLDENTRY}\ \[ 'live', 'SURFmap' ],/g" ${NFSEN_CONF}
|
264 |
fi
|
264 |
fi
|
265 |
fi
|
265 |
fi
|
266 |
|
266 |
|
267 |
# Check whether an old SURFmap version was found and ask whether the backup of that version should be removed
|
267 |
# Check whether an old SURFmap version was found and ask whether the backup of that version should be removed
|
268 |
if [ -d ${SURFMAP_BACKUPDIR_FRONTEND} -a -d ${SURFMAP_BACKUPDIR_BACKEND} ]; then
|
268 |
if [ -d ${SURFMAP_BACKUPDIR_FRONTEND} -a -d ${SURFMAP_BACKUPDIR_BACKEND} ]; then
|
269 |
while true; do
|
269 |
while true; do
|
270 |
read -p "Do you wish to remove the backup of your previous SURFmap installation [y,n] (default: n)? " input
|
270 |
read -p "Do you wish to remove the backup of your previous SURFmap installation [y,n] (default: n)? " input
|
271 |
case $input in
|
271 |
case $input in
|
272 |
[Yy]* ) echo "Removing backup of previous installation..."
|
272 |
[Yy]* ) echo "Removing backup of previous installation..."
|
273 |
rm -rf ${SURFMAP_BACKUPDIR_FRONTEND} ${SURFMAP_BACKUPDIR_BACKEND};
|
273 |
rm -rf ${SURFMAP_BACKUPDIR_FRONTEND} ${SURFMAP_BACKUPDIR_BACKEND};
|
274 |
break;;
|
274 |
break;;
|
275 |
* ) break;;
|
275 |
* ) break;;
|
276 |
esac
|
276 |
esac
|
277 |
done
|
277 |
done
|
278 |
fi
|
278 |
fi
|
279 |
|
279 |
|
280 |
echo "-----"
|
280 |
echo "-----"
|
281 |
echo "Please restart/reload NfSen to finish installation (e.g., sudo ${BINDIR}/nfsen reload)"
|
281 |
echo "Please restart/reload NfSen to finish installation (e.g., sudo ${BINDIR}/nfsen reload)"
|
282 |
|
282 |
|
283 |
|
283 |
|
284 |
Generated by GNU Enscript 1.6.6.
|
284 |
Generated by GNU Enscript 1.6.6.
|
285 |
|
285 |
|
286 |
|
286 |
|
287 |
|
287 |
|