From e7d99be6c232e692448e9a2edde013c13104f019 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 Feb 2025 12:15:26 +0000 Subject: [PATCH] First version of debian packge for oggui --- DEBIAN/changelog | 5 ++++ DEBIAN/control | 9 +++++++ DEBIAN/copyright | 21 +++++++++++++++++ DEBIAN/postinst | 40 ++++++++++++++++++++++++++++++++ DEBIAN/postrm | 32 +++++++++++++++++++++++++ DEBIAN/preinst | 15 ++++++++++++ bin/start-oggui.sh | 34 +++++++++++++++++++++++++++ etc/nginx/oggui.conf | 19 +++++++++++++++ etc/systemd/system/oggui.service | 14 +++++++++++ var/lib/oggui/oggui.config.hash | 1 + 10 files changed, 190 insertions(+) create mode 100644 DEBIAN/changelog create mode 100644 DEBIAN/control create mode 100644 DEBIAN/copyright create mode 100644 DEBIAN/postinst create mode 100755 DEBIAN/postrm create mode 100644 DEBIAN/preinst create mode 100644 bin/start-oggui.sh create mode 100644 etc/nginx/oggui.conf create mode 100644 etc/systemd/system/oggui.service create mode 100644 var/lib/oggui/oggui.config.hash diff --git a/DEBIAN/changelog b/DEBIAN/changelog new file mode 100644 index 0000000..65d538d --- /dev/null +++ b/DEBIAN/changelog @@ -0,0 +1,5 @@ +oggui (1.0) unstable; urgency=low + + * Initial release. + + -- Your Name Thu, 01 Jan 1970 00:00:00 +0000 diff --git a/DEBIAN/control b/DEBIAN/control new file mode 100644 index 0000000..3bd121f --- /dev/null +++ b/DEBIAN/control @@ -0,0 +1,9 @@ +Package: oggui +Version: %%VERSION%% +Section: base +Priority: optional +Architecture: all +Depends: nginx , npm , nodejs +Maintainer: Nicolas Arenas +Description: Description of the ogcore package + This is a longer description of the ogcore package. diff --git a/DEBIAN/copyright b/DEBIAN/copyright new file mode 100644 index 0000000..97ef204 --- /dev/null +++ b/DEBIAN/copyright @@ -0,0 +1,21 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: ogcore +Source: + +Files: * +Copyright: 2023 Your Name +License: GPL-3+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + . + This package 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 General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301 USA. diff --git a/DEBIAN/postinst b/DEBIAN/postinst new file mode 100644 index 0000000..393ab12 --- /dev/null +++ b/DEBIAN/postinst @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e + +# Asegurarse de que el usuario exista +USER="opengnsys" +HASH_FILE="/opt/opengnsys/oggui/var/lib/oggui/oggui.config.hash" +CONFIG_FILE="/opt/opengnsys/oggui/src/.env" + +# Provisionar base de datos si es necesario en caso de instalación. + + +# Detectar si es una instalación nueva o una actualización +if [ "$1" = "configure" ] && [ -z "$2" ]; then + cd /opt/opengnsys/oggui/src/ + npm install -g @angular/cli + npm install + /usr/local/bin/ng build --base-href=/ --output-path=dist/oggui --optimization=true --configuration=production --localize=false + cp -pr /opt/opengnsys/oggui/src/dist/oggui/browser/* /opt/opengnsys/oggui/browser/ + md5sum "$CONFIG_FILE" > "$HASH_FILE" + ln -s /opt/opengnsys/oggui/etc/systemd/system/oggui.service /etc/systemd/system/oggui.service + systemctl daemon-reload + systemctl enable oggui +elif [ "$1" = "configure" ] && [ -n "$2" ]; then + cd /opt/opengnsys/oggui + echo "Actualización desde la versión $2" +fi + +# Cambiar la propiedad de los archivos al usuario especificado +chown opengnsys:www-data /opt/opengnsys/ +chown -R opengnsys:www-data /opt/opengnsys/oggui +# Install http server stuff +ln -s /opt/opengnsys/oggui/etc/nginx/oggui.conf /etc/nginx/sites-enabled/oggui.conf +# Reiniciar servicios si es necesario +# systemctl restart nombre_del_servicio + +systemctl daemon-reload +systemctl restart nginx + +exit 0 diff --git a/DEBIAN/postrm b/DEBIAN/postrm new file mode 100755 index 0000000..6581225 --- /dev/null +++ b/DEBIAN/postrm @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + + +NGINX_FILE="/etc/nginx/sites-enabled/oggui.conf" +UNIT_FILE="/etc/systemd/system/oggui.service" + + +case "$1" in + remove) + echo "El paquete se está desinstalando..." + # Aquí puedes hacer limpieza de archivos o servicios + if [ -L "$NGINX_FILE" ]; then + rm -f "$NGINX_FILE" + systemctl restart nginx + fi + if [ -L "$UNIT_FILE" ]; then + rm -f "$UNIT_FILE" + systemctl daemon-reload + fi + ;; + purge) + echo "Eliminando configuración residual..." + ;; + + upgrade) + echo "Actualizando paquete..." + ;; +esac + +exit 0 diff --git a/DEBIAN/preinst b/DEBIAN/preinst new file mode 100644 index 0000000..dc60472 --- /dev/null +++ b/DEBIAN/preinst @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Asegurarse de que el usuario exista +USER="opengnsys" +HOME_DIR="/opt/opengnsys" +if id "$USER" &>/dev/null; then + echo "El usuario $USER ya existe." +else + echo "Creando el usuario $USER con home en $HOME_DIR." + useradd -m -d "$HOME_DIR" -s /bin/bash "$USER" +fi + +exit 0 \ No newline at end of file diff --git a/bin/start-oggui.sh b/bin/start-oggui.sh new file mode 100644 index 0000000..525c90b --- /dev/null +++ b/bin/start-oggui.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +CONFIG_FILE="/opt/opengnsys/oggui/src/.env" +HASH_FILE="/opt/opengnsys/oggui/var/lib/oggui/oggui.config.hash" +APP_DIR="/opt/opengnsys/oggui/browser" +SRC_DIR="/opt/opengnsys/oggui/src" +COMPILED_DIR=$SRC_DIR/dist +NGINX_SERVICE="nginx" + +# Verificar si el archivo de configuración cambió +if [ -f "$CONFIG_FILE" ] && [ -f "$HASH_FILE" ]; then + OLD_HASH=$(cat "$HASH_FILE") + NEW_HASH=$(md5sum "$CONFIG_FILE") + + if [ "$OLD_HASH" != "$NEW_HASH" ]; then + echo "🔄 Cambios detectados en $CONFIG_FILE, recompilando Angular..." + cd "$SRC_DIR" + npm install -g @angular/cli + npm install + /usr/local/bin/ng build --base-href=/ --output-path=dist/oggui --optimization=true --configuration=production --localize=false + md5sum "$CONFIG_FILE" > "$HASH_FILE" + exit 0 + else + echo "No hay cambios en $CONFIG_FILE, no es necesario recompilar." + exit 0 + fi +else + echo "Archivo de configuración no encontrado o sin hash previo. No se recompilará." + exit 1 +fi + +# Iniciar Nginx +systemctl restart "$NGINX_SERVICE" \ No newline at end of file diff --git a/etc/nginx/oggui.conf b/etc/nginx/oggui.conf new file mode 100644 index 0000000..e036513 --- /dev/null +++ b/etc/nginx/oggui.conf @@ -0,0 +1,19 @@ +server { + listen 4200; + server_name localhost; + + root /opt/opengnsys/oggui/browser; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + # Manejo de archivos estáticos + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + try_files $uri =404; + } + + # Configuración para evitar problemas con rutas de Angular + error_page 404 /index.html; +} \ No newline at end of file diff --git a/etc/systemd/system/oggui.service b/etc/systemd/system/oggui.service new file mode 100644 index 0000000..8a75041 --- /dev/null +++ b/etc/systemd/system/oggui.service @@ -0,0 +1,14 @@ +[Unit] +Description=Aplicación Angular con Nginx +After=network.target + +[Service] +Type=simple +ExecStart=/opt/opengnsys/oggui/bin/start-oggui.sh +Restart=always +User=www-data +WorkingDirectory=/var/www/mi-aplicacion +Environment=NODE_ENV=production + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/var/lib/oggui/oggui.config.hash b/var/lib/oggui/oggui.config.hash new file mode 100644 index 0000000..5111af2 --- /dev/null +++ b/var/lib/oggui/oggui.config.hash @@ -0,0 +1 @@ +986d3c82e05e6ac6d5355aafa1f65148 .env