source: llxcfg/trunk/fuentes/debian/llxcfg-apt-scripts.in @ 96

Last change on this file since 96 was 96, checked in by hectorgh, 5 years ago

adding proyect files

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1#!/bin/bash
2# -------
3# File:        llxcfg-apt-scripts
4# Description: Script to stop and start llxcfg apt scripts
5# Author:      Luis Garcia Gisbert <garcia_luigis@gva.es>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
20# --------
21
22set -e
23
24PATH="/usr/sbin:/usr/bin:/sbin:/bin"
25
26
27# ---------
28# variables
29# ---------
30LLX_PKG_PREFIX="/var/lib/llxcfg/llxcfg-apt_pkg"
31LLX_PKG_STATUS_PREFIX="${LLX_PKG_PREFIX}-status"
32dpkg_status="${LLX_PKG_STATUS_PREFIX}.dpkg"
33
34# library
35LLX_COMMONLIB="/usr/share/lliurex/llxcfg-common/llxcfg-common.sh"
36[ -f "${LLX_COMMONLIB}" ] || exit 1
37. ${LLX_COMMONLIB}
38
39# Funcion: parse_pre_install_pkgs
40#
41# Descripcion:
42# Genera el fichero ${dpkg_status} ("package status file") que contiene
43# todos los paquetes que van a modificarse (install/update/remove).
44#
45# Las líneas del fichero son de la forma:
46#
47#   PACKAGE ACTION
48#
49# Donde 'ACTION' es '+' si el paquete se instala/actualiza o '-' si se elimina.
50#
51# Esta función fue escrita originalmente por Sergio Talens-Oliag <sto@debian.org>
52# para la utilidad "cddt-apt" de su paquete cddt-runtime. La versión incluida
53# en este script fue modificada y adaptada por Luis Garcia <garcia_luigis@gva.es>
54# para el paquete llxcfg-runtime de LliureX.
55#
56
57parse_pre_install_pkgs() {
58  local TMPFILE="`tempfile -s -ll-apt`"
59  local TMPFILE2="`tempfile -s -ll-apt`"
60  # Save the status file
61  cat > $TMPFILE;
62 
63  # Check if it is a VERSION 2 file or exit without error
64  if [ "`head -1 $TMPFILE`" != "VERSION 2" ]; then
65    rm -f $TMPFILE
66    rm -f $TMPFILE2
67    return 0
68  fi
69 
70  # Remove the unneded elements of the file, that leaves a file with lines of
71  # the form:
72  #
73  #   package ACTION
74  #
75  # where ACTION is '+' for install/updates and '-' for removals.
76  sed -e "/^VERSION 2/,/^$/ { d }; \
77    s/^\([^ ]*\) [^ ]\+ . \([^ ]\+\) [^ ]\+$/\1 \2/; \
78    s/ [^-].*$/ +/" "$TMPFILE" \
79  | sort -u > "$TMPFILE2"
80 
81  # Compute the list of packages that have to be installed on the
82  # postinvoke step
83 
84  # Check if any of the old files has been removed
85  if [ -f "$dpkg_status" ]; then
86    sed -n -e '/ -$/ { s/^\(.*\) -/^\1$/; p };' \
87    | grep -v -f- "$dpkg_status" > "$TMPFILE" || true
88  else
89    cat /dev/null > "$TMPFILE"
90  fi
91 
92  # Generate the final list of packages that have to be installed.
93  cat "$TMPFILE" "$TMPFILE2" | sort -u > "$dpkg_status"
94 
95  # Remove the temporary files, as they are no longer needed
96  rm -f "$TMPFILE" "$TMPFILE2";
97}
98
99run_scripts(){
100# Funcion: run_scripts pre-dpkg|post-dpkg
101#
102# Descripcion:
103# Se ejecutan los scripts de apt
104# Los scripts reciben como primer parámetro 'pre-dpkg|post-dpkg'.
105# El segundo parámetro es opcional y consiste es la ruta completa
106# a la lista de paquetes (si existe dicho fichero).
107# Si el parámetro es 'post-dpkg', tras ejecutar los scripts, se
108# borra la lista de paquetes.
109
110    ACTION="$1"
111    rc=0
112    if [ -e "$dpkg_status" ] ; then
113       llxscr_run "apt" "$ACTION" "$dpkg_status" || rc=$?
114    else
115       llxscr_run "apt" "$ACTION" || rc=$?
116    fi
117    [ "$ACTION" = "post-dpkg" ] && rm -f ${dpkg_status}
118    return 0
119}
120
121usage(){
122   CMD_NAME="$(basename "$0")"
123   echo "Usage: $CMD_NAME [OPTIONS] {pre-install-pkgs|post-invoke}" >&2
124   echo "       $CMD_NAME {enable|disable} SCRIPT_NAME [RUN_ORDER]" >&2
125   echo "       $CMD_NAME {allow|deny} SCRIPT_NAME" >&2
126   echo "       OPTIONS: --stop-on-error, --log-dir=LOG_DIRECTORY" >&2
127   return 0
128}
129
130# ----
131# main
132# ----
133
134SCRTYPE="apt"
135SCRTOOL="/usr/sbin/llxcfg-script"
136
137MODE_VARS="UBIQUITY_MODE"
138eval `/usr/sbin/llxcfg-showvars $MODE_VARS`
139
140if [ $UBIQUITY_MODE ] && [ "$UBIQUITY_MODE" = "Y" ]; then
141   exit 0
142fi
143
144while echo "$1" |grep -q "^--" ; do
145   case "$1" in
146      --stop-on-error)
147         LLXSCR_STOP_ON_ERROR="Y"
148         ;;
149      --log-dir=*)
150         LLXSCR_LOG_DIR="${1#*=}"
151         ;;
152   esac
153   shift
154done
155
156case "$1" in
157   pre-install-pkgs)
158      parse_pre_install_pkgs
159      run_scripts pre-dpkg
160      ;;
161   post-invoke)
162#      if [ -e ${dpkg_db} -a -e ${dpkg_status} ]; then
163      run_scripts post-dpkg
164      ;;
165   enable|disable|allow|deny)
166      if [ -z "$2" ] ; then
167         usage
168         exit 1
169      fi
170      ${SCRTOOL} "$SCRTYPE" "$@" || exit $?
171      ;;
172   *)
173      usage
174      exit 1
175      ;;
176esac
177
178exit 0
179
Note: See TracBrowser for help on using the repository browser.