#!/bin/bash # # Prepare/Configure Apache # Copyright (C) 2017 AleaJactaEst # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . usage() { cat << EOF usage:$0 [options] prepare mysql (create directory, update configuration) options: -h, --help : Show this help -d, --debug : Show debug message EOF } ##################### # MAIN ##################### source /opt/servercontainer_function.sh msg_info "$(basename $0) => START" while test $# -gt 0 do case "$1" in -h|--help) usage exit 1 ;; -d|--debug) set_debug 1 shift ;; *) msg_error "options '$1' not recognize" usage exit 1 ;; esac done #################################### # Load Environment #################################### msg_debug "Load environment" if [[ ! -f /opt/khanat_config.sh ]] then echo "ERROR - missing /opt/khanat_config.sh" exit 2 fi source /opt/khanat_config.sh #################################### # Configure apache log / Account use by apache #################################### msg_debug "Configure apache log / Account use by apache" sed -i -r 's/^export[[:space:]]+APACHE_RUN_USER=(.*)/export APACHE_RUN_USER=gameserver/g' /etc/apache2/envvars || exit 2 sed -i -r 's/^export[[:space:]]+APACHE_RUN_GROUP=(.*)/export APACHE_RUN_GROUP='$(id -g -n gameserver)'/g' /etc/apache2/envvars || exit 2 sed -i -r 's/^export[[:space:]]+APACHE_LOG_DIR=(.*)/export APACHE_LOG_DIR=\/home\/gameserver\/log\/apache2\$SUFFIX/g' /etc/apache2/envvars || exit 2 sed -i -r 's/^LogLevel[[:space:]]+warn/LogLevel debug/g' /etc/apache2/apache2.conf || exit 2 #################################### # configure phpmyadmin #################################### msg_debug "configure phpmyadmin" ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf || exit 2 a2enconf phpmyadmin.conf || exit 2 cp /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.ref || exit 2 awk '{if($0 ~ /AllowNoPassword/){$1="";}; print $0;}' /etc/phpmyadmin/config.inc.php.ref > /etc/phpmyadmin/config.inc.php || exit 2 #################################### # configure phpmyadmin #################################### msg_debug "configure apache" # configure apache cat << EOF > /etc/apache2/sites-available/000-default.conf # Default Options Indexes FollowSymLinks AllowOverride None Require all granted DirectoryIndex index.php AddType text/html .php .phps AddHandler application/x-httpd-php .php AddHandler application/x-httpd-php-source .phps ServerName lirria.khaganat.net ServerAdmin webmaster@localhost DocumentRoot /home/gameserver/khanat/khanatweb/public_php/ ErrorLog \${APACHE_LOG_DIR}/error.log CustomLog \${APACHE_LOG_DIR}/access.log combined # Khanat Server Web Options Indexes FollowSymLinks AllowOverride None Require all granted ServerName lirria.khaganat.net ServerAdmin admin@localhost DocumentRoot /home/gameserver/khanat/khanatweb/public_php ErrorLog \${APACHE_LOG_DIR}/error.log CustomLog \${APACHE_LOG_DIR}/access.log combined # Patch Server ServerName lirria.khaganat.net DocumentRoot /home/gameserver/khanat/patch_service/patch_game/patch/ Options -Indexes AllowOverride All Require all granted EOF # Open port use by apache cat << EOF > /etc/apache2/ports.conf # If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default.conf Listen 80 Listen 40916 Listen 43435 Listen 443 Listen 443 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet EOF # Activate php - strange beacause we have only index.php (without php code !) cat << EOF > /etc/apache2/conf-available/patch_service.conf Alias /patch /home/gameserver/khanat/patch_service/patch_game/patch Options FollowSymLinks DirectoryIndex index.php Require all granted AddType application/x-httpd-php .php SetHandler application/x-httpd-php EOF # Configuration de la page client cat << EOF > /etc/apache2/conf-available/client_service.conf Alias /client /home/gameserver/khanat/client_service Options FollowSymLinks DirectoryIndex index.html Require all granted AddType application/tar .tar.gz SetHandler application/tar EOF #################################### # Activate web site #################################### msg_info "Activate patch service" # Activate & deploy new configuration a2enconf patch_service.conf msg_info "Activate client service" # Activate & deploy new configuration a2enconf client_service.conf #################################### # End #################################### msg_info "$(basename $0) => END"