/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to initramfs-tools-hook

  • Committer: Teddy Hogeborn
  • Date: 2019-08-05 21:14:05 UTC
  • Revision ID: teddy@recompile.se-20190805211405-9m6hecekaihpttz9
Override lintian warnings about upgrading from old versions

There are some really things which are imperative that we fix in case
someone were to upgrade from a really old version.  We want to keep
these fixes in the postinst maintainer scripts, even though lintian
complains about such old upgrades not being supported by Debian in
general.  We prefer the code being there, for the sake of the users.

* debian/mandos-client.lintian-overrides
  (maintainer-script-supports-ancient-package-version): New.
  debian/mandos.lintian-overrides
  (maintainer-script-supports-ancient-package-version): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
. /usr/share/initramfs-tools/hook-functions
31
31
 
32
 
for d in /usr /usr/local; do
33
 
    if [ -d "$d"/lib/mandos ]; then
34
 
        prefix="$d"
 
32
for d in /usr/lib \
 
33
    "/usr/lib/`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`" \
 
34
    "`rpm --eval='%{_libdir}' 2>/dev/null`" /usr/local/lib; do
 
35
    if [ -d "$d"/mandos ]; then
 
36
        libdir="$d"
35
37
        break
36
38
    fi
37
39
done
38
 
if [ -z "$prefix" ]; then
 
40
if [ -z "$libdir" ]; then
39
41
    # Mandos not found
40
42
    exit 1
41
43
fi
68
70
CONFDIR="/conf/conf.d/mandos"
69
71
MANDOSDIR="/lib/mandos"
70
72
PLUGINDIR="${MANDOSDIR}/plugins.d"
 
73
PLUGINHELPERDIR="${MANDOSDIR}/plugin-helpers"
71
74
HOOKDIR="${MANDOSDIR}/network-hooks.d"
72
75
 
73
76
# Make directories
74
77
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
75
78
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}"
76
79
install --owner=${mandos_user} --group=${mandos_group} --directory \
77
 
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
 
80
        --mode=u=rwx "${DESTDIR}${PLUGINDIR}" \
 
81
        "${DESTDIR}${PLUGINHELPERDIR}"
 
82
 
 
83
copy_exec "$libdir"/mandos/mandos-to-cryptroot-unlock "${MANDOSDIR}"
78
84
 
79
85
# Copy the Mandos plugin runner
80
 
copy_exec "$prefix"/lib/mandos/plugin-runner "${MANDOSDIR}"
 
86
copy_exec "$libdir"/mandos/plugin-runner "${MANDOSDIR}"
81
87
 
82
88
# Copy the plugins
83
89
 
84
90
# Copy the packaged plugins
85
 
for file in "$prefix"/lib/mandos/plugins.d/*; do
 
91
for file in "$libdir"/mandos/plugins.d/*; do
86
92
    base="`basename \"$file\"`"
87
93
    # Is this plugin overridden?
88
94
    if [ -e "/etc/mandos/plugins.d/$base" ]; then
96
102
    esac
97
103
done
98
104
 
 
105
# Copy the packaged plugin helpers
 
106
for file in "$libdir"/mandos/plugin-helpers/*; do
 
107
    base="`basename \"$file\"`"
 
108
    # Is this plugin overridden?
 
109
    if [ -e "/etc/mandos/plugin-helpers/$base" ]; then
 
110
        continue
 
111
    fi
 
112
    case "$base" in
 
113
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
114
            : ;;
 
115
        "*") : ;;
 
116
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
117
    esac
 
118
done
 
119
 
99
120
# Copy any user-supplied plugins
100
121
for file in /etc/mandos/plugins.d/*; do
101
122
    base="`basename \"$file\"`"
107
128
    esac
108
129
done
109
130
 
 
131
# Copy any user-supplied plugin helpers
 
132
for file in /etc/mandos/plugin-helpers/*; do
 
133
    base="`basename \"$file\"`"
 
134
    case "$base" in
 
135
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
136
            : ;;
 
137
        "*") : ;;
 
138
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
139
    esac
 
140
done
 
141
 
110
142
# Get DEVICE from initramfs.conf and other files
111
143
. /etc/initramfs-tools/initramfs.conf
112
144
for conf in /etc/initramfs-tools/conf.d/*; do
113
145
    if [ -n `basename \"$conf\" | grep '^[[:alnum:]][[:alnum:]\._-]*$' \
114
146
        | grep -v '\.dpkg-.*$'` ]; then
115
 
        [ -f ${conf} ] && . ${conf}
 
147
        [ -f "${conf}" ] && . "${conf}"
116
148
    fi
117
149
done
118
150
export DEVICE
127
159
    if [ -x "$hook" ]; then
128
160
        # Copy any files needed by the network hook
129
161
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
130
 
            VERBOSITY=0 "$hook" files | while read file target; do
 
162
            VERBOSITY=0 "$hook" files | while read -r file target; do
131
163
            if [ ! -e "${file}" ]; then
132
164
                echo "WARNING: file ${file} not found, requested by Mandos network hook '${hook##*/}'" >&2
