PHP Classes

File: update.sh

Recommend this page to a friend!
  Packages of Moises Espindola   Sentinela   update.sh   Download  
File: update.sh
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Sentinela
Linux protection tools with Web dashboard panel
Author: By
Last change:
Date: 6 days ago
Size: 4,311 bytes
 

Contents

Class file image Download
#!/usr/bin/env bash #============================================================================= # Sentinela ? Intelligent Linux Security Framework # update.sh ? Actualización del sistema #============================================================================= # # Uso: ./update.sh [--check] [--force] # # --check: Solo verificar si hay actualizaciones # --force: Forzar actualización sin preguntar #============================================================================= set -Eeuo pipefail INSTALL_DIR="/usr/local/sentinela" SENTINELA_SRC="/root/sentinela" CONFIG_DIR="/etc/sentinela" CHECK_ONLY=false FORCE=false for arg in "$@"; do case "${arg}" in --check) CHECK_ONLY=true ;; --force) FORCE=true ;; esac done RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' info() { echo -e "${CYAN}[INFO]${NC} $*"; } ok() { echo -e "${GREEN}[OK]${NC} $*"; } warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } error() { echo -e "${RED}[ERROR]${NC} $*"; } #============================================================================= # Verificar versión actual #============================================================================= check_version() { local current_version="" if [[ -f "${CONFIG_DIR}/config.conf" ]]; then current_version=$(grep "^VERSION=" "${CONFIG_DIR}/config.conf" 2>/dev/null | cut -d'"' -f2 || echo "desconocida") fi local new_version="1.0.0" if [[ -f "${SENTINELA_SRC}/lib/common.sh" ]]; then new_version=$(grep "^SENTINELA_VERSION=" "${SENTINELA_SRC}/lib/common.sh" 2>/dev/null | cut -d'"' -f2 || echo "1.0.0") fi echo "${current_version}|||${new_version}" } #============================================================================= # Actualizar archivos #============================================================================= update_files() { info "Actualizando archivos..." # Backup de configuración if [[ -f "${CONFIG_DIR}/config.conf" ]]; then cp "${CONFIG_DIR}/config.conf" "${CONFIG_DIR}/config.conf.pre-update" info "Configuración respaldada: config.conf.pre-update" fi # Copiar módulos cp -r "${SENTINELA_SRC}/firewall"/* "${INSTALL_DIR}/firewall/" cp -r "${SENTINELA_SRC}/ids"/* "${INSTALL_DIR}/ids/" cp -r "${SENTINELA_SRC}/ipset"/* "${INSTALL_DIR}/ipset/" cp -r "${SENTINELA_SRC}/telegram"/* "${INSTALL_DIR}/telegram/" cp -r "${SENTINELA_SRC}/backup"/* "${INSTALL_DIR}/backup/" cp -r "${SENTINELA_SRC}/cron"/* "${INSTALL_DIR}/cron/" cp -r "${SENTINELA_SRC}/lib"/* "${INSTALL_DIR}/lib/" cp -r "${SENTINELA_SRC}/systemd"/* "${INSTALL_DIR}/systemd/" # Actualizar CLI cp "${SENTINELA_SRC}/cli/sentinela.sh" "/usr/local/bin/sentinela" chmod +x "/usr/local/bin/sentinela" # Actualizar systemd si cambió cp "${SENTINELA_SRC}/systemd/sentinela.service" /etc/systemd/system/sentinela.service systemctl daemon-reload 2>/dev/null || true ok "Archivos actualizados" } #============================================================================= # Main #============================================================================= main() { echo "??? Sentinela ? Actualización ???" echo if [[ $EUID -ne 0 ]]; then error "Debe ejecutarse como root" exit 1 fi local version_info version_info=$(check_version) local current="${version_info%%|||*}" local new="${version_info#*|||}" info "Versión actual: ${current}" info "Nueva versión: ${new}" if [[ "${current}" == "${new}" ]]; then ok "Ya está en la última versión" exit 0 fi if [[ "${CHECK_ONLY}" == "true" ]]; then info "Hay una nueva versión disponible: ${new}" exit 0 fi if [[ "${FORCE}" != "true" ]]; then echo read -r -p "¿Actualizar de ${current} a ${new}? (s/N): " confirm if [[ "${confirm,,}" != "s" ]]; then echo "Actualización cancelada." exit 0 fi fi update_files echo ok "Actualización completada" echo "Nota: Revise ${CONFIG_DIR}/config.conf para nuevas opciones" echo " La configuración anterior está en config.conf.pre-update" } main "$@"