From ecbba3d45eca0e498eb9858fc9e9a37b068a8b74 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 23 Jun 2025 09:57:10 +0200 Subject: [PATCH] refs #2282 Review errors in ogrepo update refs #2260 Change the way to install dependency refs #2260 Remove bittorrent dependency --- debian/control | 4 +-- debian/ogrepository.postinst | 49 ++++++++++++++++++++++++++++-------- debian/ogrepository.preinst | 31 +++++++++++++++++------ 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/debian/control b/debian/control index f10d4c4..071fadd 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ 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, uftp +Depends: ${misc:Depends}, git, python3, python3-pip, python3-flask, python3-paramiko, python3-psutil, python3-flasgger, samba, gunicorn, wakeonlan , lzop , partclone , qemu-utils , udpcast, uftp, ctorrent, bittornado Description: Ogrepsoitory Package This package provides Ogrepository service. -X-OG-Release: opengnsys-1.6.0-beta, opengnsys-1.6.1-beta + diff --git a/debian/ogrepository.postinst b/debian/ogrepository.postinst index 0d4a658..a356423 100755 --- a/debian/ogrepository.postinst +++ b/debian/ogrepository.postinst @@ -5,6 +5,25 @@ set -x . /usr/share/debconf/confmodule +restore_config_if_modified() { + local new="$1" + local backup="$1.bak.upgrade_package" + + if [ -f "$backup" ]; then + if ! cmp -s "$new" "$backup"; then + echo ">>> Archivo modificado por el usuario detectado en $new" + echo " - Guardando archivo nuevo como ${new}.new" + mv -f "$new" "${new}.new" + echo " - Restaurando archivo anterior desde backup" + mv -f "$backup" "$new" + else + echo ">>> El archivo $new no ha cambiado desde la última versión, eliminando backup" + rm -f "$backup" + fi + fi +} + + # Cargar variables de configuración db_get opengnsys/ogrepository_ogrepoIp OGREPO_IP="$RET" @@ -23,17 +42,17 @@ USER="opengnsys" # 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 +# " 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 @@ -62,7 +81,7 @@ done fi (echo "$SAMBA_PASS"; echo "$SAMBA_PASS") | smbpasswd -a $SAMBA_USER fi - + systemctl enable ogrepo-api # Configure Repo cp /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg.tmpl /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg @@ -83,6 +102,14 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then cp /opt/opengnsys/ogrepository/etc/opengnsys.pub $OPENGNSYS_HOME/.ssh/id_ed25519.pub cat $OPENGNSYS_HOME/.ssh/id_ed25519.pub >> $OPENGNSYS_HOME/.ssh/authorized_keys + restore_config_if_modified "/opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg" + restore_config_if_modified "/opt/opengnsys/ogrepository/etc/repoinfo.json" + restore_config_if_modified "/opt/opengnsys/ogrepository/etc/trashinfo.json" + restore_config_if_modified "/etc/samba/smb.conf" + restore_config_if_modified "/etc/samba/ogrepo-smb.conf" + restore_config_if_modified "/etc/sudoers.d/opengnsys-repository" + + fi # Cambiar la propiedad de los archivos al usuario especificado diff --git a/debian/ogrepository.preinst b/debian/ogrepository.preinst index 652cf8f..14be01b 100755 --- a/debian/ogrepository.preinst +++ b/debian/ogrepository.preinst @@ -2,8 +2,18 @@ set -e -KEY_FILE="/usr/share/keyrings/debian-archive-buster-stable.gpg" -REPO_FILE="/etc/apt/sources.list.d/buster.list" +backup_file_if_exists() { + local original="$1" + local backup="$1.bak.upgrade_package" + + if [ -e "$original" ]; then + echo " - Guardando backup de $original en $backup" + cp -a "$original" "$backup" + fi +} + +# 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" @@ -20,10 +30,17 @@ echo "Añadiendo el repositorio de Debian Buster en $REPO_FILE..." 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 +# 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 + +backup_file_if_exists "/opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg" +backup_file_if_exists "/opt/opengnsys/ogrepository/etc/repoinfo.json" +backup_file_if_exists "/opt/opengnsys/ogrepository/etc/trashinfo.json" +backup_file_if_exists "/etc/samba/smb.conf" +backup_file_if_exists "/etc/samba/ogrepo-smb.conf" +backup_file_if_exists "/etc/sudoers.d/ogrepository" exit 0