133
165
            fi
139
171
        done
140
172
        # Copy and load any modules needed by the network hook
141
173
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
142
 
            VERBOSITY=0 "$hook" modules | while read module; do
143
 
            if [ -z "${target}" ]; then
144
 
                force_load "$module"
145
 
            fi
 
174
            VERBOSITY=0 "$hook" modules | while read -r module; do
 
175
            force_load "$module"
146
176
        done
147
177
    fi
148
178
done
149
179
 
150
180
# GPGME needs GnuPG
 
181
gpg=/usr/bin/gpg
151
182
libgpgme11_version="`dpkg-query --showformat='${Version}' --show libgpgme11`"
152
 
if dpkg --compare-versions "$libgpgme11_version" ge 1.4.1-0.1; then
 
183
if dpkg --compare-versions "$libgpgme11_version" ge 1.5.0-0.1; then
 
184
    if [ -e /usr/bin/gpgconf ]; then
 
185
        if [ ! -e "${DESTDIR}/usr/bin/gpgconf" ]; then
 
186
            copy_exec /usr/bin/gpgconf
 
187
        fi
 
188
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
189
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
190
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
191
        if [ -e "$gpgagent" ] && [ ! -e "${DESTDIR}$gpgagent" ]; then
 
192
            copy_exec "$gpgagent"
 
193
        fi
 
194
    fi
 
195
elif dpkg --compare-versions "$libgpgme11_version" ge 1.4.1-0.1; then
153
196
    gpg=/usr/bin/gpg2
154
 
else
155
 
    gpg=/usr/bin/gpg
156
197
fi
157
198
if [ ! -e "${DESTDIR}$gpg" ]; then
158
199
    copy_exec "$gpg"
183
224
    if [ -d "$file" ]; then
184
225
        continue
185
226
    fi
186
 
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
187
 
    chown ${mandos_user}:${mandos_group} \
188
 
        "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
227
    case "$file" in
 
228
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
229
            : ;;
 
230
        "*") : ;;
 
231
        *)
 
232
            cp --archive --sparse=always "$file" \
 
233
               "${DESTDIR}${CONFDIR}"
 
234
            chown ${mandos_user}:${mandos_group} \
 
235
                  "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
236
            ;;
 
237
    esac
189
238
done
 
239
# Use Diffie-Hellman parameters file if available
 
240
if [ -e "${DESTDIR}${CONFDIR}"/dhparams.pem ]; then
 
241
    sed --in-place \
 
242
        --expression="1i--options-for=mandos-client:--dh-params=${CONFDIR}/dhparams.pem" \
 
243
        "${DESTDIR}/${CONFDIR}/plugin-runner.conf"
 
244
fi
190
245
 
191
246
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
192
247
# its plugin directory and its config file.  However, since almost all
197
252
# initrd; it is intended to affect the initrd.img file itself, since
198
253
# it now contains secret key files.  There is, however, no other way
199
254
# to set the permission of the initrd.img file without a race
200
 
# condition.  This umask is set by "initramfs-tools-hook-conf",
201
 
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
 
255
# condition.  This umask is set by "initramfs-tools-conf", installed
 
256
# as "/usr/share/initramfs-tools/conf.d/mandos-conf".)
202
257
203
258
for full in "${MANDOSDIR}" "${CONFDIR}"; do
204
259
    while [ "$full" != "/" ]; do
216
271
done
217
272
for dir in "${DESTDIR}"/lib* "${DESTDIR}"/usr/lib*; do
218
273
    if [ -d "$dir" ]; then
219
 
        find "$dir" \! -perm -u+rw,g+r -prune -or -print0 \
220
 
            | xargs --null --no-run-if-empty chmod a+rX
 
274
        find "$dir" \! -perm -u+rw,g+r -prune -or \! -type l -print0 \
 
275
            | xargs --null --no-run-if-empty chmod a+rX --
221
276
    fi
222
277
done