105
 
if [ -r /conf/conf.d/cryptroot ]; then
 
108
 
    # Do not replace cryptroot file unless we need to.
 
112
 
    mandos=/lib/mandos/plugin-runner
 
115
 
    # parse /conf/conf.d/cryptroot.  Format:
 
116
 
    # target=sda2_crypt,source=/dev/sda2,rootdev,key=none,keyscript=/foo/bar/baz
 
117
 
    # Is the root device specially marked?
 
119
 
    while read -r options; do
 
121
 
            rootdev,*|*,rootdev,*|*,rootdev)
 
122
 
                # If the root device is specially marked, don't change all
 
123
 
                # lines in crypttab by default.
 
 
108
# Do not replace cryptroot file unless we need to.
 
 
112
mandos=/lib/mandos/plugin-runner
 
 
115
# parse /conf/conf.d/cryptroot.  Format:
 
 
116
# target=sda2_crypt,source=/dev/sda2,rootdev,key=none,keyscript=/foo/bar/baz
 
 
117
# Is the root device specially marked?
 
 
119
while read -r options; do
 
 
121
        rootdev,*|*,rootdev,*|*,rootdev)
 
 
122
            # If the root device is specially marked, don't change all
 
 
123
            # lines in crypttab by default.
 
 
127
done < /conf/conf.d/cryptroot
 
 
129
exec 3>/conf/conf.d/cryptroot.mandos
 
 
130
while read -r options; do
 
 
133
    changethis="$changeall"
 
 
134
    # Split option line on commas
 
 
137
    for opt in $options; do
 
 
138
        # Find the keyscript option, if any
 
 
141
                keyscript="${opt#keyscript=}"
 
 
142
                newopts="$newopts,$opt"
 
 
145
            # Always use Mandos on the root device, if marked
 
 
148
                newopts="$newopts,$opt"
 
 
150
            # Don't use Mandos on resume device, if marked
 
 
153
                newopts="$newopts,$opt"
 
 
156
                newopts="$newopts,$opt"
 
127
 
    done < /conf/conf.d/cryptroot
 
129
 
    exec 3>/conf/conf.d/cryptroot.mandos
 
130
 
    while read -r options; do
 
133
 
        changethis="$changeall"
 
134
 
        # Split option line on commas
 
137
 
        for opt in $options; do
 
138
 
            # Find the keyscript option, if any
 
141
 
                    keyscript="${opt#keyscript=}"
 
142
 
                    newopts="$newopts,$opt"
 
145
 
                # Always use Mandos on the root device, if marked
 
148
 
                    newopts="$newopts,$opt"
 
150
 
                # Don't use Mandos on resume device, if marked
 
153
 
                    newopts="$newopts,$opt"
 
156
 
                    newopts="$newopts,$opt"
 
162
 
        # If there was no keyscript option, add one.
 
163
 
        if [ "$changethis" = yes ] && [ -z "$keyscript" ]; then
 
164
 
            replace_cryptroot=yes
 
165
 
            newopts="$newopts,keyscript=$mandos"
 
167
 
        newopts="${newopts#,}"
 
169
 
    done < /conf/conf.d/cryptroot
 
172
 
    # If we need to, replace the old cryptroot file with the new file.
 
173
 
    if [ "$replace_cryptroot" = yes ]; then
 
174
 
        mv /conf/conf.d/cryptroot /conf/conf.d/cryptroot.mandos-old
 
175
 
        mv /conf/conf.d/cryptroot.mandos /conf/conf.d/cryptroot
 
177
 
        rm -f /conf/conf.d/cryptroot.mandos
 
179
 
elif [ -x /usr/bin/cryptroot-unlock ]; then
 
180
 
    # Use setsid if available
 
181
 
    if command -v setsid >/dev/null 2>&1; then
 
182
 
        setsid /lib/mandos/mandos-to-cryptroot-unlock &
 
184
 
        /lib/mandos/mandos-to-cryptroot-unlock &
 
 
162
    # If there was no keyscript option, add one.
 
 
163
    if [ "$changethis" = yes ] && [ -z "$keyscript" ]; then
 
 
164
        replace_cryptroot=yes
 
 
165
        newopts="$newopts,keyscript=$mandos"
 
 
167
    newopts="${newopts#,}"
 
 
169
done < /conf/conf.d/cryptroot
 
 
172
# If we need to, replace the old cryptroot file with the new file.
 
 
173
if [ "$replace_cryptroot" = yes ]; then
 
 
174
    mv /conf/conf.d/cryptroot /conf/conf.d/cryptroot.mandos-old
 
 
175
    mv /conf/conf.d/cryptroot.mandos /conf/conf.d/cryptroot
 
 
177
    rm /conf/conf.d/cryptroot.mandos