3
# This script will be run by 'mkinitramfs' when it creates the image.
 
 
4
# Its job is to decide which files to install, then install them into
 
 
5
# the staging area, where the initramfs is being created.  This
 
 
6
# happens when a new 'linux-image' package is installed, or when the
 
 
7
# administrator runs 'update-initramfs' by hand to update an initramfs
 
 
10
# The environment contains at least:
 
 
12
#  DESTDIR -- The staging directory where the image is being built.
 
 
14
# No initramfs pre-requirements
 
 
30
. /usr/share/initramfs-tools/hook-functions
 
 
32
if [ -d /usr/lib/mandos ]; then
 
 
34
elif [ -d /usr/local/lib/mandos ]; then
 
 
41
# The Mandos network client uses the network
 
 
43
# The Mandos network client uses IPv6
 
 
46
# These are directories inside the initrd
 
 
47
CONFDIR="/conf/conf.d/mandos"
 
 
48
MANDOSDIR="/lib/mandos"
 
 
49
PLUGINDIR="${MANDOSDIR}/plugins.d"
 
 
52
mkdir --parents "${DESTDIR}${CONFDIR}"
 
 
53
mkdir --parents "${DESTDIR}${PLUGINDIR}"
 
 
55
# Copy the Mandos plugin runner
 
 
56
copy_exec "$prefix"/lib/mandos/plugin-runner "${DESTDIR}${MANDOSDIR}"
 
 
60
# Copy the packaged plugins
 
 
61
for file in "$prefix"/lib/mandos/plugins.d/*; do
 
 
62
    base="`basename \"$file\"`"
 
 
63
    # Is this plugin overridden?
 
 
64
    if [ -e "/etc/mandos/plugins.d/$base" ]; then
 
 
68
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
 
 
69
        *) copy_exec "$file" "${PLUGINDIR}";;
 
 
73
# Copy any user-supplied plugins
 
 
74
for file in /etc/mandos/plugins.d/*; do
 
 
75
    base="`basename \"$file\"`"
 
 
77
        *~|.*|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
 
 
78
        *) copy_exec "$file" "${PLUGINDIR}";;
 
 
82
# GPGME needs /usr/bin/gpg
 
 
83
if ! [ -e "${DESTDIR}/usr/bin/gpg" ] \
 
 
84
    && [ -n "`ls \"${DESTDIR}\"/usr/lib/libgpgme.so* 2>/dev/null`" ]; then
 
 
85
    copy_exec /usr/bin/gpg
 
 
89
for file in /etc/mandos/*; do
 
 
90
    if [ -d "$file" ]; then
 
 
93
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
 
 
95
# Create key ring files
 
 
96
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
 
 
97
    --no-default-keyring --no-options --enable-dsa2 \
 
 
98
    --homedir "${DESTDIR}${CONFDIR}" --no-permission-warning \
 
 
99
    --trust-model always --import-options import-minimal \
 
 
100
    --import "${DESTDIR}${CONFDIR}/seckey.txt"
 
 
101
chown nobody "${DESTDIR}${CONFDIR}/secring.gpg"
 
 
103
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
 
 
104
# its plugin directory and its config file.  However, since almost all
 
 
105
# files in initrd have been created with umask 027, this opening of
 
 
106
# permissions is needed.
 
 
108
# (The umask is not really intended to affect the files inside the
 
 
109
# initrd; it is intended to affect the initrd.img file itself, since
 
 
110
# it now contains secret key files.  There is, however, no other way
 
 
111
# to set the permission of the initrd.img file without a race
 
 
112
# condition.  This umask is set by "initramfs-tools-hook-conf",
 
 
113
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
 
 
115
for full in "${PLUGINDIR}" "${CONFDIR}"; do
 
 
116
    while [ "$full" != "/" ]; do
 
 
117
        chmod a+rX "${DESTDIR}$full"
 
 
118
        full="`dirname \"$full\"`"
 
 
122
# Reset some other things to sane permissions which we have
 
 
123
# inadvertently affected with our umask setting.
 
 
124
for dir in / /bin /etc /keyscripts /sbin /scripts /usr /usr/bin; do
 
 
125
    chmod a+rX "${DESTDIR}$dir"
 
 
127
for dir in /lib /usr/lib; do
 
 
128
    chmod --recursive a+rX "${DESTDIR}$dir"