#!/bin/bash # ------- # File: llxcfg-apt # Description: Script to stop and start llxcfg scripts on apt upgrades # Author: Sergio Talens-Oliag # Copyright: (c) 2005 Sergio Talens-Oliag # Modified: 2006-02-28 Luis Garcia Gisbert # 2007-04-23 Luis Garcia Gisbert : # Current version is intended to be used by llxcfg-apt-scripts # # 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 2 of the License, or # (at your option) any later version. # # This program 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, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e PATH="/usr/sbin:/usr/bin:/sbin:/bin" # --------- # variables # --------- dpkg_db="/var/lib/llxcfg/llxcfg-apt_pkg.db" # --- CONFDIR="/etc/llxcfg" SCR_ENABLED="scripts-enabled" ENABLEDIR="$CONFDIR/$SCR_ENABLED" get_script_list(){ # Funcion: get_script_list STATUS_FILE # # Descripcion: # Procesa el "status file" de paquetes que se le pasa y devuelve los nombres de los # scripts implicados (si hay alguno). # Para ello se utiliza la lista de paquetes/scripts asociados almacenada # en el fichero "${LLX_PKG_PREFIX}.db" # NOTA: La lista PUEDE tener duplicados ... [ -e "${1}" -a -e "${dpkg_db}" ] && generate_sed_script ${1} |sed -n -f- ${dpkg_db} return 0 } generate_sed_script(){ # Funcion: generate_sed_script STATUS_FILE # # Descripcion: # Toma como argumento un "status file" de paquetes y # genera la lista de comandos de sed para buscar en # el fichero ${LLX_PKG_PREFIX}.db sed -ne "s/\([^[:space:]]*\).*/s%^\1:%%p/p" ${1} } run_scripts(){ # Funcion: run_scripts pre-dpkg|post-dpkg # # Descripcion: # Primero se obtiene la lista de scripts a partir del "status file" de paquetes correspondiente # Después, para cada uno de los scripts de la lista, tras comprobar si está activo, # se activan/desactivan las configuraciones y los servicios asociados ACTION="$1" STATUS_FILE="$dpkg_status" CANDIDATE_SCRIPTS="`get_script_list ${STATUS_FILE}`" SCRIPTS_LIST="" for SCR in ${CANDIDATE_SCRIPTS}; do SCRIPT_FILE="${ENABLEDIR}/${SCR}" if [ -x ${SCRIPT_FILE} ] && ! echo " ${SCRIPTS_LIST} " |grep -q " ${SCR} " ; then # mantenemos la lista SCRIPTS_LIST para evitar duplicidades SCRIPTS_LIST="${SCRIPTS_LIST} ${SCR}" SERVICES=`${SCRIPT_FILE} services` case "$ACTION" in post-dpkg) ${SCRIPT_FILE} start || /bin/true for s in $SERVICES; do invoke-rc.d --quiet $s restart || /bin/true done ;; pre-dpkg) for s in $SERVICES; do invoke-rc.d --quiet $s stop || /bin/true done ${SCRIPT_FILE} stop || /bin/true ;; esac fi done [ "$ACTION" = "post-dpkg" ] && rm -f ${STATUS_FILE} } # ---- # main # ---- INITDSCR="/etc/init.d/llxcfg" dpkg_status="$2" case "$1" in pre-dpkg) if [ "${dpkg_status}" -a -e "${dpkg_db}" -a -e "${dpkg_status}" ]; then run_scripts pre-dpkg else # si no existe el fichero, revertimos al comportamiento original de llxcfg-apt [ -x "$INITDSCR" ] || exit 0 SERVICES=`$INITDSCR services` for s in $SERVICES; do invoke-rc.d $s stop done $INITDSCR stop fi ;; post-dpkg) if [ "${dpkg_status}" -a -e "${dpkg_db}" -a -e "${dpkg_status}" ]; then run_scripts post-dpkg else # si no existe el fichero, revertimos al comportamiento original de llxcfg-apt [ -x "$INITDSCR" ] || exit 0 SERVICES=`$INITDSCR services` $INITDSCR start for s in $SERVICES; do invoke-rc.d $s restart done fi ;; esac exit 0