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