diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c8332b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +### Debian packaging +debian/ogrepository +debian/*.substvars +debian/*.log +debian/.debhelper/ +debian/files +debian/*.debhelper +debian/*.debhelper.log +debian/debhelper-build-stamp diff --git a/Jenkins/Jenkinsfile-deb-pkg b/Jenkins/Jenkinsfile-deb-pkg new file mode 100644 index 0000000..9a87195 --- /dev/null +++ b/Jenkins/Jenkinsfile-deb-pkg @@ -0,0 +1,77 @@ +@Library('jenkins-shared-library') _ +pipeline { + agent { + label 'jenkins-slave' + } + environment { + DEBIAN_FRONTEND = 'noninteractive' + DEFAULT_DEV_NAME = 'Opengnsys Team' + DEFAULT_DEV_EMAIL = 'opengnsys@qindel.com' + } + options { + skipDefaultCheckout() + } + parameters { + string(name: 'DEV_NAME', defaultValue: '', description: 'Nombre del desarrollador') + string(name: 'DEV_EMAIL', defaultValue: '', description: 'Email del desarrollador') + } + stages { + stage('Prepare Workspace') { + steps { + script { + env.BUILD_DIR = "${WORKSPACE}/ogrepository" + sh "mkdir -p ${env.BUILD_DIR}" + } + } + } + + stage('Checkout') { + steps { + dir("${env.BUILD_DIR}") { + checkout scm + } + } + } + + stage('Generate Changelog') { + when { + expression { + return env.TAG_NAME != null + } + } + steps { + script { + def devName = params.DEV_NAME ? params.DEV_NAME : env.DEFAULT_DEV_NAME + def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL + + generateDebianChangelog(env.BUILD_DIR, devName, devEmail) + } + } + } + + stage('Build') { + steps { + dir("${env.BUILD_DIR}") { + sh ''' + dpkg-buildpackage -us -uc + mkdir -p ../artifacts && mv ../*.deb ../*.changes ../*.buildinfo ../artifacts/ + ssh aptly@172.17.8.68 "rm -rf /var/tmp/opengnsys/debian-repo && mkdir -p /var/tmp/opengnsys/debian-repo" + scp -r ../artifacts/* aptly@172.17.8.68:/var/tmp/opengnsys/debian-repo/ + ''' + } + } + } + } + post { + always { + notifyBuildStatus('narenas@qindel.com') + } + } +} +// stage ('Publish to Debian Repository') { +// agent { label 'debian-repo' } +// steps { +// sh "aptly repo add opengnsys-devel /var/tmp/opengnsys/debian-repo/*.deb" +// } +// } + diff --git a/debian/README b/debian/README new file mode 100644 index 0000000..62eec21 --- /dev/null +++ b/debian/README @@ -0,0 +1,6 @@ +The Debian Package ogrepository +---------------------------- + + + + -- vagrant Thu, 06 Mar 2025 07:16:52 +0000 diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..1ec9a83 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +ogrepository for Debian +---------------------- + + + + -- vagrant Thu, 06 Mar 2025 07:16:52 +0000 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..15d5dba --- /dev/null +++ b/debian/README.source @@ -0,0 +1,10 @@ +ogrepository for Debian +---------------------- + + + + + + -- vagrant Thu, 06 Mar 2025 07:16:52 +0000 + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..a7337d9 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,14 @@ +ogrepository (1.0.0+deb-packages20250311-1) unstable; urgency=medium + + * First debian version + * Merge pull request 'refs #1530 - Add 'backupImage.py' and related endpoint' (#22) from add_python_scripts into main + * refs #1530 - Add 'backupImage.py' and related endpoint + * Merge pull request 'refs #1482 - Modify Paramiko SSH Client parameters' (#21) from add_python_scripts into main + * refs #1482 - Modify Paramiko SSH Client parameters + * Merge pull request 'add_python_scripts' (#20) from add_python_scripts into main + * refs #1444 - Modify API help + * refs #1444 - Modify transfers between repositories + * Merge pull request 'refs #1437 - Scripts corrections' (#19) from add_python_scripts into main + * refs #1437 - Scripts corrections + + -- Tu Nombre Tue, 11 Mar 2025 04:43:58 +0000 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..a33a545 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: ogrepository +Section: base +Priority: optional +Maintainer: Nicolas Arenas +Standards-Version: 4.5.0 +Build-Depends: debhelper-compat (= 12) + +Package: ogrepository +Architecture: all +Pre-Depends: debian-archive-keyring , debconf (>= 1.5.0), +Depends: ${misc:Depends}, git, python3, python3-pip, python3-flask, python3-paramiko, python3-psutil, python3-flasgger, samba, gunicorn, wakeonlan , lzop , partclone , qemu-utils , udpcast +Description: Ogrepsoitory Package + This package provides Ogrepsoitory service. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..0a91364 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,43 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Source: +Upstream-Name: ogrepository +Upstream-Contact: + +Files: + * +Copyright: + + +License: GPL-3.0+ + +Files: + debian/* +Copyright: + 2025 vagrant +License: GPL-3.0+ + +License: GPL-3.0+ + This program 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 program. If not, see . +Comment: + On Debian systems, the complete text of the GNU General + Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid picking licenses with terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. +# +# If you need, there are some extra license texts available in two places: +# /usr/share/debhelper/dh_make/licenses/ +# /usr/share/common-licenses/ diff --git a/debian/ogrepository.config b/debian/ogrepository.config new file mode 100755 index 0000000..300b466 --- /dev/null +++ b/debian/ogrepository.config @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +. /usr/share/debconf/confmodule + + +# Leer las variables de configuración + +db_input high opengnsys/ogrepository_ogrepoIp || true +db_input high opengnsys/ogrepository_ogcoreIp || true +db_input high opengnsys/ogrepository_sambaUser || true +db_input high opengnsys/ogrepository_sambaUserPass || true + +db_go diff --git a/debian/ogrepository.dirs b/debian/ogrepository.dirs new file mode 100644 index 0000000..becf1e5 --- /dev/null +++ b/debian/ogrepository.dirs @@ -0,0 +1,4 @@ +/opt/opengnsys/ogrepository/images_virtual +/opt/opengnsys/ogrepository/images +/opt/opengnsys/ogrepository/images_trash +/opt/opengnsys/ogrepository/log diff --git a/debian/ogrepository.install b/debian/ogrepository.install new file mode 100644 index 0000000..525da26 --- /dev/null +++ b/debian/ogrepository.install @@ -0,0 +1,8 @@ +api/* /opt/opengnsys/ogrepository/api/ +bin/* /opt/opengnsys/ogrepository/bin/ +etc/* /opt/opengnsys/ogrepository/etc/ +installer/files/ctorrent.sources /etc/apt/sources.list.d/ +installer/files/ogrepo-api.service /etc/systemd/system/ +installer/files/ogrepo-smb.conf /etc/samba/ +installer/ssh-keys/* /opt/opengnsys/ogrepository/etc/ + diff --git a/debian/ogrepository.postinst b/debian/ogrepository.postinst new file mode 100755 index 0000000..68bfb7a --- /dev/null +++ b/debian/ogrepository.postinst @@ -0,0 +1,116 @@ +#!/bin/sh + +set -e +set -x + +. /usr/share/debconf/confmodule + +# Cargar variables de configuración +db_get opengnsys/ogrepository_ogrepoIp +OGREPO_IP="$RET" +db_get opengnsys/ogrepository_ogcoreIp +OGCORE_IP="$RET" +db_get opengnsys/ogrepository_sambaUser +SAMBA_USER="$RET" +db_get opengnsys/ogrepository_sambaUserPass +SAMBA_PASS="$RET" + +# Asegurarse de que el usuario exista +USER="opengnsys" + + +# 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 + systemd-run --no-block /bin/bash -c " +sleep 10; +apt update -y; +for pkg in bittorrent bittornado ctorrent; do + if ! dpkg -l | grep -qw \"\$pkg\"; then + apt install -y \"\$pkg\" + fi +done +" + + sed -i "s/%%OGREPOSITORY_USER%%/$SAMBA_USER/g" /etc/systemd/system/ogrepo-api.service + sed -i "s/%%OGREPOSITORY_USER%%/$SAMBA_USER/g" /etc/samba/ogrepo-smb.conf + + # Install ssh keys on opengnsys user + # Get opengnsys home directory + OPENGNSYS_HOME=$(getent passwd opengnsys | cut -d: -f6) + # Create .ssh directory + mkdir -p $OPENGNSYS_HOME/.ssh + # Copy ssh keys + cp /opt/opengnsys/ogrepository/etc/opengnsys $OPENGNSYS_HOME/.ssh/id_ed25519 + cp /opt/opengnsys/ogrepository/etc/opengnsys.pub $OPENGNSYS_HOME/.ssh/id_ed25519.pub + + if [ -f /etc/samba/smb.conf ]; then + dpkg-divert --package ogrepository --add --rename --divert /etc/samba/smb.conf.orig /etc/samba/smb.conf + fi + # Incluir el archivo de configuración de samba si no está incluido ya + if ! grep -q "include = /etc/samba/ogrepo-smb.conf" /etc/samba/smb.conf; then + echo "include = /etc/samba/ogrepo-smb.conf" >> /etc/samba/smb.conf + fi + + (echo "$SAMBA_PASS"; echo "$SAMBA_PASS") | smbpasswd -a $SAMBA_USER + + # Configure Repo + + cp /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg.tmpl /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg + sed -i "s/SERVERIP/$OGREPO_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg + sed -i "s/OGCOREIP/$OGCORE_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg + +elif [ "$1" = "configure" ] && [ -n "$2" ]; then + 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/ogrepository + +# Install http server stuff +# Reiniciar servicios si es necesario +# systemctl restart nombre_del_servicio + +systemctl daemon-reload +systemctl enable ogrepo-api +systemctl restart ogrepo-api +systemctl restart smbd + +# echo "ogrepository-trigger" > /var/lib/dpkg/triggers/ogrepository.trigger +# POST_INVOKE_SCRIPT="/var/lib/dpkg/info/ogrepository.trigger" + +# echo "Registrando post-invoke para instalación de paquetes adicionales..." + +# cat < "$POST_INVOKE_SCRIPT" +# #!/bin/sh +# set -e + +# echo "Ejecutando post-trigger: Instalando bittorrent, bittornado y ctorrent..." + +# export DEBIAN_FRONTEND=noninteractive +# apt-get update +# apt-get install -y bittorrent bittornado ctorrent + +# echo "Instalación de paquetes adicionales completada." + +# exit 0 +# EOF + +# chmod +x "$POST_INVOKE_SCRIPT" + +# # Intentar ejecutar el script ahora si no hay otro proceso de apt corriendo +# if ! pgrep -x "apt" > /dev/null; then +# echo "Ejecutando instalación de paquetes adicionales inmediatamente..." +# "$POST_INVOKE_SCRIPT" +# else +# echo "Apt está en uso, los paquetes se instalarán después." +# fi + +# find /opt/opengnsys/ogrepository -type f -name "*.py" -exec chmod +x {} \; + +# dpkg-trigger --by-package=ogrepository ogrepository-trigger + +exit 0 diff --git a/debian/ogrepository.postrm b/debian/ogrepository.postrm new file mode 100755 index 0000000..6581225 --- /dev/null +++ b/debian/ogrepository.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/ogrepository.preinst b/debian/ogrepository.preinst new file mode 100755 index 0000000..652cf8f --- /dev/null +++ b/debian/ogrepository.preinst @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +KEY_FILE="/usr/share/keyrings/debian-archive-buster-stable.gpg" +REPO_FILE="/etc/apt/sources.list.d/buster.list" + +# Asegurarse de que el usuario exista +USER="opengnsys" +HOME_DIR="/opt/opengnsys" +if id "$USER" >/dev/null 2>&1; 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 +echo "Añadiendo el repositorio de Debian Buster en $REPO_FILE..." + +# Crear el directorio si no existe +mkdir -p "$(dirname "$REPO_FILE")" + +# Crear el archivo de repositorio si no existe +if [ ! -f "$REPO_FILE" ]; then + echo "deb [signed-by=$KEY_FILE] http://ftp.de.debian.org/debian buster main" > "$REPO_FILE" +else + echo "El repositorio ya está configurado en $REPO_FILE" +fi + +exit 0 diff --git a/debian/ogrepository.prerm b/debian/ogrepository.prerm new file mode 100755 index 0000000..e991396 --- /dev/null +++ b/debian/ogrepository.prerm @@ -0,0 +1,60 @@ +#!/bin/bash + +set -e + +case "$1" in + remove|purge) + echo "Deteniendo y deshabilitando servicios..." + systemctl stop ogrepo-api || true + systemctl disable ogrepo-api || true + + systemctl stop smbd || true + systemctl stop nmbd || true + + # Restaurar configuración original de Samba si fue modificada + if [ -f /etc/samba/smb.conf.ogrepository ]; then + echo "Restaurando configuración original de Samba..." + mv /etc/samba/smb.conf.ogrepository /etc/samba/smb.conf + dpkg-divert --remove --rename /etc/samba/smb.conf + fi + + # Eliminar configuración específica de ogrepository en Samba + if grep -q "include = /etc/samba/ogrepo-smb.conf" /etc/samba/smb.conf; then + echo "Eliminando referencia a ogrepo-smb.conf en smb.conf..." + sed -i '/include = \/etc\/samba\/ogrepo-smb.conf/d' /etc/samba/smb.conf + fi + + # Eliminar usuario de Samba si es necesario + if pdbedit -L | grep -q "^$SAMBA_USER:"; then + echo "Eliminando usuario Samba $SAMBA_USER..." + smbpasswd -x "$SAMBA_USER" + fi + + # Eliminar archivos de configuración si se trata de una purga + if [ "$1" = "purge" ]; then + echo "Eliminando archivos de configuración..." + rm -rf /opt/opengnsys/ogrepository + rm -rf /etc/samba/ogrepo-smb.conf + rm -rf /etc/systemd/system/ogrepo-api.service + fi + + # Eliminar el script post-invoke si existe + if [ -f /var/lib/dpkg/info/ogrepository.post-invoke ]; then + echo "Eliminando script post-invoke..." + rm -f /var/lib/dpkg/info/ogrepository.post-invoke + fi + + echo "Limpieza completada." + ;; + + upgrade|deconfigure) + # No hacer nada en actualización o desconfiguración + ;; + + *) + echo "prerm llamado con un argumento desconocido '$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/ogrepository.templates b/debian/ogrepository.templates new file mode 100644 index 0000000..c6be411 --- /dev/null +++ b/debian/ogrepository.templates @@ -0,0 +1,19 @@ +Template: opengnsys/ogrepository_ogrepoIp +Type: string +Default: 127.0.0.1 +Description: IP del repositorio. + +Template: opengnsys/ogrepository_ogcoreIp +Default: 127.0.0.1 +Type: string +Description: IP del servidor OGCore. + +Template: opengnsys/ogrepository_sambaUser +Type: string +Default: opengnsys +Description: Usuario de Samba. + +Template: opengnsys/ogrepository_sambaUserPass +Type: password +Default: og +Description: Contraseña para el usuario de Samba. diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..f1d1d25 --- /dev/null +++ b/debian/rules @@ -0,0 +1,26 @@ +#!/usr/bin/make -f + +# See debhelper(7) (uncomment to enable). +# Output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# See FEATURE AREAS in dpkg-buildflags(1). +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# See ENVIRONMENT in dpkg-buildflags(1). +# Package maintainers to append CFLAGS. +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# Package maintainers to append LDFLAGS. +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + + +# dh_make generated override targets. +# This is an example for Cmake (see ). +#override_dh_auto_configure: +# dh_auto_configure -- \ +# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/installer/ssh-keys/opengnsys b/installer/ssh-keys/opengnsys new file mode 100644 index 0000000..4514194 --- /dev/null +++ b/installer/ssh-keys/opengnsys @@ -0,0 +1,7 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW +QyNTUxOQAAACBs7Wbqztq5ixPGFL+1DlTa0T6QUBMiLq6KxZnCJ5rofQAAAJD7Xj89+14/ +PQAAAAtzc2gtZWQyNTUxOQAAACBs7Wbqztq5ixPGFL+1DlTa0T6QUBMiLq6KxZnCJ5rofQ +AAAEC4UmYDisgl5jNR6SUwRA80k6Qc06cBHg1mW3+2NU6SfmztZurO2rmLE8YUv7UOVNrR +PpBQEyIurorFmcInmuh9AAAABm5vbmFtZQECAwQFBgc= +-----END OPENSSH PRIVATE KEY----- diff --git a/installer/ssh-keys/opengnsys.pub b/installer/ssh-keys/opengnsys.pub new file mode 100644 index 0000000..7edd74c --- /dev/null +++ b/installer/ssh-keys/opengnsys.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGztZurO2rmLE8YUv7UOVNrRPpBQEyIurorFmcInmuh9 noname