backport to buster
[hcoop/debian/openafs.git] / debian / openafs-client-precheck
CommitLineData
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.
29PATH=/bin:/usr/bin:/sbin:/usr/sbin
30
31# Gather up options and post startup script name, if present
32if [ -f /etc/openafs/afs.conf ]; then
33 . /etc/openafs/afs.conf
34fi
35
36CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo}
37MODULEROOT=${MODULEROOT:-/lib/modules/`uname -r`}
38
39do_nothing_env() {
40 cat > /var/cache/openafs-client/openafs-client.env <<EOF
41AFSD_ARGS=-help
42AFS_SETCRYPT=-help
43AFS_SYSNAME=-help
44KMOD=--version
45EOF
46}
47
48# Exit if the package is not installed.
49[ -x /sbin/afsd ] || exit 1
50
51# Do some other checks for prerequisites
52if ! [ -f "${CACHEINFO}" ]; then
53 echo "required cacheinfo file does not exist" >&2
54 exit 1
55fi
56if ! [ -d "$(awk -F : '{print $1}' < "${CACHEINFO}")" ]; then
57 echo "AFS mountpoint is not a directory or does not exist" >&2
58 exit 1
59fi
60if pidof /sbin/afsd || pidof /usr/sbin/afsd; then
61 echo "afsd is already running, continuing" >&2
62 do_nothing_env
63 exit 0
64fi
65
66# Ensure that the kernel module is loaded.
67if ! /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
82fi
83
84# Determine which afsd options to use. /etc/openafs/afs.conf contains the
85# settings that are checked here.
86if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then
87 AFSD_OPTIONS="$VERBOSE"
88else
89 AFSD_OPTIONS="$OPTIONS $VERBOSE"
90fi
91
92# These variables are from /etc/openafs/afs.conf.client and are managed
93# automatically by debconf.
94case "$AFS_AFSDB" in
95[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee])
96 AFSD_OPTIONS="$AFSD_OPTIONS -afsdb"
97esac
98case "$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"
104esac
105case "$AFS_FAKESTAT" in
106[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee])
107 AFSD_OPTIONS="$AFSD_OPTIONS -fakestat"
108esac
109
110case "$AFS_CRYPT" in
111[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee])
112 AFS_SETCRYPT=on
113 ;;
114*)
115 AFS_SETCRYPT=off
116esac
117
118# Generate an EnvironmentFile for use by systemd.
119cat > /var/cache/openafs-client/openafs-client.env <<EOF
120AFSD_ARGS=${AFSD_OPTIONS}
121AFS_SETCRYPT=${AFS_SETCRYPT}
122AFS_SYSNAME=${AFS_SYSNAME}
123KMOD=openafs
124EOF