Debian Codegraph @

debian/ucf-helper/ucf-helper-functions.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 UCF="ucf --three-way --debconf-ok"
4
5 # rename ucf-conffile. This was mostly stolen from cacti.postinst after
6 # a short discussion on debian-mentors, see
7 # http://lists.debian.org/debian-mentors/2013/07/msg00027.html
8 # and the following thread. Thanks to Paul Gevers
9 rename_ucf_filescip-shell shell shell-project 0.0.0 rename_ucf_file().() {
10 local oldname
11 local newname
12
13 # override UCF_FORCE_CONFFNEW with an empty local variable
14 local UCF_FORCE_CONFFNEW
15
16 oldname="$1"
17 newname="$2"
18 if [scip-shell system . . `[`. ! -e "$newname" ] ; then
19 if [scip-shell system . . `[`. -e "$oldname" ]; then
20 mvscip-shell system . . mv. "$oldname" "$newname"
21 fi
22 # ucf doesn't offer a documented way to do this, so we need to
23 # peddle around with undocumented ucf internals.
24 sedscip-shell system . . sed. -i "s|$oldname|$newname|" /var/lib/ucf/hashfilescip-shell filesystem . . `/var/lib/ucf/hashfile`.
25 ucfr --purge "$PKGNAME" "$oldname"
26 ucfr "$PKGNAME" "$newname"
27 # else: Don't do anything, leave old file in place
28 fi
29 ucfr "$PKGNAME" "$newname"
30 }
31
32 generate_directory_structurescip-shell shell shell-project 0.0.0 generate_directory_structure().() {
33 local pkgdir
34 local locdir
35 pkgdir="$1"
36 locdir="$2"
37
38 # generate empty directory structure
39
40 (cd "$pkgdir" && findscip-shell system . . find. . -type d -print0 ) | \
41 (cd "$locdir" && xargsscip-shell system . . xargs. -0 mkdir -p --)
42 }
43
44 # handle a single ucf_conffile by first checking whether the file might be
45 # accociated with a different package. If so, we keep our hands off the file
46 # so that a different package can safely hijack our conffiles.
47 # to hijack a file, simply ucfr it to a package before the ucf processing
48 # code.
49 # If the file is either unassociated or already associated with us, call ucf
50 # proper and register the file as ours.
51 handle_single_ucf_filescip-shell shell shell-project 0.0.0 handle_single_ucf_file().()
52 {
53 local pkgfile
54 local locfile
55 if [scip-shell system . . `[`. -n "${UCF_HELPER_FUNCTIONS_DEBUG:-}" ]; then
56 set -x
57 fi
58
59 pkgfile="$1"
60 locfile="$2"
61 export DEBIAN_FRONTEND
62
63 PKG="$(ucfq --with-colons "$locdir/$file" | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. --delimiter=: --fields=2 )"
64 # skip conffile if it is associated with a different package.
65 # This allows other packages to safely hijack our conffiles.
66 if [scip-shell system . . `[`. -z "$PKG" ] || [scip-shell system . . `[`. "$PKG" = "$PKGNAME" ]; then
67 $UCF "$pkgfile" "$locdir/$file"
68 ucfr "$PKGNAME" "$locdir/$file"
69 fi
70 set +x
71 }
72
73 # checks whether a file was deleted in the package and handle it on the local
74 # system appropriately: If the local file differs from what we had previously,
75 # we just unregister it and leave it on the system (preserving local changes),
76 # otherwise we remove it.
77 # this also removes conffiles that are zero-size after the
78 # ucf run, which might happen if the local admin has
79 # deleted a conffile that has changed in the package.
80 handle_deleted_ucf_filescip-shell shell shell-project 0.0.0 handle_deleted_ucf_file().()
81 {
82 local locfile
83 local locdir
84 local pkgdir
85 if [scip-shell system . . `[`. -n "${UCF_HELPER_FUNCTIONS_DEBUG:-}" ]; then
86 set -x
87 fi
88 locfile="$1"
89 pkgdir="$2"
90 locdir="$3"
91
92 # compute the name of the reference file in $pkgdir
93 reffile="$(echoscip-shell system . . echo. "$locfile" | sedscip-shell system . . sed. "s|$locdir|$pkgdir|")"
94 if ! [scip-shell system . . `[`. -e "$reffile" ]; then
95 # if the reference file does not exist, then it was removed in the package
96 # do as if the file was replaced with an empty file
97 $UCF /dev/nullscip-shell filesystem . . `/dev/null`. "$locfile"
98 if [scip-shell system . . `[`. -s "$locfile" ]; then
99 # the file has non-zero size after the ucf run. local admin must
100 # have decided to keep the file with contents. Done here.
101 :
102 else
103 # the file has zero size and can be removed
104 # remove the file itself ('') and all possible backup/reference extensions
105 for ext in '' '~' '%' .bak .dpkg-tmp .dpkg-new .dpkg-old .dpkg-dist .ucf-new .ucf-old .ucf-dist; do
106 rmscip-shell system . . rm. -f "${locfile}$ext"
107 done
108 fi
109 # unregister the file anyhow since the package doesn't know about it any more
110 ucf --purge "${locfile}"
111 ucfr --purge "$PKGNAME" "${locfile}"
112 fi
113 set +x
114 }
115
116 handle_all_ucf_filesscip-shell shell shell-project 0.0.0 handle_all_ucf_files().() {
117 local pkgdir
118 local locdir
119 pkgdir="$1"
120 locdir="$2"
121
122 generate_directory_structurescip-shell shell shell-project 0.0.0 generate_directory_structure(). "$pkgdir" "$locdir"
123
124 # handle regular ucf-conffiles by iterating through all conffiles
125 # that come with the package
126 for file in $(findscip-shell system . . find. "$pkgdir" -type f -printf '%P\n' ); do
127 handle_single_ucf_filescip-shell shell shell-project 0.0.0 handle_single_ucf_file(). "$pkgdir/$file" "$locdir/$file"
128 done
129
130 # handle ucf-conffiles that were deleted in our package by iterating
131 # through all ucf-conffiles that are registered for the package
132 for locfile in $(ucfq --with-colons "$PKGNAME" | cutscip-shell system . . cut. --delimiter=: --fields=1); do
133 handle_deleted_ucf_filescip-shell shell shell-project 0.0.0 handle_deleted_ucf_file(). "$locfile" "$pkgdir" "$locdir"
134 done
135 }
136
137 # vim:sw=4:sts=4:et:
138