2019-07-30 23:34:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
export SCRIPT_NAME="$(realpath "$0")"
|
|
|
|
export SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"
|
2019-07-31 09:37:16 +02:00
|
|
|
export PATH="$SCRIPT_PATH/../share/bin/:$PATH"
|
2019-07-30 23:34:41 +02:00
|
|
|
|
|
|
|
cd "$SCRIPT_PATH/../"
|
|
|
|
|
|
|
|
. ./etc/config
|
|
|
|
|
|
|
|
exit_if_empty() {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
printf "$2\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Collect of information #
|
|
|
|
##########################
|
|
|
|
|
|
|
|
TITLE="Deblan network - New website"
|
|
|
|
|
|
|
|
DOMAIN="$(form_input -t "$TITLE" -l "Domain" -r)"
|
|
|
|
|
|
|
|
exit_if_empty "$DOMAIN" "Aborded! (DOMAIN_EMPTY)"
|
|
|
|
|
|
|
|
DOMAIN_ALIASES="$(form_input -t "$TITLE" -l "Aliase(s)")"
|
|
|
|
|
|
|
|
WEB_HTTP="$(form_yes_no -t "$TITLE" -l "Support of HTTP (recommanded)")"
|
|
|
|
WEB_HTTPS="$(form_yes_no -t "$TITLE" -l "Support of HTTPS (recommanded)")"
|
|
|
|
|
|
|
|
if [ "$WEB_HTTP" = "yes" -a "$WEB_HTTPS" = "yes" ]; then
|
|
|
|
WEB_HTTPS_FORCE="$(form_yes_no -t "$TITLE" -l "Redirect HTTP to HTTPS (recommanded)")"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#if [ "$WEB_HTTPS" = "yes" ]; then
|
|
|
|
# WEB_HTTPS_GENERATE_CERTIFICATE="$(form_yes_no -t "$TITLE" -l "Retrieve certificate using LE")"
|
|
|
|
#fi
|
|
|
|
|
|
|
|
DOCUMENT_ROOT="$(form_input -t "$TITLE" -l "Document Root" -d "/var/www/service-web/www/$DOMAIN/web")"
|
|
|
|
|
|
|
|
PHP_ENABLED="$(form_yes_no -t "$TITLE" -l "Support of PHP")"
|
|
|
|
|
|
|
|
exit_if_empty "$DOCUMENT_ROOT" "Aborded! (SYSTEM_USERNAME_EMPTY)"
|
|
|
|
|
|
|
|
if [ "$PHP_ENABLED" = "yes" ]; then
|
|
|
|
PHP_VERSION="$(form_choices -t "$TITLE" -l "Version of PHP" \
|
|
|
|
"7.3" "PHP 7.3 (recommanded)" \
|
|
|
|
"7.2" "PHP 7.2" \
|
|
|
|
"7.1" "PHP 7.1" \
|
|
|
|
"5.6" "PHP 5.6 (not recommanded)")"
|
|
|
|
|
|
|
|
exit_if_empty "$PHP_VERSION" "Aborded! (PHP_VERSION_EMPTY)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
USER_PASSWORD="$(tr -dc "12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
|
|
|
|
|
|
|
|
SYSTEM_USER_USERNAME="$(form_input -t "$TITLE" -l "System username" -d "web" -r)"
|
|
|
|
SYSTEM_USER_GROUP="webgroup"
|
|
|
|
SYSTEM_USER_PASSWORD=$(export PASSWORD="$USER_PASSWORD"; export SALT=$(date +'%S'); crypt)
|
|
|
|
|
|
|
|
exit_if_empty "$SYSTEM_USER_USERNAME" "Aborded! (SYSTEM_USERNAME_EMPTY)"
|
|
|
|
|
2019-07-31 09:57:44 +02:00
|
|
|
################
|
|
|
|
# Confirmation #
|
|
|
|
################
|
|
|
|
|
|
|
|
export DOMAIN
|
|
|
|
export DOMAIN_ALIASES
|
|
|
|
export DOCUMENT_ROOT
|
|
|
|
export SYSTEM_USER_USERNAME
|
|
|
|
export SYSTEM_USER_GROUP
|
|
|
|
export PHP_ENABLED
|
|
|
|
export PHP_VERSION
|
|
|
|
export WEB_HTTP
|
|
|
|
export WEB_HTTPS
|
|
|
|
export WEB_HTTPS_FORCE
|
|
|
|
|
|
|
|
TMP_FILE="/tmp/vhost-add-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
|
|
|
|
template summary > "$TMP_FILE"
|
|
|
|
chmod 600 "$TMP_FILE"
|
|
|
|
whiptail --textbox "$TMP_FILE" 20 80
|
|
|
|
rm "$TMP_FILE"
|
|
|
|
|
|
|
|
CONTINUE="$(form_yes_no -t "$TITLE" -l "Do you confirm?")"
|
|
|
|
|
|
|
|
if [ "$CONTINUE" = "no" ]; then
|
|
|
|
printf "Aborded!\n"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-07-30 23:34:41 +02:00
|
|
|
###############################
|
|
|
|
# User and directory creation #
|
|
|
|
###############################
|
|
|
|
|
|
|
|
useradd -G "$SYSTEM_USER_GROUP" -s /bin/zsh -m -p "$SYSTEM_USER_PASSWORD" -d "/services/web/www/$DOMAIN" "$SYSTEM_USER_USERNAME" -k /etc/skel/
|
|
|
|
chgrp www-data "/services/web/www/$DOMAIN"
|
|
|
|
chmod o-r "/services/web/www/$DOMAIN"
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Make configurations #
|
|
|
|
#######################
|
|
|
|
|
|
|
|
SERVICES_TO_RELOAD="apache2"
|
|
|
|
|
|
|
|
SYSTEM_USER_ID="$(id -u "$SYSTEM_USER_USERNAME")"
|
|
|
|
PHP_FPM_PORT=$(($SYSTEM_USER_ID + 12000))
|
|
|
|
|
|
|
|
if [ "$WEB_HTTP" = "yes" ]; then
|
|
|
|
VHOST_FILE_SA="/etc/apache2/sites-available/${DOMAIN}.${WEB_HTTP_PORT}.conf"
|
|
|
|
VHOST_FILE_SE="/etc/apache2/sites-enabled/${DOMAIN}.${WEB_HTTP_PORT}.conf"
|
|
|
|
PORT=$WEB_HTTP_PORT template vhost-http > "$VHOST_FILE_SA"
|
|
|
|
|
|
|
|
ln -rs "$VHOST_FILE_SA" "$VHOST_FILE_SE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$WEB_HTTPS" = "yes" ]; then
|
|
|
|
VHOST_FILE_SA="/etc/apache2/sites-available/${DOMAIN}.${WEB_HTTPS_PORT}.conf"
|
2019-07-31 00:04:37 +02:00
|
|
|
VHOST_FILE_SE="/etc/apache2/sites-enabled/${DOMAIN}.${WEB_HTTPS_PORT}.conf"
|
2019-07-30 23:34:41 +02:00
|
|
|
|
|
|
|
PORT=$WEB_HTTPS_PORT template vhost-https > "$VHOST_FILE_SA"
|
|
|
|
|
|
|
|
ln -rs "$VHOST_FILE_SA" "$VHOST_FILE_SE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PHP_ENABLED" = "yes" ]; then
|
|
|
|
if [ "$PHP_VERSION" = "5.6" ]; then
|
|
|
|
SERVICES_TO_RELOAD="$SERVICES_TO_RELOAD php5-fpm"
|
|
|
|
PHP_FPM_FILE="/etc/php5/fpm/pool.d/${SYSTEM_USER_USERNAME}.conf"
|
|
|
|
else
|
|
|
|
SERVICES_TO_RELOAD="$SERVICES_TO_RELOAD php${PHP_VERSION}-fpm"
|
|
|
|
PHP_FPM_FILE="/etc/php/$PHP_VERSION/fpm/pool.d/${SYSTEM_USER_USERNAME}.conf"
|
|
|
|
fi
|
|
|
|
|
2019-07-31 09:57:44 +02:00
|
|
|
export PHP_FPM_PORT
|
|
|
|
|
2019-07-30 23:34:41 +02:00
|
|
|
template php-fpm > "$PHP_FPM_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
for SERVICE in $SERVICES_TO_RELOAD; do
|
|
|
|
service $SERVICE reload
|
|
|
|
done
|
|
|
|
|
2019-07-31 09:57:44 +02:00
|
|
|
export USER_PASSWORD
|
|
|
|
|
|
|
|
TMP_FILE="/tmp/vhost-add-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
|
|
|
|
template result > "$TMP_FILE"
|
|
|
|
chmod 600 "$TMP_FILE"
|
2019-07-31 11:35:41 +02:00
|
|
|
whiptail --textbox "$TMP_FILE" 25 80
|
2019-07-31 09:57:44 +02:00
|
|
|
rm "$TMP_FILE"
|