root/alternc/branches/larpoux-unstable/install/alternc.install

Revision 805, 7.5 kB (checked in by root, 3 years ago)

- correcting bug in mysql.sql to add default quotas.
- correcting dependency on libapache-mod-php4
- patch alternc.install cosmetique de shell

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