|
|
@@ -1,49 +1,113 @@
|
|
|
-#!/bin/bash
|
|
|
+#!/bin/sh
|
|
|
|
|
|
+set -e
|
|
|
|
|
|
-# Stoppe le serveur Apache2 s'il est demarre
|
|
|
+case "$1" in
|
|
|
+ configure)
|
|
|
+ # Recupere le nom de domaine
|
|
|
|
|
|
-if systemctl is-active --quiet apache2;
|
|
|
-then
|
|
|
- systemctl stop apache2
|
|
|
-fi
|
|
|
+ DOMAIN=""
|
|
|
+ if [ -e /usr/share/debconf/confmodule ];
|
|
|
+ then
|
|
|
+ . /usr/share/debconf/confmodule db_get monsite/domain
|
|
|
+ DOMAIN="$RET"
|
|
|
+ fi
|
|
|
|
|
|
+ [ -z "$DOMAIN" ] && DOMAIN="ipsocloud.com"
|
|
|
|
|
|
-# Creation et installation des certificats Let's Encrypt
|
|
|
+ if [ ! -d /etc/ipsocloud ] && mkdir -p /etc/ipsocloud
|
|
|
+ if [ -f /etc/ipsocloud/domain.conf ] && rm /etc/ipsocloud/domain.conf
|
|
|
|
|
|
-certbot certonly --standalone -d monrisquearteriel.com -d api.monrisquearteriel.com -d www.monrisquearteriel.com -d cro.monrisquearteriel.com
|
|
|
-
|
|
|
-
|
|
|
-# Configuration Apache2
|
|
|
-
|
|
|
-a2enmod headers rewrite ssl proxy proxy_http
|
|
|
-a2ensite ipsocloud.conf
|
|
|
-
|
|
|
-
|
|
|
-# Configuration PHP
|
|
|
+ cat > /etc/ipsocloud/domain.conf <<EOF
|
|
|
+DOMAIN=$DOMAIN
|
|
|
+EOF
|
|
|
|
|
|
-for i in /etc/php/*/apache2/php.ini;
|
|
|
-do
|
|
|
- if [ -f ${i} ];
|
|
|
- then
|
|
|
- ed -s ${i} <<EOF
|
|
|
+ echo "Configuration pour le domaine : $DOMAIN"
|
|
|
+
|
|
|
+
|
|
|
+ # Stoppe le serveur Apache2 s'il est demarre
|
|
|
+
|
|
|
+ echo "Stoppe le serveur Apache"
|
|
|
+ if systemctl is-active --quiet apache2;
|
|
|
+ then
|
|
|
+ systemctl stop apache2
|
|
|
+ fi
|
|
|
+
|
|
|
+
|
|
|
+ # Change le nom de domaine dans le fichier de configuration Apache
|
|
|
+
|
|
|
+ echo "Change le domaine dans la configuration Apache"
|
|
|
+ [ $DOMAIN != "ipsocloud.com" ] && sed -i "s/ipsocloud.com/$DOMAIN/g" /etc/apache2/sites-available/ipsocloud.conf
|
|
|
+
|
|
|
+
|
|
|
+ # Creation et installation des certificats Let's Encrypt
|
|
|
+
|
|
|
+ if [ ! -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ];
|
|
|
+ then
|
|
|
+ echo "Creation des certificats pour $DOMAIN, api.$DOMAIN, www.$DOMAIN et cro.$DOMAIN"
|
|
|
+ certbot certonly --non-interactive --agree-tos --email "pjtw@iimt.fr" --standalone -d "$DOMAIN" -d "api.$DOMAIN" -d "www.$DOMAIN" -d "cro.$DOMAIN"
|
|
|
+ else
|
|
|
+ echo "Les certificats pour $DOMAIN existent deja"
|
|
|
+ fi
|
|
|
+
|
|
|
+
|
|
|
+ # Configuration Apache2
|
|
|
+
|
|
|
+ echo "Ajoute les modules Apache"
|
|
|
+ if ! a2query -m headers >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2enmod headers
|
|
|
+ fi
|
|
|
+ if ! a2query -m rewrite >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2enmod rewrite
|
|
|
+ fi
|
|
|
+ if ! a2query -m ssl >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2enmod ssl
|
|
|
+ fi
|
|
|
+ if ! a2query -m proxy >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2enmod proxy
|
|
|
+ fi
|
|
|
+ if ! a2query -m proxy_http >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2enmod proxy_http
|
|
|
+ fi
|
|
|
+ echo "Active le site web"
|
|
|
+ if ! a2query -s ipsocloud >/dev/null 2>&1;
|
|
|
+ then
|
|
|
+ a2ensite ipsocloud.conf
|
|
|
+ fi
|
|
|
+
|
|
|
+
|
|
|
+ # Configuration PHP
|
|
|
+
|
|
|
+ echo "Configure PHP"
|
|
|
+ for i in /etc/php/*/apache2/php.ini;
|
|
|
+ do
|
|
|
+ if [ -f ${i} ];
|
|
|
+ then
|
|
|
+ ed -s ${i} <<EOF
|
|
|
/upload_max_filesize
|
|
|
s/2M/30M
|
|
|
.
|
|
|
w
|
|
|
EOF
|
|
|
- fi
|
|
|
-done
|
|
|
+ fi
|
|
|
+ done
|
|
|
|
|
|
|
|
|
-# Redemarrage du serveur Apache2
|
|
|
+ # Redemarrage du serveur Apache2
|
|
|
|
|
|
-systemctl restart apache2
|
|
|
+ echo "Redemarre le serveur Apache"
|
|
|
+ systemctl restart apache2
|
|
|
|
|
|
|
|
|
-# Configuration de la base de donnees
|
|
|
+ # Configuration de la base de donnees
|
|
|
|
|
|
-mysql -u root <<EOF
|
|
|
+ echo "Configure la base de donnees"
|
|
|
+ mysql -u root <<EOF
|
|
|
CREATE USER IF NOT EXISTS 'newuser'@'localhost';
|
|
|
SET PASSWORD FOR 'newuser'@'localhost' = PASSWORD( 'password' );
|
|
|
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
|
|
|
@@ -52,26 +116,30 @@ exit
|
|
|
EOF
|
|
|
|
|
|
|
|
|
-# Ajoute les tables de Math-Cloud
|
|
|
+ # Ajoute les tables de Math-Cloud
|
|
|
|
|
|
-if [ -f /tmp/iimt_mathcloud.sql ] &&
|
|
|
- [ -f /tmp/iimt_mathcloud_audit.sql ] &&
|
|
|
- [ -f /tmp/iimt_mathcloud_shadow.sql ];
|
|
|
-then
|
|
|
- mysql -u root <<EOF
|
|
|
+ echo "Ajoute les tables de MAthCloud"
|
|
|
+ if [ -f /tmp/iimt_mathcloud.sql ] &&
|
|
|
+ [ -f /tmp/iimt_mathcloud_audit.sql ] &&
|
|
|
+ [ -f /tmp/iimt_mathcloud_shadow.sql ];
|
|
|
+ then
|
|
|
+ mysql -u root <<EOF
|
|
|
SOURCE /tmp/iimt_mathcloud.sql
|
|
|
SOURCE /tmp/iimt_mathcloud_audit.sql
|
|
|
SOURCE /tmp/iimt_mathcloud_shadow.sql
|
|
|
exit
|
|
|
EOF
|
|
|
-fi
|
|
|
+ fi
|
|
|
|
|
|
|
|
|
-# Mettre les droits d'acces au repertoire storage/
|
|
|
+ # Mettre les droits d'acces au repertoire storage/
|
|
|
|
|
|
-chmod 777 /var/www/storage/
|
|
|
-chmod 777 /var/www/storage/media/
|
|
|
-chmod 777 /var/www/storage/report/
|
|
|
-chown www-data:www-data /var/www/storage/tmp/
|
|
|
+ chown -R www-data:www-data /var/www/storage/
|
|
|
+ chmod 777 /var/www/storage/
|
|
|
+ chmod 777 /var/www/storage/media/
|
|
|
+ chmod 777 /var/www/storage/report/
|
|
|
+ ;;
|
|
|
+esac
|
|
|
|
|
|
+exit 0
|
|
|
|