| 1 | #! /bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | #********************************************************************* |
| 4 | # |
| 5 | # fai-debconf - set debconf values using classes |
| 6 | # |
| 7 | # This script is part of FAI (Fully Automatic Installation) |
| 8 | # (c) 2005-2025 by Thomas Lange, [email protected] |
| 9 | # Universitaet zu Koeln |
| 10 | # |
| 11 | #********************************************************************* |
| 12 | # This program is free software; you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License as published by |
| 14 | # the Free Software Foundation; either version 2 of the License, or |
| 15 | # (at your option) any later version. |
| 16 | # |
| 17 | # This program is distributed in the hope that it will be useful, but |
| 18 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | # General Public License for more details. |
| 21 | # |
| 22 | # A copy of the GNU General Public License is available as |
| 23 | # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution |
| 24 | # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You |
| 25 | # can also obtain it by writing to the Free Software Foundation, Inc., |
| 26 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 27 | #********************************************************************* |
| 28 | |
| 29 | # variables needed: $classes, $ROOTCMD, $LOGDIR, $target |
| 30 | |
| 31 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 32 | call_confscip-shell shell fai 6.6 call_conf().() { |
| 33 | |
| 34 | # loop over all files in debconf |
| 35 | local class f |
| 36 | cd $debconfdir |
| 37 | for class in $classes ; do |
| 38 | [scip-shell system . . `[`. -f $class ] && add_datascip-shell shell fai 6.6 add_data(). $class |
| 39 | if [scip-shell system . . `[`. -d $class ]; then |
| 40 | for f in $(lsscip-shell system . . ls. $class/* | grepscip-shell system . . grep. -E '^[[:alnum:]/_.-]+$') ; do |
| 41 | [scip-shell system . . `[`. -f $f ] && add_datascip-shell shell fai 6.6 add_data(). $f |
| 42 | done |
| 43 | fi |
| 44 | done |
| 45 | } |
| 46 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 47 | add_datascip-shell shell fai 6.6 add_data().() { |
| 48 | |
| 49 | # add debconf data |
| 50 | local file=$1 |
| 51 | |
| 52 | [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Adding debconf data from $debconfdir/$file" |
| 53 | $ROOTCMD debconf-set-selections $v < $debconfdir/$file 2>> $LOGDIR/debconf.log |
| 54 | catscip-shell system . . cat. $debconfdir/$file >> $LOGDIR/debconf.data |
| 55 | } |
| 56 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 57 | reconfigure_packagesscip-shell shell fai 6.6 reconfigure_packages().() { |
| 58 | |
| 59 | local packages p tmpdb |
| 60 | |
| 61 | [scip-shell system . . `[`. -s $LOGDIR/debconf.data ] || return # nothing to do if is size 0 or missing |
| 62 | if [scip-shell system . . `[`. -r $LOGDIR/debconf.old ] ; then |
| 63 | $ROOTCMD debconf-get-selections | sortscip-shell system . . sort. > $LOGDIR/debconf.new |
| 64 | dscip-shell system . . diff.iffscip-shell system . . diff. --changed-group-format="%>" --unchanged-line-format="" \ |
| 65 | $LOGDIR/debconf.old $LOGDIR/debconf.new > $LOGDIR/debconf.data |
| 66 | fi |
| 67 | |
| 68 | packages=$(awkscip-shell system . . awk. '{print $1}' $LOGDIR/debconf.data | sortscip-shell system . . sort. | uniqscip-shell system . . uniq.) |
| 69 | # backup database |
| 70 | tmpdb=$($ROOTCMD mktemp -t fai-debconf.XXXXXXXXXX) || exit 10 |
| 71 | $ROOTCMD debconf-copydb configdb faidb --config=Name:faidb --config=Driver:File --config=Filename:$tmpdb |
| 72 | for p in $packages; do |
| 73 | # test if package is installed |
| 74 | if [scip-shell system . . `[`. -f $target/var/lib/dpkg/info/$p.list ]; then |
| 75 | [scip-shell system . . `[`. X$verbose = X1 ] && echoscip-shell system . . echo. "Reconfiguring package $p" |
| 76 | DEBCONF_DB_OVERRIDE="File{$tmpdb readonly:true}" DEBIAN_FRONTEND=noninteractive $ROOTCMD /usr/sbin/dpkg-reconfigurescip-shell filesystem . . `/usr/sbin/dpkg-reconfigure`. $p |
| 77 | else |
| 78 | [scip-shell system . . `[`. "$debug" ] && echoscip-shell system . . echo. "Package $p is not yet installed. Skipping reconfiguration." |
| 79 | fi |
| 80 | done |
| 81 | rmscip-shell system . . rm. -f $target/$tmpdb $target/$tmpdb-old |
| 82 | } |
| 83 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 84 | usagescip-shell shell fai 6.6 usage().() { |
| 85 | |
| 86 | local ex=$1 |
| 87 | catscip-shell system . . cat. <<-EOF |
| 88 | fai-debconf Copyright (C) 2005-2021 Thomas Lange |
| 89 | |
| 90 | Usage: fai-debconf [OPTION] DIRECTORY |
| 91 | EOF |
| 92 | exit $ex |
| 93 | } |
| 94 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 95 | # main program |
| 96 | |
| 97 | reconf=1 # call dpkg-reconfigure by default |
| 98 | forcereconf=0 # don't call dpkg-reconfigure for unchanged packages |
| 99 | |
| 100 | while getopts "hvsfd" opt ; do |
| 101 | case "$opt" in |
| 102 | d) debug=1; verbose=1; v=-v ;; |
| 103 | f) forcereconf=1 ;; |
| 104 | h) usagescip-shell shell fai 6.6 usage(). 0 ;; |
| 105 | s) reconf=0 ;; |
| 106 | v) verbose=1; v=-v ;; |
| 107 | esac |
| 108 | done |
| 109 | shift $((OPTIND - 1)) |
| 110 | [scip-shell system . . `[`. -z "$1" ] || [scip-shell system . . `[`. -n "$2" ] && usagescip-shell shell fai 6.6 usage(). 1 |
| 111 | debconfdir=$1 # will be $FAI/debconf |
| 112 | |
| 113 | if [scip-shell system . . `[`. ! -d $debconfdir ]; then |
| 114 | echoscip-shell system . . echo. "WARNING: Subdirectory $debconf not found" |
| 115 | exit 1 |
| 116 | fi |
| 117 | |
| 118 | if [scip-shell system . . `[`. -z "$classes" ]; then |
| 119 | echoscip-shell system . . echo. "No classes are defined." |
| 120 | exit 9 |
| 121 | fi |
| 122 | |
| 123 | [scip-shell system . . `[`. $forcereconf -eq 0 ] && [scip-shell system . . `[`. -x $target/usr/bin/debconf-get-selections ] && $ROOTCMD debconf-get-selections | sortscip-shell system . . sort. > $LOGDIR/debconf.old |
| 124 | call_confscip-shell shell fai 6.6 call_conf(). # add data to debconf database |
| 125 | [scip-shell system . . `[`. $reconf -eq 1 ] && reconfigure_packagesscip-shell shell fai 6.6 reconfigure_packages(). |
| 126 | exit 0 |