refs #184 Clean and optimize ogdhcp_installer

pull/1/head
Alvaro Puente Mella 2024-03-20 13:25:35 +01:00
parent 5f32ddd66f
commit 6faac6099a
1 changed files with 187 additions and 204 deletions

View File

@ -5,67 +5,90 @@
####### Autor: Luis Gerardo Romero <lguillen@unizar.es> ####### Autor: Luis Gerardo Romero <lguillen@unizar.es>
##################################################################### #####################################################################
function globalSetup () function globalSetup() {
{ local current_dir
PROGRAMDIR=$(readlink -e "$(dirname "$0")") current_dir=$(dirname "$0")
PROGRAMNAME=$(basename "$0") PROGRAMDIR=$(readlink -e "$current_dir")
OPENGNSYS_CLIENT_USER="ogdhcp" PROGRAMNAME=$(basename "$0")
# Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1). OPENGNSYS_CLIENT_USER="ogdhcp"
OPENGNSYS_SERVER="opengnsys.es"
if [ -d "$PROGRAMDIR/../installer" ]; then
echo REMOTE=0
REMOTE=0
else
echo REMOTE=1
REMOTE=1
fi
BRANCH=$1
if [[ -z $BRANCH ]]; then
BRANCH="main"
fi
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogdhcp.git"
# Directorios de instalación y destino de OpenGnsys. # Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1).
WORKDIR=/tmp/ogdhcp_installer if [ -d "$PROGRAMDIR/../installer" ]; then
INSTALL_TARGET=/opt/ogdhcp echo "REMOTE=0"
PATH=$PATH:$INSTALL_TARGET/bin REMOTE=0
if which service &>/dev/null; then else
STARTSERVICE="eval service \$service restart" echo "REMOTE=1"
STOPSERVICE="eval service \$service stop" REMOTE=1
else fi
STARTSERVICE="eval /etc/init.d/\$service restart"
STOPSERVICE="eval /etc/init.d/\$service stop"
fi
ENABLESERVICE="eval update-rc.d \$service defaults"
DISABLESERVICE="eval update-rc.d \$service disable"
APACHESERV=apache2
APACHECFGDIR=/etc/apache2
APACHESITESDIR=sites-available
APACHEOGSITE=ogdhcp
APACHEUSER="www-data"
APACHEGROUP="www-data"
APACHEENABLEMODS="a2enmod headers ssl rewrite proxy_fcgi fastcgi actions alias"
APACHEENABLESSL="a2ensite default-ssl"
APACHEENABLEOG="a2ensite $APACHEENABLEOG"
APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite"
PHPFPMSERV=php7.2-fpm
# Registro de incidencias.
OGLOGFILE=$INSTALL_TARGET/var/log/${PROGRAMNAME%.sh}.log
LOG_FILE=/tmp/$(basename $OGLOGFILE)
BRANCH=${1:-"main"}
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogdhcp.git"
# Directorios de instalación y destino de OpenGnsys.
WORKDIR=/tmp/ogdhcp_installer
INSTALL_TARGET=/opt/ogdhcp
PATH=$PATH:$INSTALL_TARGET/bin
if command -v service &>/dev/null; then
STARTSERVICE="eval service \$service restart"
STOPSERVICE="eval service \$service stop"
else
STARTSERVICE="eval /etc/init.d/\$service restart"
STOPSERVICE="eval /etc/init.d/\$service stop"
fi
ENABLESERVICE="eval update-rc.d \$service defaults"
DISABLESERVICE="eval update-rc.d \$service disable"
APACHESERV=apache2
APACHECFGDIR=/etc/apache2
APACHESITESDIR=sites-available
APACHEOGSITE=ogdhcp
APACHEUSER="www-data"
APACHEGROUP="www-data"
APACHEENABLEMODS="a2enmod headers ssl rewrite proxy_fcgi fastcgi actions alias"
APACHEENABLESSL="a2ensite default-ssl"
APACHEENABLEOG="a2ensite $APACHEENABLEOG"
APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite"
PHPFPMSERV=php7.2-fpm
# Registro de incidencias.
OGLOGFILE="$INSTALL_TARGET/var/log/${PROGRAMNAME%.sh}.log"
LOG_FILE="/tmp/$(basename "$OGLOGFILE")"
} }
function checkDependencies() { function checkDependencies() {
echoAndLog "Checking dependencies..." echoAndLog "Checking dependencies..."
# Lista de dependencias # Lista de dependencias
local DEPENDENCIES=(php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath composer unzip apache2 libapache2-mod-php) local DEPENDENCIES=(
php
php-cli
php-fpm
php-json
php-pdo
php-mysql
php-zip
php-gd
php-mbstring
php-curl
php-xml
php-pear
php-bcmath
composer
unzip
apache2
libapache2-mod-php
)
# Comprobar cada dependencia # Comprobar cada dependencia
for dep in "${DEPENDENCIES[@]}"; do for dep in "${DEPENDENCIES[@]}"; do
if ! dpkg -s $dep >/dev/null 2>&1; then if ! dpkg -s "$dep" >/dev/null 2>&1; then
echoAndLog "$dep is not installed. Installing..." echoAndLog "$dep is not installed. Installing..."
sudo apt-get install -y $dep sudo apt-get install -y "$dep"
else else
echoAndLog "$dep is already installed." echoAndLog "$dep is already installed."
fi fi
@ -74,11 +97,9 @@ function checkDependencies() {
echoAndLog "Dependencies checked." echoAndLog "Dependencies checked."
} }
# Función para instalar los paquetes necesarios para KEA-DHCP # Función para instalar los paquetes necesarios para KEA-DHCP
install_kea() { install_kea() {
sudo apt-get install -y isc-kea-common isc-kea-ctrl-agent isc-kea-dhcp4-server isc-kea-dhcp6-server isc-kea-admin sudo apt-get install -y isc-kea-common isc-kea-ctrl-agent isc-kea-dhcp4-server isc-kea-dhcp6-server isc-kea-admin
} }
# Función para instalar Composer # Función para instalar Composer
@ -87,7 +108,6 @@ install_composer() {
sudo mv composer.phar /usr/local/bin/composer sudo mv composer.phar /usr/local/bin/composer
} }
# Función para instalar Swagger UI # Función para instalar Swagger UI
install_swagger() { install_swagger() {
sudo apt-get install -y unzip sudo apt-get install -y unzip
@ -96,32 +116,29 @@ install_swagger() {
sudo mv /var/www/html/swagger-ui-master /var/www/html/swagger-ui sudo mv /var/www/html/swagger-ui-master /var/www/html/swagger-ui
} }
# Obtiene el código fuente del proyecto desde el repositorio de GitHub. # Obtiene el código fuente del proyecto desde el repositorio de GitHub.
function downloadCode() function downloadCode() {
{ if [ $# -ne 1 ]; then
if [ $# -ne 1 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters"
errorAndLog "${FUNCNAME}(): invalid number of parameters" exit 1
exit 1 fi
fi
local url="$1" local url="$1"
echoAndLog "${FUNCNAME}(): downloading code from '$url'..." echoAndLog "${FUNCNAME}(): downloading code from '$url'..."
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new" git archive --remote=$url --format zip --output opengnsys.zip --prefix=opengnsys/ $BRANCH && unzip opengnsys.zip GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new" git archive --remote="$url" --format zip --output opengnsys.zip --prefix=opengnsys/ "$BRANCH" && unzip opengnsys.zip
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error getting OpenGnsys code from $url" errorAndLog "${FUNCNAME}(): error getting OpenGnsys code from $url"
return 1 return 1
fi fi
rm -f opengnsys.zip rm -f opengnsys.zip
echoAndLog "${FUNCNAME}(): code was downloaded" echoAndLog "${FUNCNAME}(): code was downloaded"
return 0 return 0
} }
# Crea la estructura base de la instalación de opengnsys # Crea la estructura base de la instalación de opengnsys
function createDirs() function createDirs() {
{
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters" errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1 exit 1
@ -131,70 +148,59 @@ function createDirs()
# Crear estructura de directorios. # Crear estructura de directorios.
echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
mkdir -p $path_opengnsys_base mkdir -p "$path_opengnsys_base"/{bin,config,docs,public,src,etc/kea/backup,templates,var/{cache,log},vendor}
mkdir -p $path_opengnsys_base/bin
mkdir -p $path_opengnsys_base/config
mkdir -p $path_opengnsys_base/docs # Swagger documentation
mkdir -p $path_opengnsys_base/public
mkdir -p $path_opengnsys_base/src
mkdir -p $path_opengnsys_base/etc/kea/backup
mkdir -p $path_opengnsys_base/templates
mkdir -p $path_opengnsys_base/var/{cache,log}
mkdir -p $path_opengnsys_base/vendor
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
return 1 return 1
fi fi
# Crear usuario ficticio. # Crear usuario ficticio.
if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then if id -u "$OPENGNSYS_CLIENT_USER" &>/dev/null; then
echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created" echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created"
else else
echoAndLog "${FUNCNAME}(): creating OpenGnsys user" echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
useradd $OPENGNSYS_CLIENT_USER 2>/dev/null useradd "$OPENGNSYS_CLIENT_USER" 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error creating OpenGnsys user" errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
return 1 return 1
fi fi
fi fi
# Mover el fichero de registro de instalación al directorio de logs.
echoAndLog "${FUNCNAME}(): moving installation log file"
mv "$LOG_FILE" "$path_opengnsys_base/var/log" && LOG_FILE="$OGLOGFILE"
chmod 777 "$LOG_FILE"
sudo chmod -R 777 "$path_opengnsys_base/etc"
# Mover el fichero de registro de instalación al directorio de logs. # Mover el fichero de registro de instalación al directorio de logs.
echoAndLog "${FUNCNAME}(): moving installation log file" echoAndLog "${FUNCNAME}(): moving installation log file"
mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$OGLOGFILE touch "$path_opengnsys_base/var/log/dev.log"
chmod 777 $LOG_FILE chmod 777 "$path_opengnsys_base/var/log/dev.log"
sudo chmod -R 777 $path_opengnsys_base/etc
# Mover el fichero de registro de instalación al directorio de logs.
echoAndLog "${FUNCNAME}(): moving installation log file"
touch $path_opengnsys_base/var/log/dev.log
chmod 777 $path_opengnsys_base/var/log/dev.log
echoAndLog "${FUNCNAME}(): directory paths created" echoAndLog "${FUNCNAME}(): directory paths created"
return 0 return 0
# Cambiar permisos de usuario
echoAndLog "Changing user permission" echoAndLog "Changing user permission"
chown -R $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET chown -R "$OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER" "$INSTALL_TARGET"
# Copia de antemano .env ya que es necesario para montar el esqueleto de symfony # Copiar .env
cp -a $WORKDIR/ogdhcp/.env "${path_opengnsys_base}/.env" cp -a "$WORKDIR/ogdhcp/.env" "${path_opengnsys_base}/.env"
} }
function create_ogdhcp_project { function create_ogdhcp_project {
# Cambia al usuario ogdhcp y crea el proyecto Symfony # Cambia al usuario ogdhcp y crea el proyecto Symfony
local path_opengnsys_base="$1" local path_opengnsys_base="$1"
composer create-project symfony/website-skeleton $path_opengnsys_base composer create-project symfony/website-skeleton "$path_opengnsys_base"
pushd $path_opengnsys_base pushd "$path_opengnsys_base" || return
# Elimina el archivo composer.lock # Elimina el archivo composer.lock
rm composer.lock rm composer.lock
popd popd || return
echoAndLog "Esqueleto de la aplicación creado y archivo composer.lock eliminado." echoAndLog "Esqueleto de la aplicación creado y archivo composer.lock eliminado."
} }
function copyServerFiles () function copyServerFiles() {
{
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters" errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1 exit 1
@ -204,33 +210,35 @@ function copyServerFiles ()
# Lista de ficheros y directorios origen y de directorios destino. # Lista de ficheros y directorios origen y de directorios destino.
local SOURCES=( local SOURCES=(
config \ config
#public \ #public
src \ src
etc \ etc
templates \ templates
tests \ tests
vendor \ vendor
.env \ .env
composer.json \ composer.json
composer.lock \ composer.lock
phpunit.xml.dist \ phpunit.xml.dist
symfony.lock ) symfony.lock
)
local TARGETS=( local TARGETS=(
config \ config
#public \ #public
src \ src
etc \ etc
templates \ templates
tests \ tests
vendor \ vendor
.env \ .env
composer.json \ composer.json
composer.lock \ composer.lock
phpunit.xml.dist \ phpunit.xml.dist
symfony.lock ) symfony.lock
)
if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then if [ "${#SOURCES[@]}" != "${#TARGETS[@]}" ]; then
errorAndLog "${FUNCNAME}(): inconsistent number of array items" errorAndLog "${FUNCNAME}(): inconsistent number of array items"
exit 1 exit 1
fi fi
@ -238,34 +246,33 @@ function copyServerFiles ()
# Copiar ficheros. # Copiar ficheros.
echoAndLog "${FUNCNAME}(): copying files to server directories" echoAndLog "${FUNCNAME}(): copying files to server directories"
pushd $WORKDIR/ogdhcp pushd "$WORKDIR/ogdhcp" || return
local i local i
for (( i = 0; i < ${#SOURCES[@]}; i++ )); do for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
if [ -f "${SOURCES[$i]}" ]; then if [ -f "${SOURCES[$i]}" ]; then
echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
cp -a "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}" cp -a "${SOURCES[$i]}" "$path_opengnsys_base/${TARGETS[$i]}"
elif [ -d "${SOURCES[$i]}" ]; then elif [ -d "${SOURCES[$i]}" ]; then
echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}" cp -a "${SOURCES[$i]}"/* "$path_opengnsys_base/${TARGETS[$i]}"
else else
warningAndLog "Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" warningAndLog "Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
fi fi
done done
echoAndLog "Changing user permission" echoAndLog "Changing user permission"
chown -R $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET chown -R "$OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER" "$INSTALL_TARGET"
popd || return
popd
} }
function downloadComposer() { function downloadComposer() {
echoAndLog "Downloading composer.phar..." echoAndLog "Downloading composer.phar..."
# Crear el directorio de trabajo si no existe # Crear el directorio de trabajo si no existe
mkdir -p $WORKDIR/ogdhcp/bin mkdir -p "$WORKDIR/ogdhcp/bin" || return
# Cambiar al directorio de trabajo # Cambiar al directorio de trabajo
pushd $WORKDIR/ogdhcp/bin pushd "$WORKDIR/ogdhcp/bin" || return
# Descargar composer.phar # Descargar composer.phar
curl -sS https://getcomposer.org/installer | php curl -sS https://getcomposer.org/installer | php
@ -278,20 +285,20 @@ function downloadComposer() {
fi fi
# Crear el directorio de destino si no existe # Crear el directorio de destino si no existe
mkdir -p /opt/ogdhcp/bin mkdir -p "/opt/ogdhcp/bin" || return
# Mover composer.phar a /opt/ogdhcp/bin # Mover composer.phar a /opt/ogdhcp/bin
mv composer.phar /opt/ogdhcp/bin/ mv composer.phar "/opt/ogdhcp/bin/"
# Comprobar si el movimiento fue exitoso # Comprobar si el movimiento fue exitoso
if [ ! -f /opt/ogdhcp/bin/composer.phar ]; then if [ ! -f "/opt/ogdhcp/bin/composer.phar" ]; then
errorAndLog "Failed to move composer.phar to /opt/ogdhcp/bin" errorAndLog "Failed to move composer.phar to /opt/ogdhcp/bin"
popd popd
return 1 return 1
fi fi
# Volver al directorio original # Volver al directorio original
popd popd || return
echoAndLog "composer.phar downloaded and moved to /opt/ogdhcp/bin" echoAndLog "composer.phar downloaded and moved to /opt/ogdhcp/bin"
return 0 return 0
@ -301,10 +308,10 @@ function runComposer() {
echoAndLog "Running composer.phar to install dependencies..." echoAndLog "Running composer.phar to install dependencies..."
# Cambiar al directorio donde está composer.phar # Cambiar al directorio donde está composer.phar
pushd /opt/ogdhcp/bin pushd /opt/ogdhcp/bin || return
# Ejecutar composer.phar # Ejecutar composer.phar
sudo -u $OPENGNSYS_CLIENT_USER php composer.phar install sudo -u "$OPENGNSYS_CLIENT_USER" php composer.phar install
# Comprobar si la ejecución fue exitosa # Comprobar si la ejecución fue exitosa
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -314,11 +321,12 @@ function runComposer() {
fi fi
# Volver al directorio original # Volver al directorio original
popd popd || return
echoAndLog "composer.phar ran successfully and dependencies were installed" echoAndLog "composer.phar ran successfully and dependencies were installed"
return 0 return 0
} }
function install_swagger_ui { function install_swagger_ui {
# Define la URL del archivo de Swagger UI que quieres descargar # Define la URL del archivo de Swagger UI que quieres descargar
swagger_ui_url="https://github.com/swagger-api/swagger-ui/archive/refs/heads/master.zip" swagger_ui_url="https://github.com/swagger-api/swagger-ui/archive/refs/heads/master.zip"
@ -330,44 +338,26 @@ function install_swagger_ui {
destination_path="/opt/ogdhcp/public" destination_path="/opt/ogdhcp/public"
# Crea los directorios si no existen # Crea los directorios si no existen
mkdir -p $swagger_ui_path mkdir -p "$swagger_ui_path"
mkdir -p $destination_path mkdir -p "$destination_path"
# Descarga el archivo de Swagger UI # Descarga el archivo de Swagger UI
wget $swagger_ui_url -O /tmp/swagger-ui.zip wget "$swagger_ui_url" -O /tmp/swagger-ui.zip
# Descomprime el archivo de Swagger UI en la ruta especificada # Descomprime el archivo de Swagger UI en la ruta especificada
unzip /tmp/swagger-ui.zip -d $swagger_ui_path unzip /tmp/swagger-ui.zip -d "$swagger_ui_path"
# Copia los archivos de Swagger UI al directorio de destino # Copia los archivos de Swagger UI al directorio de destino
cp -r $swagger_ui_path/swagger-ui-master/dist/* $destination_path cp -r "$swagger_ui_path"/swagger-ui-master/dist/* "$destination_path"
# Elimina el archivo descargado y el directorio temporal # Elimina el archivo descargado y el directorio temporal
rm /tmp/swagger-ui.zip rm /tmp/swagger-ui.zip
rm -r $swagger_ui_path rm -r "$swagger_ui_path"
/opt/ogdhcp/vendor/bin/openapi /opt/ogdhcp/src/DhcpBundle/Controller/ -o /opt/ogdhcp/public/swagger.json /opt/ogdhcp/vendor/bin/openapi /opt/ogdhcp/src/DhcpBundle/Controller/ -o "$destination_path/swagger.json"
echo "Swagger UI instalado en $destination_path." echo "Swagger UI instalado en $destination_path."
} }
create_kea_source_list() { function installWebConsoleApacheConf() {
# Comprobar si el sistema operativo es Ubuntu 18.04
if [[ "$(lsb_release -rs)" == "18.04" ]]; then
echo "Creating isc-kea-2-0.list file..."
# Crear el archivo isc-kea-2-0.list
echo "
deb [signed-by=/usr/share/keyrings/isc-kea-2-0-archive-keyring.gpg] https://dl.cloudsmith.io/public/isc/kea-2-0/deb/ubuntu jammy main
deb-src [signed-by=/usr/share/keyrings/isc-kea-2-0-archive-keyring.gpg] https://dl.cloudsmith.io/public/isc/kea-2-0/deb/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/isc-kea-2-0.list
echo "File created successfully."
else
echo "This script is only for Ubuntu 18.04."
fi
}
function installWebConsoleApacheConf()
{
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters" errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1 exit 1
@ -375,35 +365,35 @@ function installWebConsoleApacheConf()
local path_opengnsys_base="$1" local path_opengnsys_base="$1"
local path_apache2_confd="$2" local path_apache2_confd="$2"
local OGHDPCDIR=${path_opengnsys_base}/public local OGHDPCDIR="${path_opengnsys_base}/public"
local sockfile local sockfile
if [ ! -d $path_apache2_confd ]; then if [ ! -d "$path_apache2_confd" ]; then
errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
return 1 return 1
fi fi
mkdir -p $path_apache2_confd/{sites-available,sites-enabled} mkdir -p "$path_apache2_confd/{sites-available,sites-enabled}"
echoAndLog "${FUNCNAME}(): creating apache2 config file.." echoAndLog "${FUNCNAME}(): creating apache2 config file.."
# Avtivar PHP-FPM. # Activar PHP-FPM.
echoAndLog "${FUNCNAME}(): configuring PHP-FPM" echoAndLog "${FUNCNAME}(): configuring PHP-FPM"
service=$PHPFPMSERV service="$PHPFPMSERV"
$ENABLESERVICE; $STARTSERVICE $ENABLESERVICE; $STARTSERVICE
sockfile=$(find /run/php -name "php*.sock" -type s -print 2>/dev/null | tail -1) sockfile=$(find /run/php -name "php*.sock" -type s -print 2>/dev/null | tail -1)
# Activar módulos de Apache. # Activar módulos de Apache.
$APACHEENABLEMODS $APACHEENABLEMODS
# Genera configuración de consola web a partir del fichero plantilla. # Generar configuración de consola web a partir del archivo de plantilla.
if [ -n "$sockfile" ]; then if [ -n "$sockfile" ]; then
sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \ sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \
-e "s,proxy:fcgi:.*,proxy:unix:${sockfile%% *}|fcgi://localhost\",g" \ -e "s,proxy:fcgi:.*,proxy:unix:${sockfile%% *}|fcgi://localhost\",g" \
$WORKDIR/ogdhcp/etc/apache.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf "$WORKDIR/ogdhcp/etc/apache.conf.tmpl" > "$path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf"
else else
sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \ sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \
$WORKDIR/ogdhcp/server/etc/apache.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf "$WORKDIR/ogdhcp/server/etc/apache.conf.tmpl" > "$path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf"
fi fi
$APACHEENABLEOG $APACHEENABLEOG
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -411,50 +401,44 @@ function installWebConsoleApacheConf()
return 1 return 1
fi fi
echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
service=$APACHESERV service="$APACHESERV"
$ENABLESERVICE; $STARTSERVICE $ENABLESERVICE; $STARTSERVICE
return 0 return 0
} }
##################################################################### #####################################################################
####### Algunas funciones útiles de propósito general: ####### Algunas funciones útiles de propósito general:
##################################################################### #####################################################################
function getDateTime() # Obtiene la fecha y hora actual en el formato especificado
{ function getDateTime() {
date "+%Y%m%d-%H%M%S" date "+%Y%m%d-%H%M%S"
} }
# Escribe a fichero y muestra por pantalla # Escribe un mensaje en el archivo de registro y lo muestra por pantalla
function echoAndLog() function echoAndLog() {
{ local DATETIME=$(getDateTime)
local DATETIME=`getDateTime` echo "$1"
echo "$1" echo "$DATETIME;$SSH_CLIENT;$1" >> "$LOG_FILE"
echo $LOG_FILE
echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
} }
# Escribe a fichero y muestra mensaje de error # Escribe un mensaje de error en el archivo de registro y lo muestra por pantalla
function errorAndLog() function errorAndLog() {
{ local DATETIME=$(getDateTime)
local DATETIME=`getDateTime` echo "ERROR: $1"
echo "ERROR: $1" echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> "$LOG_FILE"
echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
} }
# Escribe a fichero y muestra mensaje de aviso # Escribe un mensaje de advertencia en el archivo de registro y lo muestra por pantalla
function warningAndLog() function warningAndLog() {
{ local DATETIME=$(getDateTime)
local DATETIME=`getDateTime` echo "Warning: $1"
echo "Warning: $1" echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> "$LOG_FILE"
echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> $LOG_FILE
} }
########################################################################## ##########################################################################
################################main###################################### ################################main######################################
# Sólo ejecutable por usuario root # Sólo ejecutable por usuario root
if [ "$(whoami)" != 'root' ]; then if [ "$(whoami)" != 'root' ]; then
echo "ERROR: this program must run under root privileges!!" echo "ERROR: this program must run under root privileges!!"
@ -467,7 +451,7 @@ echoAndLog "OpenGnsys installation begins at $(date)"
mkdir -p $WORKDIR mkdir -p $WORKDIR
pushd $WORKDIR pushd $WORKDIR
create_kea_source_list
checkDependencies checkDependencies
install_kea install_kea
# Si es necesario, descarga el repositorio de código en directorio temporal # Si es necesario, descarga el repositorio de código en directorio temporal
@ -523,4 +507,3 @@ sudo apt-get update
# git clone <URL del repositorio de ogDhcp> # git clone <URL del repositorio de ogDhcp>
# cd <directorio de ogDhcp> # cd <directorio de ogDhcp>
# composer install # composer install