Debian Codegraph @

bin/fai-debconf

raw symbols SCIP
1 #! /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_conf() {
33
34 # loop over all files in debconf
35 local class f
36 cd $debconfdir
37 for class in $classes ; do
38 [ -f $class ] && add_data $class
39 if [ -d $class ]; then
40 for f in $(ls $class/* | grep -E '^[[:alnum:]/_.-]+$') ; do
41 [ -f $f ] && add_data $f
42 done
43 fi
44 done
45 }
46 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47 add_data() {
48
49 # add debconf data
50 local file=$1
51
52 [ X$verbose = X1 ] && echo "Adding debconf data from $debconfdir/$file"
53 $ROOTCMD debconf-set-selections $v < $debconfdir/$file 2>> $LOGDIR/debconf.log
54 cat $debconfdir/$file >> $LOGDIR/debconf.data
55 }
56 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 reconfigure_packages() {
58
59 local packages p tmpdb
60
61 [ -s $LOGDIR/debconf.data ] || return # nothing to do if is size 0 or missing
62 if [ -r $LOGDIR/debconf.old ] ; then
63 $ROOTCMD debconf-get-selections | sort > $LOGDIR/debconf.new
64 diff --changed-group-format="%>" --unchanged-line-format="" \
65 $LOGDIR/debconf.old $LOGDIR/debconf.new > $LOGDIR/debconf.data
66 fi
67
68 packages=$(awk '{print $1}' $LOGDIR/debconf.data | sort | 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 [ -f $target/var/lib/dpkg/info/$p.list ]; then
75 [ X$verbose = X1 ] && echo "Reconfiguring package $p"
76 DEBCONF_DB_OVERRIDE="File{$tmpdb readonly:true}" DEBIAN_FRONTEND=noninteractive $ROOTCMD /usr/sbin/dpkg-reconfigure $p
77 else
78 [ "$debug" ] && echo "Package $p is not yet installed. Skipping reconfiguration."
79 fi
80 done
81 rm -f $target/$tmpdb $target/$tmpdb-old
82 }
83 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 usage() {
85
86 local ex=$1
87 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) usage 0 ;;
105 s) reconf=0 ;;
106 v) verbose=1; v=-v ;;
107 esac
108 done
109 shift $((OPTIND - 1))
110 [ -z "$1" ] || [ -n "$2" ] && usage 1
111 debconfdir=$1 # will be $FAI/debconf
112
113 if [ ! -d $debconfdir ]; then
114 echo "WARNING: Subdirectory $debconf not found"
115 exit 1
116 fi
117
118 if [ -z "$classes" ]; then
119 echo "No classes are defined."
120 exit 9
121 fi
122
123 [ $forcereconf -eq 0 ] && [ -x $target/usr/bin/debconf-get-selections ] && $ROOTCMD debconf-get-selections | sort > $LOGDIR/debconf.old
124 call_conf # add data to debconf database
125 [ $reconf -eq 1 ] && reconfigure_packages
126 exit 0