| 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 | INSTALLED_CONFIG_TAR="/var/backups/alternc/etc-installed.tar.gz" |
|---|
| 53 | |
|---|
| 54 | ####################################################################### |
|---|
| 55 | # Look for modified configuration files |
|---|
| 56 | # |
|---|
| 57 | if [ -f "$INSTALLED_CONFIG_TAR" ]; then |
|---|
| 58 | CHANGED="`tar -zdf "$INSTALLED_CONFIG_TAR" -C / 2> /dev/null | |
|---|
| 59 | sed -e 's/^\([^:]*\).*/ \1/' | sort -u`" |
|---|
| 60 | if [ ! -z "$CHANGED" ]; then |
|---|
| 61 | echo "The following configuration files has changed since last AlternC" |
|---|
| 62 | echo "installation :" |
|---|
| 63 | echo "$CHANGED" |
|---|
| 64 | echo "" |
|---|
| 65 | if [ "$1" = "force" ]; then |
|---|
| 66 | echo "Replacing them as you requested." |
|---|
| 67 | else |
|---|
| 68 | echo "These configuration files should normally be modified by" |
|---|
| 69 | echo "changing the template in $TEMPLATE_DIR and then calling" |
|---|
| 70 | echo "$0 to perform the update." |
|---|
| 71 | echo "" |
|---|
| 72 | echo "Please examine the situation closely and call '$0 force'" |
|---|
| 73 | echo "if you still want to actually overwrite these files." |
|---|
| 74 | exit 1 |
|---|
| 75 | fi |
|---|
| 76 | fi |
|---|
| 77 | fi |
|---|
| 78 | |
|---|
| 79 | ####################################################################### |
|---|
| 80 | # Prepare template expansions |
|---|
| 81 | # |
|---|
| 82 | |
|---|
| 83 | . /etc/alternc/local.sh |
|---|
| 84 | |
|---|
| 85 | WARNING="WARNING: Do not edit this file, edit the one in /etc/alternc/templates and launch alternc.install again." |
|---|
| 86 | |
|---|
| 87 | VERSION="`dpkg -s alternc | sed -n -e 's/^Version: \(.*\)/\1/p'`" |
|---|
| 88 | |
|---|
| 89 | # /var/alternc/dns/d/www.example.com |
|---|
| 90 | FQDN_LETTER="`echo $FQDN | sed -e 's/.*\.\([^\.]\)[^\.]*\.[^\.]*$/\1/'`" |
|---|
| 91 | if [ "$FQDN_LETTER" = "$FQDN" ] |
|---|
| 92 | then |
|---|
| 93 | FQDN_LETTER="_" |
|---|
| 94 | fi |
|---|
| 95 | |
|---|
| 96 | NS2_IP=`perl -e "\\$h = (gethostbyname(\"$NS2_HOSTNAME\"))[4]; |
|---|
| 97 | @ip = unpack('C4', \\$h); |
|---|
| 98 | print join (\".\", @ip);"` |
|---|
| 99 | |
|---|
| 100 | if [ ! -z "$BIND_INTERNAL" ]; then |
|---|
| 101 | BIND_INTERNAL="$BIND_INTERNAL;" |
|---|
| 102 | fi |
|---|
| 103 | |
|---|
| 104 | if [ -z "$MONITOR_IP" ]; then |
|---|
| 105 | MONITOR_IP="127.0.0.1" |
|---|
| 106 | fi |
|---|
| 107 | |
|---|
| 108 | SED_SCRIPT=" |
|---|
| 109 | s\\%%hosting%%\\$HOSTING\\; |
|---|
| 110 | s\\%%fqdn%%\\$FQDN\\; |
|---|
| 111 | s\\%%public_ip%%\\$PUBLIC_IP\\; |
|---|
| 112 | s\\%%internal_ip%%\\$INTERNAL_IP\\; |
|---|
| 113 | s\\%%monitor_ip%%\\$MONITOR_IP\\; |
|---|
| 114 | s\\%%ns1%%\\$NS1_HOSTNAME\\; |
|---|
| 115 | s\\%%ns2%%\\$NS2_HOSTNAME\\; |
|---|
| 116 | s\\%%bind_internal%%\\$BIND_INTERNAL\\; |
|---|
| 117 | s\\%%mx%%\\$DEFAULT_MX\\; |
|---|
| 118 | s\\%%dbhost%%\\$MYSQL_HOST\\; |
|---|
| 119 | s\\%%dbname%%\\$MYSQL_DATABASE\\; |
|---|
| 120 | s\\%%dbuser%%\\$MYSQL_USER\\; |
|---|
| 121 | s\\%%dbpwd%%\\$MYSQL_PASS\\; |
|---|
| 122 | s\\%%ALTERNC_LOC%%\\$ALTERNC_LOC\\; |
|---|
| 123 | s\\%%mynetwork%%\\$SMTP_RELAY_NETWORKS\\; |
|---|
| 124 | s\\%%warning_message%%\\$WARNING\\; |
|---|
| 125 | s\\%%fqdn_lettre%%\\$FQDN_LETTER\\; |
|---|
| 126 | s\\%%version%%\\$VERSION\\; |
|---|
| 127 | s\\%%ns2_ip%%\\$NS2_IP\\; |
|---|
| 128 | " |
|---|
| 129 | |
|---|
| 130 | ####################################################################### |
|---|
| 131 | # Backup configuration files |
|---|
| 132 | # |
|---|
| 133 | BACKUP_FILE="/var/backups/alternc/etc-original-`date +%Y%m%d-%H%M`.tar.gz" |
|---|
| 134 | |
|---|
| 135 | # Only backup what we are really going to replace |
|---|
| 136 | BACKUPS="" |
|---|
| 137 | for file in $CONFIG_FILES; do |
|---|
| 138 | TEMPLATE="$TEMPLATE_DIR/${file##etc/}" |
|---|
| 139 | if [ -f "$TEMPLATE" ]; then |
|---|
| 140 | BACKUPS="$BACKUPS $file" |
|---|
| 141 | fi |
|---|
| 142 | done |
|---|
| 143 | |
|---|
| 144 | tar -zcf "$BACKUP_FILE" -C / $BACKUPS || true |
|---|
| 145 | |
|---|
| 146 | ####################################################################### |
|---|
| 147 | # Expand templates in the right place |
|---|
| 148 | # |
|---|
| 149 | for file in $CONFIG_FILES; do |
|---|
| 150 | TEMPLATE="$TEMPLATE_DIR/${file##etc/}" |
|---|
| 151 | if [ -f "$TEMPLATE" ]; then |
|---|
| 152 | sed -e "$SED_SCRIPT" < $TEMPLATE > /$file |
|---|
| 153 | fi |
|---|
| 154 | done |
|---|
| 155 | |
|---|
| 156 | v v v v v v v |
|---|
| 157 | ####################################################################### |
|---|
| 158 | # Save installed files to check them during next install |
|---|
| 159 | # |
|---|
| 160 | tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES |
|---|
| 161 | ************* |
|---|
| 162 | v v v v v v v |
|---|
| 163 | ####################################################################### |
|---|
| 164 | # Save installed files to check them during next install |
|---|
| 165 | # |
|---|
| 166 | tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES |
|---|
| 167 | ************* |
|---|
| 168 | %vars = ( |
|---|
| 169 | "hosting" => "Nom du service d'hebergement ", |
|---|
| 170 | "mx" => "Nom du serveur de mail ", |
|---|
| 171 | "ns1" => "Nom du serveur DNS primaire ", |
|---|
| 172 | "ns2" => "Nom du serveur DNS secondaire ", |
|---|
| 173 | "internal_ip" => "Adresse IP de l'interface réseau", |
|---|
| 174 | "mynetwork" => "Liste des réseaux autorisés en SMTP", |
|---|
| 175 | "fqdn" => "Nom de domaine du serveur hébergé ", |
|---|
| 176 | "bind_internal" => "Adresse IP ou classe d'IP des machines à l'intérieur de notre réseau de confiance DNS, séparés par ';', facultatif ", |
|---|
| 177 | "public_ip" => "Adresse IP annoncee par le serveur DNS pour ce serveur (vaut souvent internal_ip)", |
|---|
| 178 | "data_part" => "Nom de la partition contenant /%DATA/, pour la gestion des quotas (ex: /dev/hda3)", |
|---|
| 179 | "dbhost" => "Serveur où la base de données systeme de MySQL sera créée", |
|---|
| 180 | "dbname" => "Base de données systeme de MySQL à créer", |
|---|
| 181 | "dbuser" => "Nom d'utilisateur mysql réservé pour le Bureau", |
|---|
| 182 | "dbpwd" => "Mot de passe de l'utilisateur mysql du Bureau", |
|---|
| 183 | "monitor_ip" => "Adresse IP (ou ip/prefixe) du(des) serveur(s) dont on veut autoriser le ping vers nous et le status apache (pour le monitoring de serveur.) 127.0.0.1 par défaut", |
|---|
| 184 | "myrandom" => "Debian : Mot de passe de l'utilisateur 'debian-maint' de mysql.", |
|---|
| 185 | "ALTERNC_LOC" => "General : chemin où AlternC est installé (pour les quotas)", |
|---|
| 186 | "version" => "General : Version d'AlternC" |
|---|
| 187 | ); |
|---|
| 188 | ^ ^ ^ ^ ^ ^ ^ |
|---|
| 189 | ^ ^ ^ ^ ^ ^ ^ |
|---|
| 190 | |
|---|
| 191 | ###################################################################### |
|---|
| 192 | # Initialize database |
|---|
| 193 | # |
|---|
| 194 | if [ -x /etc/init.d/mysql -a ! -d /var/alternc/db/mysql ]; then |
|---|
| 195 | if /etc/init.d/mysql status | grep -v "MySQL is stopped." > /dev/null; then |
|---|
| 196 | /etc/init.d/mysql stop |
|---|
| 197 | fi |
|---|
| 198 | |
|---|
| 199 | echo "Setup MySQL and database..." |
|---|
| 200 | /usr/share/alternc/install/mysql.sh $MYSQL_USER $MYSQL_PASS $MYSQL_DATABASE |
|---|
| 201 | |
|---|
| 202 | /etc/init.d/mysql start |
|---|
| 203 | fi |
|---|
| 204 | |
|---|
| 205 | ######################################################################## |
|---|
| 206 | # Ad-hoc fixes |
|---|
| 207 | # |
|---|
| 208 | # Add access to the management panel |
|---|
| 209 | ln -nsf /var/alternc/bureau /var/alternc/dns/$FQDN_LETTER/$FQDN |
|---|
| 210 | |
|---|
| 211 | # Update l18n files |
|---|
| 212 | /usr/share/alternc/install/dopo.sh |
|---|
| 213 | |
|---|
| 214 | # Bind stuff |
|---|
| 215 | touch /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 216 | chown root:bind /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 217 | chmod 640 /var/alternc/bind/automatic.conf /var/alternc/bind/slaveip.conf |
|---|
| 218 | touch /var/run/alternc/refresh_slave |
|---|
| 219 | /usr/lib/alternc/slave_dns |
|---|
| 220 | |
|---|
| 221 | # Apache will not start without this file |
|---|
| 222 | touch /var/alternc/apacheconf/override_php.conf |
|---|
| 223 | |
|---|
| 224 | # Copy postfix *_checks if they do not exist |
|---|
| 225 | for file in body_checks header_checks; do |
|---|
| 226 | if [ ! -e "/etc/postfix/$file" ]; then |
|---|
| 227 | cp /usr/share/alternc/install/$file /etc/postfix |
|---|
| 228 | fi |
|---|
| 229 | done |
|---|
| 230 | |
|---|
| 231 | ####################################################################### |
|---|
| 232 | # Reload services |
|---|
| 233 | # |
|---|
| 234 | for service in apache apache-ssl postfix bind9 courier-authdaemon \ |
|---|
| 235 | courier-imap courier-imap-ssl courier-pop courier-pop-ssl \ |
|---|
| 236 | cron proftpd; do |
|---|
| 237 | test -x /etc/init.d/$service && /etc/init.d/$service force-reload || true |
|---|
| 238 | done |
|---|
| 239 | |
|---|
| 240 | ####################################################################### |
|---|
| 241 | # Last touches |
|---|
| 242 | # |
|---|
| 243 | |
|---|
| 244 | # Add basedir protection |
|---|
| 245 | /usr/lib/alternc/basedir_prot.sh |
|---|
| 246 | |
|---|
| 247 | # Creating root user if needed |
|---|
| 248 | HAS_ROOT=`echo "SELECT COUNT(*) FROM membres WHERE login = 'root'" | |
|---|
| 249 | mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS $MYSQL_DATABASE | |
|---|
| 250 | tail -1` |
|---|
| 251 | if [ "$HAS_ROOT" -eq 0 ]; then |
|---|
| 252 | echo "Creating root user..." |
|---|
| 253 | su - www-data -c /usr/share/alternc/install/newone.php |
|---|
| 254 | echo "" |
|---|
| 255 | echo "*******************************************" |
|---|
| 256 | echo "* *" |
|---|
| 257 | echo "* Root account *" |
|---|
| 258 | echo "* ------------ *" |
|---|
| 259 | echo "* *" |
|---|
| 260 | echo "* user: root password: root *" |
|---|
| 261 | echo "* *" |
|---|
| 262 | echo "* Please change this as soon as possible! *" |
|---|
| 263 | echo "* *" |
|---|
| 264 | echo "*******************************************" |
|---|
| 265 | fi |
|---|
| 266 | |
|---|
| 267 | v v v v v v v |
|---|
| 268 | ************* |
|---|
| 269 | v v v v v v v |
|---|
| 270 | # Postfix (serveur SMTP) |
|---|
| 271 | "etc/postfix/main.cf" => "[Postfix] Fichier de configuration principal de postfix", |
|---|
| 272 | "etc/postfix/sasl/smtpd.conf" => "[Postfix] Fichier de configuration SASL de postfix", |
|---|
| 273 | "etc/postfix/myalias.cf" => "[Postfix] Table des alias dans MySQL", |
|---|
| 274 | "etc/postfix/mydomain.cf" => "[Postfix] Table des mails en domaine dans MySQL", |
|---|
| 275 | "etc/postfix/myvirtual.cf" => "[Postfix] Table des wrappers / comptes pop dans MySQL", |
|---|
| 276 | "etc/postfix/mygid.cf" => "[Postfix] Table des mapping GID unix dans MySQL", |
|---|
| 277 | |
|---|
| 278 | "redir.htaccess" => "[WebMail] Redirection url interne", |
|---|
| 279 | "etc/squirrelmail/apache.conf" => "[Squirrelmail] Fichier de conf apache", |
|---|
| 280 | |
|---|
| 281 | ); |
|---|
| 282 | |
|---|
| 283 | # Those files are copied ONLY if they don't already exist |
|---|
| 284 | %onetime_vars = ( |
|---|
| 285 | "etc/bind/slaveip.conf" => "[Bind9] Liste des esclaves", |
|---|
| 286 | "etc/postfix/body_checks" => "[Postfix] Regles de filtrage des mails", |
|---|
| 287 | "etc/postfix/header_checks" => "[Postfix] Regles de filtrage des en-tetes", |
|---|
| 288 | "etc/bind/automatic.conf" => "[Bind9] Fichier (vide) dynamiquement genere par PHP", |
|---|
| 289 | ); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | @etcdir = ( |
|---|
| 293 | "etc/alternc", "etc/bind", "etc/bind/master", "etc/mysql", "etc/courier", |
|---|
| 294 | "etc/php4", "etc/php4/apache", "etc/apache-ssl", "etc/apache", |
|---|
| 295 | "etc/postfix", "etc/squirrelmail", "etc/php4/cgi", "etc/phpmyadmin", "usr/lib/alternc" |
|---|
| 296 | ); |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | ######################################################################### |
|---|
| 300 | # 6. Compute other variables depending on the variables setup in 4. and |
|---|
| 301 | # setup some defaults |
|---|
| 302 | ######################################################################### |
|---|
| 303 | |
|---|
| 304 | %varscalc = ( |
|---|
| 305 | "fqdn_lettre" => "Premiere lettre de l'avant dernier membre du fqdn", |
|---|
| 306 | "warning_message" => "Message d'avertissement insere en commentaire dans tous les fichiers de conf ...", |
|---|
| 307 | "random_hash" => "Chaine aléatoire utilisée par phpmyadmin ..." |
|---|
| 308 | ); |
|---|
| 309 | |
|---|
| 310 | @fq=split /\./, $conf{fqdn}; |
|---|
| 311 | |
|---|
| 312 | $conf{fqdn_lettre} = substr($fq[(scalar @fq)-2],0,1); |
|---|
| 313 | $conf{warning_message} = "WARNING : Do not edit this file, edit the one in /usr/share/alternc/install/ and launch alternc.install again"; |
|---|
| 314 | |
|---|
| 315 | if ($conf{bind_internal}) { |
|---|
| 316 | $conf{bind_internal} .= ";"; |
|---|
| 317 | } |
|---|
| 318 | if (!$conf{monitor_ip}) { |
|---|
| 319 | $conf{monitor_ip} = "127.0.0.1"; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | $conf{random_hash} = map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..10); |
|---|
| 323 | |
|---|
| 324 | ######################################################################### |
|---|
| 325 | # 7. Create the temporary etc files, and parse them, replacing the |
|---|
| 326 | # variables set in 4 and 6 |
|---|
| 327 | ######################################################################### |
|---|
| 328 | |
|---|
| 329 | $TMP=`mktemp -d /tmp/alternc.install.XXXXXX`; chomp($TMP); |
|---|
| 330 | mkdir("$TMP/etc",0777); |
|---|
| 331 | mkdir("$TMP/usr",0777); |
|---|
| 332 | mkdir("$TMP/usr/lib",0777); |
|---|
| 333 | |
|---|
| 334 | for ($i=0;$i<scalar @etcdir;$i++) { |
|---|
| 335 | print "creating directory /".$etcdir[$i]."\n"; |
|---|
| 336 | mkdir("$TMP/".$etcdir[$i]."",0777); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | while (($key,$val) = each(%conf_vars)) { |
|---|
| 340 | print "parsing configuration file /$key $val "; |
|---|
| 341 | open F,"</usr/share/alternc/install/$key" || die "Erreur Ouverture R"; |
|---|
| 342 | open G,">$TMP/$key" || die "Erreur Ouverture W"; |
|---|
| 343 | while ($buffer = <F>) { |
|---|
| 344 | # Replace user variables : |
|---|
| 345 | while (($kv,$vv)=each(%vars)) { |
|---|
| 346 | $buffer=~ s/%%$kv%%/$conf{$kv}/; |
|---|
| 347 | } |
|---|
| 348 | # Replace computed variables : |
|---|
| 349 | while (($kv,$vv)=each(%varscalc)) { |
|---|
| 350 | # printf $kv." : ".$conf{$kv}."\n"; |
|---|
| 351 | $buffer=~ s/%%$kv%%/$conf{$kv}/; |
|---|
| 352 | } |
|---|
| 353 | print G $buffer; |
|---|
| 354 | } |
|---|
| 355 | close(F) || warn("cannot close F /usr/share/alternc/install/$key: $!"); |
|---|
| 356 | close(G) || warn("cannot close G $TMP/$key: $!"); |
|---|
| 357 | print "\n"; |
|---|
| 358 | } |
|---|
| 359 | # Chmod the shell scripts (a+x) |
|---|
| 360 | system("find $TMP/ -name \"*.sh\" -exec chmod a+x '{}' \\;"); |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | ######################################################################### |
|---|
| 364 | # 8. Backup current conf files |
|---|
| 365 | ######################################################################### |
|---|
| 366 | |
|---|
| 367 | print "backup current system files (/etc)\n"; |
|---|
| 368 | |
|---|
| 369 | # Creation des dossiers dans /tmp/system.DATEDUJOUR |
|---|
| 370 | chop($TS=`date +%Y%m%d-%H%M`); |
|---|
| 371 | mkdir("/usr/lib/alternc/backups"); |
|---|
| 372 | # XXX: this should change name instead of just overwriting |
|---|
| 373 | unlink("/usr/lib/alternc/backups/system.$TS.tgz"); |
|---|
| 374 | # prepend a slash before each etcdir: TODO : is it still necessary ? |
|---|
| 375 | map { $_ =~ s/^/\//; } @etcdir; |
|---|
| 376 | $cmd = "tar -czf /usr/lib/alternc/backups/system.$TS.tgz /etc >/dev/null 2>&1"; |
|---|
| 377 | system($cmd) == 0 || die ("error tar $cmd: $!"); |
|---|
| 378 | system("/usr/share/alternc/install/dopo.sh") == 0 || die ("error dodpo"); |
|---|
| 379 | |
|---|
| 380 | ######################################################################### |
|---|
| 381 | # 9. Stop services |
|---|
| 382 | ######################################################################### |
|---|
| 383 | |
|---|
| 384 | system("/etc/init.d/apache stop >&2"); |
|---|
| 385 | system("/etc/init.d/apache-ssl stop >&2"); |
|---|
| 386 | system("/etc/init.d/postfix stop >&2"); |
|---|
| 387 | system("/etc/init.d/bind9 stop >&2"); |
|---|
| 388 | system("/etc/init.d/courier-authdaemon stop >&2"); |
|---|
| 389 | system("/etc/init.d/courier-imap stop >&2"); |
|---|
| 390 | system("/etc/init.d/courier-imap-ssl stop >&2"); |
|---|
| 391 | system("/etc/init.d/courier-pop stop >&2"); |
|---|
| 392 | system("/etc/init.d/courier-pop-ssl stop >&2"); |
|---|
| 393 | system("/etc/init.d/cron stop >&2"); |
|---|
| 394 | system("/etc/init.d/proftpd stop >&2"); |
|---|
| 395 | system("/etc/init.d/mysql stop >&2"); |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | ######################################################################### |
|---|
| 399 | # 10. Create dir structure and copy panel files |
|---|
| 400 | ######################################################################### |
|---|
| 401 | |
|---|
| 402 | print "Creating directory structure in /var/alternc\n"; |
|---|
| 403 | system("/usr/share/alternc/install/initrep.sh"); |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | ######################################################################### |
|---|
| 407 | # 11. Send etc files to /etc :) |
|---|
| 408 | ######################################################################### |
|---|
| 409 | |
|---|
| 410 | print "Copying files to /etc\n"; |
|---|
| 411 | # 11.1 copy all the files setup in 7 in /etc, plus other places |
|---|
| 412 | system("rsync -a $TMP/etc/* /etc/"); |
|---|
| 413 | # 11.2 setup part of the webmail |
|---|
| 414 | system("cp $TMP/redir.htaccess /var/alternc/bureau/admin/webmail/.htaccess"); |
|---|
| 415 | # 11.3 setup part of bind |
|---|
| 416 | system("cp $TMP/domaines.template /usr/lib/alternc/system/bind2/"); |
|---|
| 417 | # 11.4 setup part of the panel |
|---|
| 418 | system("cp $TMP/local.php /var/alternc/bureau/class"); |
|---|
| 419 | # 11.5 setup permissions for scripts and configs |
|---|
| 420 | system("chown -R www-data.www-data /var/alternc/bureau/admin/webmail/.htaccess /var/alternc/dns /var/run/alternc /var/log/alternc"); |
|---|
| 421 | system("chown -R root.www-data /var/alternc/bureau"); |
|---|
| 422 | system("chmod -R 0640 /var/alternc/bureau"); |
|---|
| 423 | system("chmod -R ug+X /var/alternc/bureau"); |
|---|
| 424 | system("chown www-data.www-data /var/alternc/html/* /var/alternc/mail/* /var/alternc/html/ /var/alternc/mail/ "); |
|---|
| 425 | system("install -o root -g www-data -m0750 $TMP/usr/lib/alternc/sendmail /usr/lib/alternc/sendmail"); |
|---|
| 426 | |
|---|
| 427 | # 11.6 symlink the bureau in dns/ |
|---|
| 428 | @fq=split /\./, $conf{fqdn}; |
|---|
| 429 | $fl=substr($fq[(scalar @fq)-2],0,1); |
|---|
| 430 | symlink("/var/alternc/bureau","/var/alternc/dns/$fl/$conf{fqdn}"); |
|---|
| 431 | |
|---|
| 432 | # 11.7 Copy 'one time' files IF REQUIRED |
|---|
| 433 | while (($key,$val) = each(%onetime_vars)) { |
|---|
| 434 | if (! (-e "/$key") ) { |
|---|
| 435 | print "Copying one time file /$key $val "; |
|---|
| 436 | open F,"</usr/share/alternc/install/$key" || die "Erreur Ouverture R"; |
|---|
| 437 | open G,">/$key" || die "Erreur Ouverture W"; |
|---|
| 438 | while ($buffer = <F>) { |
|---|
| 439 | # Replace user variables : |
|---|
| 440 | while (($kv,$vv)=each(%vars)) { |
|---|
| 441 | $buffer=~ s/%%$kv%%/$conf{$kv}/; |
|---|
| 442 | } |
|---|
| 443 | # Replace computed variables : |
|---|
| 444 | while (($kv,$vv)=each(%varscalc)) { |
|---|
| 445 | # printf $kv." : ".$conf{$kv}."\n"; |
|---|
| 446 | $buffer=~ s/%%$kv%%/$conf{$kv}/; |
|---|
| 447 | } |
|---|
| 448 | print G $buffer; |
|---|
| 449 | } |
|---|
| 450 | close(F); |
|---|
| 451 | close(G); |
|---|
| 452 | print "\n"; |
|---|
| 453 | } |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | ######################################################################### |
|---|
| 457 | # 14. Create MySQL database, restart mysql and add default users |
|---|
| 458 | ######################################################################### |
|---|
| 459 | |
|---|
| 460 | print "Creating MySQL db, restarting mysql.\n"; |
|---|
| 461 | system("/usr/share/alternc/install/mysql.sh '".$conf{dbuser}."' '".$conf{dbpwd}."' '".$conf{dbname}."' >&2"); |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | ######################################################################### |
|---|
| 465 | # 15. Start services |
|---|
| 466 | ######################################################################### |
|---|
| 467 | |
|---|
| 468 | system("/etc/init.d/apache start >&2"); |
|---|
| 469 | system("/etc/init.d/apache-ssl start >&2"); |
|---|
| 470 | system("/etc/init.d/postfix start >&2"); |
|---|
| 471 | system("/etc/init.d/bind9 start >&2"); |
|---|
| 472 | system("/etc/init.d/courier-authdaemon start >&2"); |
|---|
| 473 | system("/etc/init.d/courier-imap start >&2"); |
|---|
| 474 | system("/etc/init.d/courier-imap-ssl start >&2"); |
|---|
| 475 | system("/etc/init.d/courier-pop start >&2"); |
|---|
| 476 | system("/etc/init.d/courier-pop-ssl start >&2"); |
|---|
| 477 | system("/etc/init.d/cron start >&2"); |
|---|
| 478 | system("/etc/init.d/proftpd start >&2"); |
|---|
| 479 | |
|---|
| 480 | ######################################################################### |
|---|
| 481 | # 16. Create the first user |
|---|
| 482 | ######################################################################### |
|---|
| 483 | |
|---|
| 484 | print "Creating user root, with password root (change it as soon as possible)\n"; |
|---|
| 485 | |
|---|
| 486 | system("su - www-data -c /usr/share/alternc/install/newone.php"); |
|---|
| 487 | system("/usr/lib/alternc/basedir_prot.sh"); |
|---|
| 488 | |
|---|
| 489 | system("rm -rf $TMP"); |
|---|
| 490 | |
|---|
| 491 | ######################################################################### |
|---|
| 492 | # 17. Job's done ! Ready to serve... |
|---|
| 493 | ######################################################################### |
|---|
| 494 | |
|---|
| 495 | print " |
|---|
| 496 | AlternC Install complete. |
|---|
| 497 | You may use you server now. Don't forget to change your root password |
|---|
| 498 | as soon as possible. |
|---|
| 499 | If you use this software, please send a mail to tech\@alternc.org |
|---|
| 500 | so that we know who use it :) and build some kind of statistics. Thanks. |
|---|
| 501 | |
|---|
| 502 | "; |
|---|
| 503 | |
|---|
| 504 | exit(0); |
|---|
| 505 | ************* |
|---|
| 506 | # vim: et sw=4 |
|---|
| 507 | ^ ^ ^ ^ ^ ^ ^ |
|---|
| 508 | |
|---|
| 509 | ^ ^ ^ ^ ^ ^ ^ |
|---|