root/tags/module-PHP-WeatherMap-1.2.2/install

Revision 3156, 8.6 kB (checked in by wlienard, 16 months ago)

bug fix : web_group

  • Property svn:executable set to *
Line 
1#!/bin/sh
2###################################################################
3# Oreon is developped with GPL Licence 2.0
4#
5# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
6#
7# Developped by : Julien Mathis - Romain Le Merlus
8#                 Christophe Coraboeuf - Mathieu Chateau
9#
10###################################################################
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License for more details.
20#
21#    For information : infos@oreon-project.org
22####################################################################
23##################################
24# Must be Set for each verion
25VERSION=1.2.2
26##################################
27
28if [ -z "$BASH" ]; then # Test if BASH is in path
29    if ! which bash > /dev/null 2>&1; then
30        echo "Install bash and try `bash install.sh`."
31    fi # Exit if we are not in BASH
32    echo "Error: The script must be run with BASH shell. Try:"
33    echo "# bash install.sh"
34    exit 1
35fi
36
37#Check_dialog_version
38dial_vers=`whereis dialog | cut -d ':' -f2`
39if [ -z "$dial_vers" ] ; then
40        echo "Dialog not found install dialog version 1.0 or latest before Centreon installation"
41        exit 1
42else
43        dial_vers=`dialog --version 2>&1 | cut -d ':' -f2 | cut -d ' ' -f2 | cut -d '.' -f1`
44        if [ $dial_vers -lt 1 ] ; then
45                echo "Dialog less than 1.0, please install the latest version of Dialog before Centreon installation"
46                exit 1
47        fi
48fi
49
50#Check_root_permissions
51ID="id -u"
52MYUID=`$ID 2> /dev/null`
53
54if [ -z "$MYUID" ]; then
55    MYUID=`/usr/xpg4/bin/$ID 2> /dev/null`;
56fi
57
58if [ ! -z "$MYUID" ]; then
59    if [ $MYUID != 0 ]; then
60        echo "You need root privileges to run this script!";
61        exit 1;
62    fi
63fi
64
65##
66##      Function
67##
68
69        . functions_dialog
70
71##
72##      Var
73##
74
75MODULE="PHP-WeatherMap".$VERSION
76LOG_VERSION="Centreon Module $MODULE installation"
77BACKTITLE="Centreon Module $MODULE installation"
78TITLE="\Z4\ZbCentreon Module $MODULE installation\Zn"
79DIALOG='dialog --colors'
80QUITMSG="\n\Z1\ZbDo you really want to quit ?\Zn"
81TEMP=/tmp/install.$$
82PWD=`pwd`
83LOG_FILE="$PWD/install_oreon.log"
84OREON_CONF="/etc/oreon.conf"
85SEARCH_CONF_A=0
86
87# catch "SIGINT" signal (ctrl-c) and execut function "quit"
88trap "quit" 2
89
90#First message of centreon installation
91function Welcome() {
92        # Welcome
93                dialog_msgbox "\nWelcome to Centreon module Installation!\
94                \nFor more information reagarding this procedure, please see the Centreon module Installation Guide."
95       
96        if [ $temp != 0 ]; then
97            quit
98        fi
99        Old_oreon_conf
100}
101
102#test if old configuration exist and ask user if he want use it
103function Old_oreon_conf() {
104        # old Oreon conf
105        if test -a $OREON_CONF ; then
106                SEARCH_CONF_A=1
107                . $OREON_CONF
108        fi
109        Centreon_path
110}
111
112function Centreon_path() {
113        # Configuration Centreon path
114       
115        err=1
116        ERROR_MSG=""
117        while [ $err != 0 ]
118        do
119                #setup directory for centreon
120                if [ -z $INSTALL_DIR_OREON ] ; then
121                        dialog_input2 "$ERROR_MSG\nPlease specify the location of Oreon/centreon install:" "/usr/local/oreon"
122                else
123                        dialog_input2 "$ERROR_MSG\nPlease specify the location of Oreon/centreon install:" "$INSTALL_DIR_OREON"
124                fi
125                case $temp in
126                1)#Cancel
127                        test_quit "\n$QUITMSG"
128                        ;;
129                0)#yes
130                        INSTALL_DIR_OREON=`cat $TEMP`
131                        if [ -n "$INSTALL_DIR_OREON" ] ; then
132                                if [ -d $INSTALL_DIR_OREON ] ; then
133                                        err=0
134                                fi
135                                ERROR_MSG="\nThe directory does not exist!"
136                        else
137                                ERROR_MSG="\nThe path can't be null!"
138                        fi
139                        ;;
140                *)
141                        quit
142                        ;;
143                esac
144        done
145       
146        get_web_group
147}
148
149#ask user to specify the Apache group. Test if information are correct.
150function get_web_group() {
151        ERROR_MSG=""
152    err=1
153    while [ $err != 0 ]
154      do
155      dialog_input "$ERROR_MSG\nPlease specify the Apache group:\n" "$WEB_GROUP"
156      case $temp in
157          3)#Cancel
158             test_quit "\n$QUITMSG"
159             ;;
160           1)#Previous
161             Centreon_path
162             prev_funct
163             ;;
164           0)#yes
165             WEB_GROUP=`cat $TEMP`
166             if [ -n "$WEB_GROUP" ] ; then
167                        web_group_grep=`grep $WEB_GROUP /etc/passwd >> /dev/null 2>> $LOG_FILE; echo $?`
168                        if [ $web_group_grep == 0 ]; then
169                        err=0
170                    else
171                        ERROR_MSG="\nThe Apache group does not exist!"
172                        fi
173                 else
174                        ERROR_MSG="\nThe Apache group can't be null!"
175             fi
176             ;;
177           *)
178             quit
179             ;;
180      esac
181    done
182    get_web_user
183}
184
185#ask user to specify the Apache user. Test if information are correct.
186function get_web_user() {
187        ERROR_MSG=""
188        err=1
189    while [ $err != 0 ]
190    do
191      dialog_input "$ERROR_MSG\nPlease specify the Apache user:\n" "$WEB_USER"
192      case $temp in
193          3)#Cancel
194             test_quit "\n$QUITMSG"
195             ;;
196          1)#Previous
197             get_web_group
198             prev_funct
199             ;;
200          0)#yes
201             WEB_USER=`cat $TEMP`
202             if [ -n "$WEB_USER" ] ; then
203                        web_user_grep=`grep $WEB_USER /etc/passwd > /dev/null; echo $?`
204                        if [ $web_user_grep == 0 ]; then
205                                err=0
206                        else
207                        ERROR_MSG="\nThe Apache user does not exist!"
208                        fi
209                 else
210                        ERROR_MSG="\nThe Apache user can't be null!"
211             fi
212             ;;
213          *)
214            quit
215            ;;
216      esac
217    done
218   
219    get_rrdtool
220    #install_module
221}
222
223
224#ask user to specify the rrdtool binary path, and test if it is a good path (rrdtool exist or not).
225function get_rrdtool() {
226        err=1
227        ERROR_MSG=""
228        while [ $err != 0 ]
229        do
230                dialog_input "$ERROR_MSG\nPlease specify the location of binary rrdtool:\n" "$BIN_RRDTOOL"
231                case $temp in
232                3)#Cancel
233                        test_quit "\n$QUITMSG"
234                        ;;
235                1)#Previous
236                        get_web_user
237                        prev_funct
238                        ;;
239                0)#yes
240                        BIN_RRDTOOL=`cat $TEMP`
241                        BIN_RRDTOOL=`echo "$BIN_RRDTOOL" | sed -e 's/\/rrdtool$//'`
242                        if [ -n $BIN_RRDTOOL ] && [ -d $BIN_RRDTOOL ] && [ -a "${BIN_RRDTOOL}/rrdtool" ] ; then
243                                err=0
244                        else
245                                if [ -z "$BIN_RRDTOOL" ] ; then
246                                        ERROR_MSG="\nThe path can't be null!"
247                                else if [ ! -d $BIN_RRDTOOL ] ; then
248                                        ERROR_MSG="\nThe directory does not exist!"
249                                else
250                                        ERROR_MSG="\nThe path is not correct!"
251                                fi
252                                fi
253                        fi
254                        ;;
255                *)
256                        quit
257                        ;;
258                esac
259        done
260        install_module
261}
262
263
264
265function install_module() {
266        TEXT=""
267        $DIALOG --colors --backtitle "$BACKTITLE" --title "$TITLE" \
268        --infobox " " 9 62
269        TEMP_D="/tmp/Install_module"
270        mkdir $TEMP_D >> $LOG_FILE 2>> $LOG_FILE
271        cp -Rf ./* $TEMP_D/ >> $LOG_FILE 2>> $LOG_FILE
272        rm $TEMP_D/install $TEMP_D/functions_dialog $TEMP_D/*.log
273        testphp=`which php5 > /dev/null 2> /dev/null ; echo $?`
274        if [ $testphp = 0 ] ; then
275                `sed -e 's|@PHP_BIN@|!/usr/bin/php5|g' \
276                -e 's|@BIN_RRDTOOL@|'"$BIN_RRDTOOL/rrdtool"'|g' \
277                "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap.php" > "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap2.php"`
278        else
279                testphp=`which php4 > /dev/null 2> /dev/null ; echo $?`
280                if [ $testphp = 0 ] ; then
281                        `sed -e 's|@PHP_BIN@|!/usr/bin/php4|g' \
282                        -e 's|@BIN_RRDTOOL@|'"$BIN_RRDTOOL/rrdtool"'|g' \
283                        "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap.php" > "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap2.php"`
284                else
285                        `sed -e 's|@PHP_BIN@|!/usr/bin/php|g' \
286                        -e 's|@BIN_RRDTOOL@|'"$BIN_RRDTOOL/rrdtool"'|g' \
287                        "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap.php" > "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap2.php"`
288                fi
289        fi
290        `mv "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap2.php" "$TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/weathermap.php" >> $LOG_FILE 2>> $LOG_FILE`
291
292        TEXT="${TEXT}\nSetting right"
293        $DIALOG --colors --backtitle "$BACKTITLE" --title "$TITLE" \
294        --infobox "$TEXT" 9 62
295        chmod -R 755 $TEMP_D/* >> $LOG_FILE 2>> $LOG_FILE
296        TEXT="${TEXT}\nSetting owner/group"
297        $DIALOG --colors --backtitle "$BACKTITLE" --title "$TITLE" \
298        --infobox "$TEXT" 9 62
299        chown -R root.root $TEMP_D/* >> $LOG_FILE 2>> $LOG_FILE
300        cp -Rf --preserve $TEMP_D/* $INSTALL_DIR_OREON/ >> $LOG_FILE 2>> $LOG_FILE
301        chown -R $WEB_USER.$WEB_GROUP $TEMP_D/www/modules/php-weathermap/configuration/pwm-editor/configs/ >> $LOG_FILE 2>> $LOG_FILE
302        chown -R $WEB_USER.$WEB_GROUP $TEMP_D/www/modules/php-weathermap/views/renderer >> $LOG_FILE 2>> $LOG_FILE
303        TEXT="${TEXT}\ncopying module"
304        $DIALOG --colors --backtitle "$BACKTITLE" --title "$TITLE" \
305        --infobox "$TEXT" 9 62
306        rm -Rf $TEMP_D $TEMP >> $LOG_FILE 2>> $LOG_FILE
307        sleep 3
308       
309        End_install
310}
311
312function End_install() {
313    dialog_msgbox "\nThe $LOG_VERSION is finished\nSee README and the log file for more details."
314    clear_all
315    clear
316}
317
318
319Welcome
Note: See TracBrowser for help on using the browser.