]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/zfs-helpers.sh
zfs filesystem skipped by df -h
[mirror_zfs.git] / scripts / zfs-helpers.sh
CommitLineData
c8f9061f 1#!/bin/sh
f00828e5
BB
2#
3# This script is designed to facilitate in-tree development and testing
4# by installing symlinks on your system which refer to in-tree helper
5# utilities. These helper utilities must be installed to in order to
6# exercise all ZFS functionality. By using symbolic links and keeping
7# the scripts in-tree during development they can be easily modified
8# and those changes tracked.
9#
10# Use the following configuration option to override the installation
11# paths for these scripts. The correct path is automatically set for
12# most distributions but you can optionally set it for your environment.
13#
14# --with-mounthelperdir=DIR install mount.zfs in dir [/sbin]
15# --with-udevdir=DIR install udev helpers [default=check]
16# --with-udevruledir=DIR install udev rules [default=UDEVDIR/rules.d]
099700d9 17# --sysconfdir=DIR install zfs configuration files [PREFIX/etc]
f00828e5
BB
18#
19
c8f9061f 20BASE_DIR=$(dirname "$0")
f00828e5 21SCRIPT_COMMON=common.sh
c8f9061f
BB
22if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
23 . "${BASE_DIR}/${SCRIPT_COMMON}"
f00828e5 24else
c8f9061f 25 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
f00828e5
BB
26fi
27
28PROG=zfs-helpers.sh
c8f9061f
BB
29DRYRUN="no"
30INSTALL="no"
31REMOVE="no"
32VERBOSE="no"
33
34fail() {
35 echo "${PROG}: $1" >&2
36 exit 1
37}
38
39msg() {
40 if [ "$VERBOSE" = "yes" ]; then
41 echo "$@"
42 fi
43}
f00828e5
BB
44
45usage() {
46cat << EOF
47USAGE:
48$0 [dhirv]
49
50DESCRIPTION:
51 Install/remove the ZFS helper utilities.
52
53OPTIONS:
54 -d Dry run
55 -h Show this message
4e33ba4c 56 -i Install the helper utilities
f00828e5
BB
57 -r Remove the helper utilities
58 -v Verbose
59
60$0 -iv
61$0 -r
62
63EOF
64}
65
66while getopts 'hdirv' OPTION; do
67 case $OPTION in
68 h)
69 usage
70 exit 1
71 ;;
72 d)
c8f9061f 73 DRYRUN="yes"
f00828e5
BB
74 ;;
75 i)
c8f9061f 76 INSTALL="yes"
f00828e5
BB
77 ;;
78 r)
c8f9061f 79 REMOVE="yes"
f00828e5
BB
80 ;;
81 v)
c8f9061f 82 VERBOSE="yes"
f00828e5
BB
83 ;;
84 ?)
85 usage
86 exit
87 ;;
88 esac
89done
90
ea49beba 91if [ "$INSTALL" = "yes" ] && [ "$REMOVE" = "yes" ]; then
c8f9061f
BB
92 fail "Specify -i or -r but not both"
93fi
94
ea49beba 95if [ "$INSTALL" = "no" ] && [ "$REMOVE" = "no" ]; then
c8f9061f 96 fail "Either -i or -r must be specified"
f00828e5
BB
97fi
98
c8f9061f
BB
99if [ "$(id -u)" != "0" ]; then
100 fail "Must run as root"
f00828e5
BB
101fi
102
c8f9061f
BB
103if [ "$INTREE" != "yes" ]; then
104 fail "Must be run in-tree"
f00828e5
BB
105fi
106
c8f9061f 107if [ "$VERBOSE" = "yes" ]; then
f00828e5 108 echo "--- Configuration ---"
c8f9061f
BB
109 echo "udevdir: $INSTALL_UDEV_DIR"
110 echo "udevruledir: $INSTALL_UDEV_RULE_DIR"
111 echo "mounthelperdir: $INSTALL_MOUNT_HELPER_DIR"
112 echo "sysconfdir: $INSTALL_SYSCONF_DIR"
85ce3f4f 113 echo "pythonsitedir: $INSTALL_PYTHON_DIR"
c8f9061f 114 echo "dryrun: $DRYRUN"
f00828e5
BB
115 echo
116fi
117
118install() {
ea49beba
GDN
119 src=$1
120 dst=$2
f00828e5 121
c8f9061f 122 if [ -h "$dst" ]; then
f00828e5 123 echo "Symlink exists: $dst"
c8f9061f 124 elif [ -e "$dst" ]; then
f00828e5 125 echo "File exists: $dst"
c8f9061f 126 elif [ ! -e "$src" ]; then
f00828e5
BB
127 echo "Source missing: $src"
128 else
129 msg "ln -s $src $dst"
130
c8f9061f
BB
131 if [ "$DRYRUN" = "no" ]; then
132 DIR=$(dirname "$dst")
133 mkdir -p "$DIR" >/dev/null 2>&1
134 ln -s "$src" "$dst"
f00828e5
BB
135 fi
136 fi
137}
138
139remove() {
ea49beba 140 dst=$1
f00828e5 141
c8f9061f 142 if [ -h "$dst" ]; then
f00828e5 143 msg "rm $dst"
c8f9061f
BB
144 rm "$dst"
145 DIR=$(dirname "$dst")
146 rmdir "$DIR" >/dev/null 2>&1
147 elif [ -e "$dst" ]; then
148 echo "Expected symlink: $dst"
f00828e5
BB
149 fi
150}
151
c8f9061f
BB
152if [ "${INSTALL}" = "yes" ]; then
153 install "$CMD_DIR/mount_zfs/mount.zfs" \
154 "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
155 install "$CMD_DIR/fsck_zfs/fsck.zfs" \
156 "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
157 install "$CMD_DIR/zvol_id/zvol_id" \
158 "$INSTALL_UDEV_DIR/zvol_id"
159 install "$CMD_DIR/vdev_id/vdev_id" \
160 "$INSTALL_UDEV_DIR/vdev_id"
161 install "$UDEV_RULE_DIR/60-zvol.rules" \
162 "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
163 install "$UDEV_RULE_DIR/69-vdev.rules" \
164 "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
165 install "$UDEV_RULE_DIR/90-zfs.rules" \
166 "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
167 install "$CMD_DIR/zpool/zpool.d" \
168 "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
85ce3f4f 169 install "$CONTRIB_DIR/pyzfs/libzfs_core" \
170 "$INSTALL_PYTHON_DIR/libzfs_core"
171 # Ideally we would install these in the configured ${libdir}, which is
172 # by default "/usr/local/lib and unfortunately not included in the
173 # dynamic linker search path.
174 install "$(find "$LIB_DIR/libzfs_core" -type f -name 'libzfs_core.so*')" \
175 "/lib/libzfs_core.so"
176 install "$(find "$LIB_DIR/libnvpair" -type f -name 'libnvpair.so*')" \
177 "/lib/libnvpair.so"
178 ldconfig
f00828e5 179else
c8f9061f
BB
180 remove "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
181 remove "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
182 remove "$INSTALL_UDEV_DIR/zvol_id"
183 remove "$INSTALL_UDEV_DIR/vdev_id"
184 remove "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
185 remove "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
186 remove "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
187 remove "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
85ce3f4f 188 remove "$INSTALL_PYTHON_DIR/libzfs_core"
189 remove "/lib/libzfs_core.so"
190 remove "/lib/libnvpair.so"
191 ldconfig
f00828e5
BB
192fi
193
194exit 0