/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
1
#!/bin/sh
2
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
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.
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
9
10
# The environment contains at least:
11
#
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
12
#  DESTDIR -- The staging directory where the image is being built.
13
14
# No initramfs pre-requirements
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
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
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
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
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
42
auto_add_modules net
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
43
# The Mandos network client uses IPv6
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
44
force_load ipv6
45
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
46
# These are directories inside the initrd
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
47
CONFDIR="/conf/conf.d/mandos"
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
48
MANDOSDIR="/lib/mandos"
49
PLUGINDIR="${MANDOSDIR}/plugins.d"
50
51
# Make directories
52
mkdir --parents "${DESTDIR}${CONFDIR}"
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
53
mkdir --parents "${DESTDIR}${PLUGINDIR}"
54
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
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
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
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
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
73
# Copy any user-supplied plugins
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
74
for file in /etc/mandos/plugins.d/*; do
75
    base="`basename \"$file\"`"
76
    case "$base" in
155 by Teddy Hogeborn
* README: Improved wording.
77
	*~|.*|\#*\#|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
78
	*) copy_exec "$file" "${PLUGINDIR}";;
79
    esac
80
done
81
82
# GPGME needs /usr/bin/gpg
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
83
if ! [ -e "${DESTDIR}/usr/bin/gpg" ] \
84
    && [ -n "`ls \"${DESTDIR}\"/usr/lib/libgpgme.so* 2>/dev/null`" ]; then
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
85
    copy_exec /usr/bin/gpg
86
fi
87
155 by Teddy Hogeborn
* README: Improved wording.
88
# Key files and config files
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
89
for file in /etc/mandos/*; do
90
    if [ -d "$file" ]; then
91
	continue
92
    fi
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
93
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
94
done
95
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
96
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
97
# its plugin directory and its config file.  However, since almost all
98
# files in initrd have been created with umask 027, this opening of
99
# permissions is needed.
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
100
# 
101
# (The umask is not really intended to affect the files inside the
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
102
# initrd; it is intended to affect the initrd.img file itself, since
103
# it now contains secret key files.  There is, however, no other way
104
# to set the permission of the initrd.img file without a race
105
# condition.  This umask is set by "initramfs-tools-hook-conf",
106
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
107
# 
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
108
for full in "${PLUGINDIR}" "${CONFDIR}"; do
109
    while [ "$full" != "/" ]; do
110
	chmod a+rX "${DESTDIR}$full"
111
	full="`dirname \"$full\"`"
112
    done
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
113
done
74 by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR): New.
114
115
# Reset some other things to sane permissions which we have
116
# inadvertently affected with our umask setting.
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
117
for dir in / /bin /etc /keyscripts /sbin /scripts /usr /usr/bin; do
118
    chmod a+rX "${DESTDIR}$dir"
119
done
120
for dir in /lib /usr/lib; do
155 by Teddy Hogeborn
* README: Improved wording.
121
    find "${DESTDIR}$dir" \! -perm /u+rw,g+r -prune -o -print0 \
122
	| xargs --null chmod a+rX
68 by Teddy Hogeborn
* initramfs-tools-hook: New.
123
done