#!/bin/bash # ------- # File: llxcfg-apt-scripts # Description: Script to stop and start llxcfg apt scripts # Author: Luis Garcia Gisbert # # 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 # --------- LLX_PKG_PREFIX="/var/lib/llxcfg/llxcfg-apt_pkg" LLX_PKG_STATUS_PREFIX="${LLX_PKG_PREFIX}-status" dpkg_status="${LLX_PKG_STATUS_PREFIX}.dpkg" # library LLX_COMMONLIB="/usr/share/lliurex/llxcfg-common/llxcfg-common.sh" [ -f "${LLX_COMMONLIB}" ] || exit 1 . ${LLX_COMMONLIB} # Funcion: parse_pre_install_pkgs # # Descripcion: # Genera el fichero ${dpkg_status} ("package status file") que contiene # todos los paquetes que van a modificarse (install/update/remove). # # Las líneas del fichero son de la forma: # # PACKAGE ACTION # # Donde 'ACTION' es '+' si el paquete se instala/actualiza o '-' si se elimina. # # Esta función fue escrita originalmente por Sergio Talens-Oliag # para la utilidad "cddt-apt" de su paquete cddt-runtime. La versión incluida # en este script fue modificada y adaptada por Luis Garcia # para el paquete llxcfg-runtime de LliureX. # parse_pre_install_pkgs() { local TMPFILE="`tempfile -s -ll-apt`" local TMPFILE2="`tempfile -s -ll-apt`" # Save the status file cat > $TMPFILE; # Check if it is a VERSION 2 file or exit without error if [ "`head -1 $TMPFILE`" != "VERSION 2" ]; then rm -f $TMPFILE rm -f $TMPFILE2 return 0 fi # Remove the unneded elements of the file, that leaves a file with lines of # the form: # # package ACTION # # where ACTION is '+' for install/updates and '-' for removals. sed -e "/^VERSION 2/,/^$/ { d }; \ s/^\([^ ]*\) [^ ]\+ . \([^ ]\+\) [^ ]\+$/\1 \2/; \ s/ [^-].*$/ +/" "$TMPFILE" \ | sort -u > "$TMPFILE2" # Compute the list of packages that have to be installed on the # postinvoke step # Check if any of the old files has been removed if [ -f "$dpkg_status" ]; then sed -n -e '/ -$/ { s/^\(.*\) -/^\1$/; p };' \ | grep -v -f- "$dpkg_status" > "$TMPFILE" || true else cat /dev/null > "$TMPFILE" fi # Generate the final list of packages that have to be installed. cat "$TMPFILE" "$TMPFILE2" | sort -u > "$dpkg_status" # Remove the temporary files, as they are no longer needed rm -f "$TMPFILE" "$TMPFILE2"; } run_scripts(){ # Funcion: run_scripts pre-dpkg|post-dpkg # # Descripcion: # Se ejecutan los scripts de apt # Los scripts reciben como primer parámetro 'pre-dpkg|post-dpkg'. # El segundo parámetro es opcional y consiste es la ruta completa # a la lista de paquetes (si existe dicho fichero). # Si el parámetro es 'post-dpkg', tras ejecutar los scripts, se # borra la lista de paquetes. ACTION="$1" rc=0 if [ -e "$dpkg_status" ] ; then llxscr_run "apt" "$ACTION" "$dpkg_status" || rc=$? else llxscr_run "apt" "$ACTION" || rc=$? fi [ "$ACTION" = "post-dpkg" ] && rm -f ${dpkg_status} return 0 } usage(){ CMD_NAME="$(basename "$0")" echo "Usage: $CMD_NAME [OPTIONS] {pre-install-pkgs|post-invoke}" >&2 echo " $CMD_NAME {enable|disable} SCRIPT_NAME [RUN_ORDER]" >&2 echo " $CMD_NAME {allow|deny} SCRIPT_NAME" >&2 echo " OPTIONS: --stop-on-error, --log-dir=LOG_DIRECTORY" >&2 return 0 } # ---- # main # ---- SCRTYPE="apt" SCRTOOL="/usr/sbin/llxcfg-script" MODE_VARS="UBIQUITY_MODE" eval `/usr/sbin/llxcfg-showvars $MODE_VARS` if [ $UBIQUITY_MODE ] && [ "$UBIQUITY_MODE" = "Y" ]; then exit 0 fi while echo "$1" |grep -q "^--" ; do case "$1" in --stop-on-error) LLXSCR_STOP_ON_ERROR="Y" ;; --log-dir=*) LLXSCR_LOG_DIR="${1#*=}" ;; esac shift done case "$1" in pre-install-pkgs) parse_pre_install_pkgs run_scripts pre-dpkg ;; post-invoke) # if [ -e ${dpkg_db} -a -e ${dpkg_status} ]; then run_scripts post-dpkg ;; enable|disable|allow|deny) if [ -z "$2" ] ; then usage exit 1 fi ${SCRTOOL} "$SCRTYPE" "$@" || exit $? ;; *) usage exit 1 ;; esac exit 0