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