/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: 2008-08-15 21:09:25 UTC
  • mfrom: (24.1.52 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080815210925-32718zu3nrlotix5
Merge.

* plugin-runner.c (ARGFILE): Renamed to "plugin-runner.conf".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
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
 
8
# image.
 
9
 
 
10
# The environment contains at least:
 
11
#
 
12
#  DESTDIR -- The staging directory where the image is being built.
 
13
 
 
14
# No initramfs pre-requirements
 
15
PREREQ="cryptroot"
 
16
 
 
17
prereqs()
 
18
{
 
19
        echo "$PREREQ"
 
20
}
 
21
 
 
22
case $1 in
 
23
# get pre-requisites
 
24
prereqs)
 
25
        prereqs
 
26
        exit 0
 
27
        ;;
 
28
esac
 
29
 
 
30
. /usr/share/initramfs-tools/hook-functions
 
31
 
 
32
if [ -d /usr/lib/mandos ]; then
 
33
    prefix=/usr
 
34
elif [ -d /usr/local/lib/mandos ]; then
 
35
    prefix=/usr/local
 
36
else
 
37
    # Mandos not found
 
38
    exit 1
 
39
fi
 
40
 
 
41
# The Mandos network client uses the network
 
42
auto_add_modules net
 
43
# The Mandos network client uses IPv6
 
44
force_load ipv6
 
45
 
 
46
# These are directories inside the initrd
 
47
CONFDIR="/conf/conf.d/mandos"
 
48
MANDOSDIR="/lib/mandos"
 
49
PLUGINDIR="${MANDOSDIR}/plugins.d"
 
50
 
 
51
# Make directories
 
52
mkdir --parents "${DESTDIR}${CONFDIR}"
 
53
mkdir --parents "${DESTDIR}${PLUGINDIR}"
 
54
 
 
55
# Copy the Mandos plugin runner
 
56
copy_exec "$prefix"/lib/mandos/plugin-runner "${DESTDIR}${MANDOSDIR}"
 
57
 
 
58
# Copy the plugins
 
59
 
 
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
 
65
        continue
 
66
    fi
 
67
    case "$base" in
 
68
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
 
69
        *) copy_exec "$file" "${PLUGINDIR}";;
 
70
    esac
 
71
done
 
72
 
 
73
# Copy any user-supplied plugins
 
74
for file in /etc/mandos/plugins.d/*; do
 
75
    base="`basename \"$file\"`"
 
76
    case "$base" in
 
77
        *~|.*|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
 
78
        *) copy_exec "$file" "${PLUGINDIR}";;
 
79
    esac
 
80
done
 
81
 
 
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
 
86
fi
 
87
 
 
88
# Key files
 
89
for file in /etc/mandos/*; do
 
90
    if [ -d "$file" ]; then
 
91
        continue
 
92
    fi
 
93
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
 
94
done
 
95
# Create key ring files
 
96
gpg --no-random-seed-file --quiet --batch --no-tty \
 
97
    --no-default-keyring --no-options \
 
98
    --homedir "${DESTDIR}${CONFDIR}" --no-permission-warning \
 
99
    --import-options import-minimal \
 
100
    --import "${DESTDIR}${CONFDIR}/seckey.txt"
 
101
chown nobody "${DESTDIR}${CONFDIR}/secring.gpg"
 
102
 
 
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.
 
107
 
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".)
 
114
 
115
for full in "${PLUGINDIR}" "${CONFDIR}"; do
 
116
    while [ "$full" != "/" ]; do
 
117
        chmod a+rX "${DESTDIR}$full"
 
118
        full="`dirname \"$full\"`"
 
119
    done
 
120
done
 
121
 
 
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"
 
126
done
 
127
for dir in /lib /usr/lib; do
 
128
    chmod --recursive a+rX "${DESTDIR}$dir"
 
129
done