refs #170 Adds new directories to backup and changes logs permissions

pull/1/head
qindel 2024-01-25 15:04:07 +00:00
parent 62bf399b45
commit 7140b7c6b6
4 changed files with 72 additions and 60 deletions

View File

@ -50,7 +50,7 @@ function globalSetup ()
APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite" APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite"
PHPFPMSERV=php7.2-fpm PHPFPMSERV=php7.2-fpm
# Registro de incidencias. # Registro de incidencias.
OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log OGLOGFILE=$INSTALL_TARGET/var/log/${PROGRAMNAME%.sh}.log
LOG_FILE=/tmp/$(basename $OGLOGFILE) LOG_FILE=/tmp/$(basename $OGLOGFILE)
} }
@ -73,43 +73,7 @@ function checkDependencies() {
echoAndLog "Dependencies checked." echoAndLog "Dependencies checked."
} }
function checkDependencies() {
echoAndLog "Checking dependencies..."
# 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)
# Comprobar cada dependencia
for dep in "${DEPENDENCIES[@]}"; do
if ! dpkg -s $dep >/dev/null 2>&1; then
echoAndLog "$dep is not installed. Installing..."
sudo apt-get install -y $dep
else
echoAndLog "$dep is already installed."
fi
done
echoAndLog "Dependencies checked."
}
# Instalar dependencias para Symfony y Swagger
function install_symfony_swagger_dependencies() {
echoAndLog "Installing Symfony and Swagger dependencies..."
sudo apt-get update
sudo apt-get install -y 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
sudo apt-get install -y composer
sudo apt-get install -y unzip
echoAndLog "Symfony and Swagger dependencies installed."
}
# Instalar dependencias para Apache
function install_apache_dependencies() {
echoAndLog "Installing Apache dependencies..."
sudo apt-get update
sudo apt-get install -y apache2 libapache2-mod-php
echoAndLog "Apache dependencies installed."
}
# Función para instalar los paquetes necesarios para KEA-DHCP # Función para instalar los paquetes necesarios para KEA-DHCP
@ -117,24 +81,12 @@ 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 PHP y las extensiones necesarias para Symfony
install_php() {
sudo apt-get install -y 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
}
# Función para instalar Composer # Función para instalar Composer
install_composer() { install_composer() {
curl -sS https://getcomposer.org/installer | php curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer sudo mv composer.phar /usr/local/bin/composer
} }
# Función para instalar Symfony
install_symfony() {
composer global require symfony
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
}
# Función para instalar Swagger UI # Función para instalar Swagger UI
install_swagger() { install_swagger() {
@ -185,7 +137,7 @@ function createDirs()
mkdir -p $path_opengnsys_base/docs # Swagger documentation mkdir -p $path_opengnsys_base/docs # Swagger documentation
mkdir -p $path_opengnsys_base/public mkdir -p $path_opengnsys_base/public
mkdir -p $path_opengnsys_base/src mkdir -p $path_opengnsys_base/src
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/templates
mkdir -p $path_opengnsys_base/var/{cache,log} mkdir -p $path_opengnsys_base/var/{cache,log}
mkdir -p $path_opengnsys_base/vendor mkdir -p $path_opengnsys_base/vendor
@ -211,11 +163,33 @@ function createDirs()
echoAndLog "${FUNCNAME}(): moving installation log file" echoAndLog "${FUNCNAME}(): moving installation log file"
mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$OGLOGFILE mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$OGLOGFILE
chmod 777 $LOG_FILE chmod 777 $LOG_FILE
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
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
cp -a $WORKDIR/ogdhcp/.env "${path_opengnsys_base}/.env"
}
function create_ogdhcp_project {
# Cambia al usuario ogdhcp y crea el proyecto Symfony
local path_opengnsys_base="$1"
composer create-project symfony/website-skeleton $path_opengnsys_base
pushd $path_opengnsys_base
# Elimina el archivo composer.lock
rm composer.lock
popd
echoAndLog "Esqueleto de la aplicación creado y archivo composer.lock eliminado."
} }
@ -229,9 +203,9 @@ function copyServerFiles ()
local path_opengnsys_base="$1" local path_opengnsys_base="$1"
# Lista de ficheros y directorios origen y de directorios destino. # Lista de ficheros y directorios origen y de directorios destino.
local SOURCES=( bin \ local SOURCES=(
config \ config \
public \ #public \
src \ src \
etc \ etc \
templates \ templates \
@ -242,9 +216,9 @@ function copyServerFiles ()
composer.lock \ composer.lock \
phpunit.xml.dist \ phpunit.xml.dist \
symfony.lock ) symfony.lock )
local TARGETS=( bin \ local TARGETS=(
config \ config \
public \ #public \
src \ src \
etc \ etc \
templates \ templates \
@ -345,6 +319,37 @@ function runComposer() {
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 {
# 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"
# Define la ruta donde quieres descomprimir Swagger UI
swagger_ui_path="/tmp/swagger-ui"
# Define la ruta de destino para los archivos de Swagger UI
destination_path="/opt/ogdhcp/public"
# Crea los directorios si no existen
mkdir -p $swagger_ui_path
mkdir -p $destination_path
# Descarga el archivo de Swagger UI
wget $swagger_ui_url -O /tmp/swagger-ui.zip
# Descomprime el archivo de Swagger UI en la ruta especificada
unzip /tmp/swagger-ui.zip -d $swagger_ui_path
# Copia los archivos de Swagger UI al directorio de destino
cp -r $swagger_ui_path/swagger-ui-master/dist/* $destination_path
# Elimina el archivo descargado y el directorio temporal
rm /tmp/swagger-ui.zip
rm -r $swagger_ui_path
/opt/ogdhcp/vendor/bin/openapi /opt/ogdhcp/src/DhcpBundle/Controller/ -o /opt/ogdhcp/public/swagger.json
echo "Swagger UI instalado en $destination_path."
}
function installWebConsoleApacheConf() function installWebConsoleApacheConf()
{ {
@ -461,6 +466,11 @@ else
ln -fs "$(dirname $PROGRAMDIR)" ogdhcp ln -fs "$(dirname $PROGRAMDIR)" ogdhcp
fi fi
create_ogdhcp_project ${INSTALL_TARGET}
if [ $? -ne 0 ]; then
errorAndLog "Error while creating skeleton directory!"
exit 1
fi
# Arbol de directorios de OpenGnsys. # Arbol de directorios de OpenGnsys.
createDirs ${INSTALL_TARGET} createDirs ${INSTALL_TARGET}
@ -469,6 +479,7 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
# Copiar ficheros de servicios OpenGnsys Server. # Copiar ficheros de servicios OpenGnsys Server.
copyServerFiles ${INSTALL_TARGET} copyServerFiles ${INSTALL_TARGET}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -479,7 +490,7 @@ fi
downloadComposer downloadComposer
runComposer runComposer
install_swagger_ui
# Creando configuración de Apache. # Creando configuración de Apache.
installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then

1
ogdhcp Symbolic link
View File

@ -0,0 +1 @@
/home/qindel/ogdhcp

View File

@ -103,7 +103,7 @@ class DhcpController
* ) * )
* ) * )
* @OA\Get( * @OA\Get(
* path="/opengnsys3/rest/dhcp/subnet", * path="/opengnsys3/rest/dhcp/subnets",
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Devuelve todas las subredes", * description="Devuelve todas las subredes",
@ -117,7 +117,7 @@ class DhcpController
* description="Error al obtener las subredes", * description="Error al obtener las subredes",
* ) * )
* ) * )
* @Route("/opengnsys3/rest/dhcp/subnet", methods={"GET"}) * @Route("/opengnsys3/rest/dhcp/subnets", methods={"GET"})
*/ */
public function getSubnets(): JsonResponse public function getSubnets(): JsonResponse
{ {
@ -443,7 +443,7 @@ class DhcpController
* @OA\Property(property="address", type="string", example="172.30.4.11") * @OA\Property(property="address", type="string", example="172.30.4.11")
* ) * )
* @OA\Get( * @OA\Get(
* path="/opengnsys3/rest/dhcp/subnet/{subnetId}/host", * path="/opengnsys3/rest/dhcp/subnet/{subnetId}/hosts",
* summary="Get all hosts in a subnet", * summary="Get all hosts in a subnet",
* @OA\Parameter( * @OA\Parameter(
* name="subnetId", * name="subnetId",
@ -477,7 +477,7 @@ class DhcpController
* ) * )
* ) * )
* ) * )
* @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}/host", methods={"GET"}) * @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}/hosts", methods={"GET"})
*/ */
public function getHosts($subnetId): JsonResponse public function getHosts($subnetId): JsonResponse
{ {

View File

@ -81,7 +81,7 @@ class CurlKeaService
$config_text = json_encode($get_output[0]['arguments']); $config_text = json_encode($get_output[0]['arguments']);
$configurationParsed = str_replace('\\', '', $config_text); $configurationParsed = str_replace('\\', '', $config_text);
$backup_dir = '/opt/opengnsys/etc/kea/backup'; $backup_dir = '/opt/ogdhcp/etc/kea/backup';
if (!is_dir($backup_dir)) { if (!is_dir($backup_dir)) {
throw new Exception('El directorio de backup no existe'); throw new Exception('El directorio de backup no existe');
} }