File: initscript.in

package info (click to toggle)
cryptmount 6.3.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,208 kB
  • sloc: ansic: 6,249; sh: 2,478; makefile: 159; sed: 16
file content (152 lines) | stat: -rw-r--r-- 3,790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# boot-time init script for cryptmount
# RW Penney, August 2006

# Basic support for Linux Standard Base:
### BEGIN INIT INFO
# Provides:             cryptmount
# Required-Start:       $remote_fs
# Required-Stop:        $remote_fs
# Should-Start:         $syslog
# Should-Stop:          $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    setup encrypted filesystems/swap at boot
# Description:          configure device-mapper targets for encrypted
#                       filesystems and swap-partitions managed by cryptmount
### END INIT INFO

. /lib/lsb/init-functions

CM_EXE=@EXENAME@
DISK_ID_PATH=/dev/disk/by-id/

CM_BOOTDV=""
CM_BOOTSW=""
CM_BOOTFS=""

# Check whether cryptmount executable is usable:
test -x "${CM_EXE}" || exit 5

# Read user-specified lists of filesystems to initialize:
if [ -f /etc/default/cryptmount ]; then
    . /etc/default/cryptmount
fi


configured() {
    # Check if any of the targets needed at boot has been configured:
    for target in ${CM_BOOTDV} ${CM_BOOTFS} ${CM_BOOTSW}; do
        if [ -b "${DISK_ID_PATH}/dm-name-${target}" ]; then
            true
            return
        fi
    done
    false
}


dodevices() {
    case "$1" in
        start)  test -z "${CM_BOOTDV}" || ${CM_EXE} --prepare ${CM_BOOTDV}
            ;;
        stop)   test -z "${CM_BOOTDV}" || ${CM_EXE} --release ${CM_BOOTDV}
            ;;
    esac
}


doswaps() {
    case "$1" in
        start)  test -z "${CM_BOOTSW}" || ${CM_EXE} --swapon ${CM_BOOTSW}
            ;;
        stop)   test -z "${CM_BOOTSW}" || ${CM_EXE} --swapoff ${CM_BOOTSW}
            ;;
    esac
}


dofilesys() {
    case "$1" in
        start)  test -z "${CM_BOOTFS}" || ${CM_EXE} --mount ${CM_BOOTFS}
            ;;
        stop)   test -z "${CM_BOOTFS}" || ${CM_EXE} --unmount ${CM_BOOTFS}
            ;;
    esac
}


doALL() {
    if test -n "${CM_BOOTDV}" -o -n "${CM_BOOTSW}" \
            -o -n "${CM_BOOTFS}" -o -n "${CM_EARLYDV}"; then
        log_warning_msg "Using /etc/default/cryptmount is DEPRECATED - please use 'bootaction={mount|swap|prepare}' flags within @SYSCONF_DIR@/cmtab"
    fi

    case "$1" in
        start)
            dodevices start
            doswaps start
            dofilesys start
            ;;
        stop)
            dofilesys stop
            doswaps stop
            dodevices stop
            ;;
    esac
}


case "$1" in
    start)
        # Make sure that kernel device-mapper is available:
        modprobe -q -a dm-mod dm-crypt || true

        ${CM_EXE} --system-boot

        if configured; then
            log_action_msg "cryptmount ${STAGE}auto-filesystems seem to be already configured"
        else
            log_action_begin_msg "Starting cryptmount ${STAGE}targets (hit shift/ctrl if short of entropy)"
            doALL start
            log_action_end_msg 0
        fi
        ;;
    stop)
        ${CM_EXE} --system-shutdown

        if configured; then
            log_action_begin_msg "Stopping cryptmount ${STAGE}targets"
            doALL stop
            log_action_end_msg 0
        fi
        ${CM_EXE} --safetynet || true
        ;;
    restart)
        ${CM_EXE} --system-shutdown
        if configured; then
            doALL stop
        fi

        ${CM_EXE} --system-boot
        doALL start
        ;;
    force-reload|reload)
        # nothing to do
        ;;
    status)
        if configured; then
            log_action_msg "cryptmount ${STAGE}auto-filesystems are in use"
        else
            log_action_msg "cryptmount ${STAGE}auto-filesystems do not appear to be in use"
            exit 3
        fi
        ;;
    *)
        echo "Usage: $0 " \
            " {start|stop|restart|reload|force-reload|status}" >&2
        exit 1
        ;;
esac

exit 0