zfs_enter rework followup
[zfs.git] / scripts / zfs-helpers.sh
blob8dcb0630126a6444474ae6d51ffc8f1228ac71d7
1 #!/bin/sh
2 # shellcheck disable=SC2154
4 # This script is designed to facilitate in-tree development and testing
5 # by installing symlinks on your system which refer to in-tree helper
6 # utilities. These helper utilities must be installed to in order to
7 # exercise all ZFS functionality. By using symbolic links and keeping
8 # the scripts in-tree during development they can be easily modified
9 # and those changes tracked.
11 # Use the following configuration option to override the installation
12 # paths for these scripts. The correct path is automatically set for
13 # most distributions but you can optionally set it for your environment.
15 # --with-mounthelperdir=DIR install mount.zfs in dir [/sbin]
16 # --with-udevdir=DIR install udev helpers [default=check]
17 # --with-udevruledir=DIR install udev rules [default=UDEVDIR/rules.d]
18 # --sysconfdir=DIR install zfs configuration files [PREFIX/etc]
21 BASE_DIR=${0%/*}
22 SCRIPT_COMMON=common.sh
23 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
24 . "${BASE_DIR}/${SCRIPT_COMMON}"
25 else
26 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
29 PROG=zfs-helpers.sh
30 DRYRUN="no"
31 INSTALL="no"
32 REMOVE="no"
33 VERBOSE="no"
35 fail() {
36 echo "${PROG}: $1" >&2
37 exit 1
40 msg() {
41 if [ "$VERBOSE" = "yes" ]; then
42 echo "$@"
46 usage() {
47 cat << EOF
48 USAGE:
49 $0 [-dhirv]
51 DESCRIPTION:
52 Install/remove the ZFS helper utilities.
54 OPTIONS:
55 -d Dry run
56 -h Show this message
57 -i Install the helper utilities
58 -r Remove the helper utilities
59 -v Verbose
61 $0 -iv
62 $0 -r
64 EOF
67 while getopts 'hdirv' OPTION; do
68 case $OPTION in
70 usage
71 exit 1
74 DRYRUN="yes"
77 INSTALL="yes"
80 REMOVE="yes"
83 VERBOSE="yes"
86 usage
87 exit
91 esac
92 done
94 if [ "$INSTALL" = "yes" ] && [ "$REMOVE" = "yes" ]; then
95 fail "Specify -i or -r but not both"
98 if [ "$INSTALL" = "no" ] && [ "$REMOVE" = "no" ]; then
99 fail "Either -i or -r must be specified"
102 if [ "$(id -u)" != "0" ] && [ "$DRYRUN" = "no" ]; then
103 fail "Must run as root"
106 if [ "$INTREE" != "yes" ]; then
107 fail "Must be run in-tree"
110 if [ "$VERBOSE" = "yes" ]; then
111 echo "--- Configuration ---"
112 echo "udevdir: $INSTALL_UDEV_DIR"
113 echo "udevruledir: $INSTALL_UDEV_RULE_DIR"
114 echo "mounthelperdir: $INSTALL_MOUNT_HELPER_DIR"
115 echo "sysconfdir: $INSTALL_SYSCONF_DIR"
116 echo "pythonsitedir: $INSTALL_PYTHON_DIR"
117 echo "dryrun: $DRYRUN"
118 echo
121 install() {
122 src=$1
123 dst=$2
125 if [ -h "$dst" ]; then
126 echo "Symlink exists: $dst"
127 elif [ -e "$dst" ]; then
128 echo "File exists: $dst"
129 elif ! [ -e "$src" ]; then
130 echo "Source missing: $src"
131 else
132 msg "ln -s $src $dst"
134 if [ "$DRYRUN" = "no" ]; then
135 DIR=${dst%/*}
136 mkdir -p "$DIR" >/dev/null 2>&1
137 ln -s "$src" "$dst"
142 remove() {
143 dst=$1
145 if [ -h "$dst" ]; then
146 msg "rm $dst"
147 rm "$dst"
148 DIR=${dst%/*}
149 rmdir "$DIR" >/dev/null 2>&1
150 elif [ -e "$dst" ]; then
151 echo "Expected symlink: $dst"
155 if [ "${INSTALL}" = "yes" ]; then
156 for cmd in "mount.zfs" "fsck.zfs"; do
157 install "$CMD_DIR/$cmd" "$INSTALL_MOUNT_HELPER_DIR/$cmd"
158 done
159 for udev in "$UDEV_CMD_DIR/zvol_id" "$UDEV_SCRIPT_DIR/vdev_id"; do
160 install "$udev" "$INSTALL_UDEV_DIR/${udev##*/}"
161 done
162 for rule in "60-zvol.rules" "69-vdev.rules" "90-zfs.rules"; do
163 install "$UDEV_RULE_DIR/$rule" "$INSTALL_UDEV_RULE_DIR/$rule"
164 done
165 install "$ZPOOL_SCRIPT_DIR" "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
166 install "$CONTRIB_DIR/pyzfs/libzfs_core" "$INSTALL_PYTHON_DIR/libzfs_core"
167 # Ideally we would install these in the configured ${libdir}, which is
168 # by default "/usr/local/lib and unfortunately not included in the
169 # dynamic linker search path.
170 install "$LIB_DIR"/libzfs_core.so.?.?.? "/lib/libzfs_core.so"
171 install "$LIB_DIR"/libnvpair.so.?.?.? "/lib/libnvpair.so"
172 [ "$DRYRUN" = "no" ] && ldconfig
173 else
174 remove "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
175 remove "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
176 remove "$INSTALL_UDEV_DIR/zvol_id"
177 remove "$INSTALL_UDEV_DIR/vdev_id"
178 remove "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
179 remove "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
180 remove "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
181 remove "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
182 remove "$INSTALL_PYTHON_DIR/libzfs_core"
183 remove "/lib/libzfs_core.so"
184 remove "/lib/libnvpair.so"
185 ldconfig
188 exit 0