Commit | Line | Data |
---|---|---|
b7cfede0 BK |
1 | #! /bin/sh |
2 | # Copyright (C) 2014 by Benjamin Kaduk | |
3 | # All rights reserved. | |
4 | # | |
5 | # Redistribution and use in source and binary forms, with or without | |
6 | # modification, are permitted provided that the following conditions | |
7 | # are met: | |
8 | # | |
9 | # * Redistributions of source code must retain the above copyright | |
10 | # notice, this list of conditions and the following disclaimer. | |
11 | # | |
12 | # * Redistributions in binary form must reproduce the above copyright | |
13 | # notice, this list of conditions and the following disclaimer in | |
14 | # the documentation and/or other materials provided with the | |
15 | # distribution. | |
16 | # | |
17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
20 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
21 | # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
28 | # OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
30 | ||
31 | # Gather up options and post startup script name, if present | |
32 | if [ -f /etc/openafs/afs.conf ]; then | |
33 | . /etc/openafs/afs.conf | |
34 | fi | |
35 | ||
36 | CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo} | |
37 | MODULEROOT=${MODULEROOT:-/lib/modules/`uname -r`} | |
38 | ||
39 | do_nothing_env() { | |
40 | cat > /var/cache/openafs-client/openafs-client.env <<EOF | |
41 | AFSD_ARGS=-help | |
42 | AFS_SETCRYPT=-help | |
43 | AFS_SYSNAME=-help | |
44 | KMOD=--version | |
45 | EOF | |
46 | } | |
47 | ||
48 | # Exit if the package is not installed. | |
49 | [ -x /sbin/afsd ] || exit 1 | |
50 | ||
51 | # Do some other checks for prerequisites | |
52 | if ! [ -f "${CACHEINFO}" ]; then | |
53 | echo "required cacheinfo file does not exist" >&2 | |
54 | exit 1 | |
55 | fi | |
56 | if ! [ -d "$(awk -F : '{print $1}' < "${CACHEINFO}")" ]; then | |
57 | echo "AFS mountpoint is not a directory or does not exist" >&2 | |
58 | exit 1 | |
59 | fi | |
60 | if pidof /sbin/afsd || pidof /usr/sbin/afsd; then | |
61 | echo "afsd is already running, continuing" >&2 | |
62 | do_nothing_env | |
63 | exit 0 | |
64 | fi | |
65 | ||
66 | # Ensure that the kernel module is loaded. | |
67 | if ! /sbin/lsmod | grep -Fq openafs; then | |
68 | modprobe openafs | |
69 | status=$? | |
70 | ||
71 | if [ $status -ne 0 ] ; then | |
72 | echo "Failed to load openafs.ko. Does it need to be built?" >&2 | |
73 | # We cannot fail hard on a missing module, though, as that will | |
74 | # cause our unit to be put in a disabled state. | |
75 | if grep -q openafs "$MODULEROOT/modules.dep"; then | |
76 | exit $status | |
77 | else | |
78 | do_nothing_env | |
79 | exit 0 | |
80 | fi | |
81 | fi | |
82 | fi | |
83 | ||
84 | # Determine which afsd options to use. /etc/openafs/afs.conf contains the | |
85 | # settings that are checked here. | |
86 | if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then | |
87 | AFSD_OPTIONS="$VERBOSE" | |
88 | else | |
89 | AFSD_OPTIONS="$OPTIONS $VERBOSE" | |
90 | fi | |
91 | ||
92 | # These variables are from /etc/openafs/afs.conf.client and are managed | |
93 | # automatically by debconf. | |
94 | case "$AFS_AFSDB" in | |
95 | [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) | |
96 | AFSD_OPTIONS="$AFSD_OPTIONS -afsdb" | |
97 | esac | |
98 | case "$AFS_DYNROOT" in | |
99 | [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) | |
100 | AFSD_OPTIONS="$AFSD_OPTIONS -dynroot" | |
101 | ;; | |
102 | [Ss][Pp][Aa][Rr][Ss][Ee]) | |
103 | AFSD_OPTIONS="$AFSD_OPTIONS -dynroot-sparse" | |
104 | esac | |
105 | case "$AFS_FAKESTAT" in | |
106 | [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) | |
107 | AFSD_OPTIONS="$AFSD_OPTIONS -fakestat" | |
108 | esac | |
109 | ||
110 | case "$AFS_CRYPT" in | |
111 | [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) | |
112 | AFS_SETCRYPT=on | |
113 | ;; | |
114 | *) | |
115 | AFS_SETCRYPT=off | |
116 | esac | |
117 | ||
118 | # Generate an EnvironmentFile for use by systemd. | |
119 | cat > /var/cache/openafs-client/openafs-client.env <<EOF | |
120 | AFSD_ARGS=${AFSD_OPTIONS} | |
121 | AFS_SETCRYPT=${AFS_SETCRYPT} | |
122 | AFS_SYSNAME=${AFS_SYSNAME} | |
123 | KMOD=openafs | |
124 | EOF |