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