root/alternc/tags/0.9.6.3/install/alternc.install

Revision 1843, 8.2 kB (checked in by benjamin, 2 years ago)

enable apache module also

Line 
1 #!/bin/sh
2 #
3 # AlternC Main install script.
4 # This script should be launched only once, when installing AlternC
5 # on a new server. THIS SCRIPT ERASE ALL DATA ON THE AlternC SYSTEM !!
6 # YOU HAVE BEEN WARNED !
7
8 set -e
9
10 #######################################################################
11 # Script configuration
12 #
13
14 # Configuration template location
15 TEMPLATE_DIR="/etc/alternc/templates"
16
17 # Find needed configuration files (without the initial '/')
18 # replace this one unconditionnally
19 CONFIG_FILES="etc/alternc/bureau.conf"
20
21 if [ -e /etc/bind/named.conf ]; then
22     CONFIG_FILES="$CONFIG_FILES etc/bind/templates/zone.template
23                   etc/bind/templates/named.template etc/bind/named.conf"
24 fi
25 if [ -e /etc/courier/authdaemonrc ]; then
26     CONFIG_FILES="$CONFIG_FILES etc/courier/authdaemonrc
27                   etc/courier/authmysqlrc"
28 fi
29 if [ -e /etc/postfix/main.cf ]; then
30     CONFIG_FILES="$CONFIG_FILES etc/postfix/main.cf etc/postfix/myalias.cf
31                   etc/postfix/mydomain.cf etc/postfix/mygid.cf
32                   etc/postfix/myvirtual.cf etc/postfix/sasl/smtpd.conf"
33 fi
34 if [ -e /etc/proftpd.conf ]; then
35     CONFIG_FILES="$CONFIG_FILES etc/proftpd.conf etc/welcome.msg"
36 fi
37 if [ -e /etc/squirrelmail/apache.conf ]; then
38     CONFIG_FILES="$CONFIG_FILES etc/squirrelmail/apache.conf"
39 fi
40
41 if [ -e /etc/default/saslauthd ]; then
42     CONFIG_FILES="$CONFIG_FILES etc/default/saslauthd"
43 fi
44
45 INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz"
46
47 #######################################################################
48 # Look for modified configuration files
49 #
50 if [ -f "$INSTALLED_CONFIG_TAR" ]; then
51     CHANGED="`tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null |
52               grep -v 'Uid differs'|grep -v 'Gid differs'  |grep -v 'Mode differs' |
53               sed -e 's/^\([^:]*\).*/    \1/' | sort -u`"
54     if [ ! -z "$CHANGED" ]; then
55         echo "The following configuration files has changed since last AlternC"
56         echo "installation :"
57         echo "$CHANGED"
58         echo ""
59         if [ "$1" = "force" ]; then
60             echo "Replacing them as you requested."
61         else
62             echo "These configuration files should normally be modified by"
63             echo "changing the template in $TEMPLATE_DIR and then calling"
64             echo "$0 to perform the update."
65             echo ""
66             echo "Please examine the situation closely and call '$0 force'"
67             echo "if you still want to actually overwrite these files."
68             exit 1
69         fi
70     fi
71 fi
72
73 #######################################################################
74 # Prepare template expansions
75 #
76
77 . /etc/alternc/local.sh
78
79 WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again."
80
81 VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`"
82
83 # /var/alternc/dns/d/www.example.com
84 FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`"
85 if [ "$FQDN_LETTER" = "$FQDN" ]
86 then
87        FQDN_LETTER="_"
88 fi
89
90 NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4];
91                  @ip = unpack('C4', \\$h);
92                  print join (\".\", @ip);"`
93
94 if [ ! -z "$BIND_INTERNAL" ]; then
95     BIND_INTERNAL="$BIND_INTERNAL;"
96 fi
97
98 if [ -z "$MONITOR_IP" ]; then
99     MONITOR_IP="127.0.0.1"
100 fi
101
102 SED_SCRIPT="
103 s\\%%hosting%%\\$HOSTING\\;
104 s\\%%fqdn%%\\$FQDN\\;
105 s\\%%public_ip%%\\$PUBLIC_IP\\;
106 s\\%%internal_ip%%\\$INTERNAL_IP\\;
107 s\\%%monitor_ip%%\\$MONITOR_IP\\;
108 s\\%%ns1%%\\$NS1_HOSTNAME\\;
109 s\\%%ns2%%\\$NS2_HOSTNAME\\;
110 s\\%%bind_internal%%\\$BIND_INTERNAL\\;
111 s\\%%mx%%\\$DEFAULT_MX\\;
112 s\\%%dbhost%%\\$MYSQL_HOST\\;
113 s\\%%dbname%%\\$MYSQL_DATABASE\\;
114 s\\%%dbuser%%\\$MYSQL_USER\\;
115 s\\%%dbpwd%%\\$MYSQL_PASS\\;
116 s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\;
117 s\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\;
118 s\\%%warning_message%%\\$WARNING\\;
119 s\\%%fqdn_lettre%%\\$FQDN_LETTER\\;
120 s\\%%version%%\\$VERSION\\;
121 s\\%%ns2_ip%%\\$NS2_IP\\;
122 "
123
124 #######################################################################
125 # Backup configuration files
126 #
127 BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz"
128
129 # Only backup what we are really going to replace
130 BACKUPS=""
131 for file in $CONFIG_FILES; do
132     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
133     if [ -f "$TEMPLATE" ]; then
134         BACKUPS="$BACKUPS $file"
135     fi
136 done
137
138 tar -zcf "$BACKUP_FILE" -C / $BACKUPS 2>/dev/null || true
139
140 #######################################################################
141 # Expand templates in the right place
142 #
143 for file in $CONFIG_FILES; do
144     TEMPLATE="$TEMPLATE_DIR/${file##etc/}"
145     if [ -f "$TEMPLATE" ]; then
146         sed -e "$SED_SCRIPT" < $TEMPLATE > /$file
147     fi
148 done
149
150 #######################################################################
151 # Save installed files to check them during next install
152 #
153 tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES
154
155 ######################################################################
156 # Initialize database
157 #
158 if [ -e /usr/sbin/mysqld ]; then
159     echo "Setup MySQL and database..."
160     /usr/share/alternc/install/mysql.sh "$MYSQL_USER" "$MYSQL_PASS" "$MYSQL_DATABASE"
161 fi
162
163 ########################################################################
164 # Ad-hoc fixes
165 #
166 # Add access to the management panel
167 ln -nsf /var/alternc/bureau /var/alternc/dns/$FQDN_LETTER/$FQDN
168
169 # Update l18n files
170 /usr/share/alternc/install/dopo.sh
171
172 # Bind stuff
173 touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
174 chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
175 chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf
176 touch /var/run/alternc/refresh_slave
177 /usr/lib/alternc/slave_dns
178
179 # Apache will not start without this file
180 touch /var/alternc/apacheconf/override_php.conf
181 # Enable vhost_alias apache module at the right place (ie: BEFORE mod_alias, but apache knows this ... )
182 apache-modconf apache enable mod_vhost_alias quiet </dev/null || true
183 apache-modconf apache enable `dpkg -l libapache-mod-php*|grep ii | cut -f 3 -d ' '|cut -b 11-18|sed -e 's/-/_/'` quiet </dev/null || true
184
185 # Copy postfix *_checks if they do not exist
186 for file in body_checks header_checks; do
187     if [ ! -e "/etc/postfix/$file" ]; then
188         cp /usr/share/alternc/install/$file /etc/postfix
189     fi
190 done
191
192 # Attribute the correct rights to critical postfix files
193 if [ -e /etc/postfix/myalias.cf -o -e /etc/postfix/mydomain.cf -o -e /etc/postfix/mygid.cf -o -e /etc/postfix/myvirtual.cf ]; then
194     chown root:postfix /etc/postfix/my*
195     chmod 640 /etc/postfix/my*
196 fi
197
198 if [ -e /etc/courier/authmysqlrc ] ; then
199     chown root:root /etc/courier/authmysqlrc
200     chmod 640 /etc/courier/authmysqlrc
201 fi
202
203 if [ -e /etc/proftpd.conf ] ; then
204     chmod 640 /etc/proftpd.conf
205 fi
206
207 #######################################################################
208 # Reload services
209 #
210 for service in apache apache-ssl postfix bind9 courier-authdaemon \
211                courier-imap courier-imap-ssl courier-pop courier-pop-ssl \
212                cron proftpd; do
213     test -x /etc/init.d/$service && invoke-rc.d $service reload || true
214 done
215
216 #######################################################################
217 # Last touches
218 #
219
220 # Add basedir protection
221 /usr/lib/alternc/basedir_prot.sh
222
223 # Creating admin user if needed
224 HAS_ROOT="`mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" -e "SELECT COUNT(*) FROM membres WHERE login = 'admin' OR login = 'root' and su = 1" | tail -1`"
225 if [ "$HAS_ROOT" != "1" ]; then
226     echo "Creating admin user..."
227     echo ""
228
229     if su - www-data -c /usr/share/alternc/install/newone.php
230       then
231       echo "*******************************************"
232       echo "*                                         *"
233       echo "*               Admin account             *"
234       echo "*               ------------              *"
235       echo "*                                         *"
236       echo "* user: admin             password: admin *"
237       echo "*                                         *"
238       echo "* Please change this as soon as possible! *"
239       echo "*                                         *"
240       echo "*******************************************"
241     else
242       echo "Il a été impossible de créer un nouveau membre alternc. newone.php a retourné un code d'erreur $?. Vérifiez si la base MySQL, PHP, ainsi que le fichier local.sh sont bien configurés. Vérifiez aussi si des erreurs ne sont pas apparues plus haut dans l'installation."
243     fi
244 fi
245
Note: See TracBrowser for help on using the browser.