config/dracut/90zfs: handle cases where hostid(1) returns all zeros
[zfs.git] / scripts / zfs-helpers.sh
blobf4edd48e880ffb80084f943aa71d5e223bdc5d43
1 #!/bin/sh
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.
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.
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]
17 # --sysconfdir=DIR install zfs configuration files [PREFIX/etc]
20 BASE_DIR=$(dirname "$0")
21 SCRIPT_COMMON=common.sh
22 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
23 . "${BASE_DIR}/${SCRIPT_COMMON}"
24 else
25 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
28 PROG=zfs-helpers.sh
29 DRYRUN="no"
30 INSTALL="no"
31 REMOVE="no"
32 VERBOSE="no"
34 fail() {
35 echo "${PROG}: $1" >&2
36 exit 1
39 msg() {
40 if [ "$VERBOSE" = "yes" ]; then
41 echo "$@"
45 usage() {
46 cat << EOF
47 USAGE:
48 $0 [dhirv]
50 DESCRIPTION:
51 Install/remove the ZFS helper utilities.
53 OPTIONS:
54 -d Dry run
55 -h Show this message
56 -i Install the helper utilities
57 -r Remove the helper utilities
58 -v Verbose
60 $0 -iv
61 $0 -r
63 EOF
66 while getopts 'hdirv' OPTION; do
67 case $OPTION in
69 usage
70 exit 1
73 DRYRUN="yes"
76 INSTALL="yes"
79 REMOVE="yes"
82 VERBOSE="yes"
85 usage
86 exit
88 esac
89 done
91 if [ "$INSTALL" = "yes" ] && [ "$REMOVE" = "yes" ]; then
92 fail "Specify -i or -r but not both"
95 if [ "$INSTALL" = "no" ] && [ "$REMOVE" = "no" ]; then
96 fail "Either -i or -r must be specified"
99 if [ "$(id -u)" != "0" ]; then
100 fail "Must run as root"
103 if [ "$INTREE" != "yes" ]; then
104 fail "Must be run in-tree"
107 if [ "$VERBOSE" = "yes" ]; then
108 echo "--- Configuration ---"
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"
113 echo "pythonsitedir: $INSTALL_PYTHON_DIR"
114 echo "dryrun: $DRYRUN"
115 echo
118 install() {
119 src=$1
120 dst=$2
122 if [ -h "$dst" ]; then
123 echo "Symlink exists: $dst"
124 elif [ -e "$dst" ]; then
125 echo "File exists: $dst"
126 elif [ ! -e "$src" ]; then
127 echo "Source missing: $src"
128 else
129 msg "ln -s $src $dst"
131 if [ "$DRYRUN" = "no" ]; then
132 DIR=$(dirname "$dst")
133 mkdir -p "$DIR" >/dev/null 2>&1
134 ln -s "$src" "$dst"
139 remove() {
140 dst=$1
142 if [ -h "$dst" ]; then
143 msg "rm $dst"
144 rm "$dst"
145 DIR=$(dirname "$dst")
146 rmdir "$DIR" >/dev/null 2>&1
147 elif [ -e "$dst" ]; then
148 echo "Expected symlink: $dst"
152 if [ "${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"
169 install "$SYSCONF_DIR/zfs/draid.d" \
170 "$INSTALL_SYSCONF_DIR/zfs/draid.d"
171 install "$CONTRIB_DIR/pyzfs/libzfs_core" \
172 "$INSTALL_PYTHON_DIR/libzfs_core"
173 # Ideally we would install these in the configured ${libdir}, which is
174 # by default "/usr/local/lib and unfortunately not included in the
175 # dynamic linker search path.
176 install "$(find "$LIB_DIR/libzfs_core" -type f -name 'libzfs_core.so*')" \
177 "/lib/libzfs_core.so"
178 install "$(find "$LIB_DIR/libnvpair" -type f -name 'libnvpair.so*')" \
179 "/lib/libnvpair.so"
180 ldconfig
181 else
182 remove "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
183 remove "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
184 remove "$INSTALL_UDEV_DIR/zvol_id"
185 remove "$INSTALL_UDEV_DIR/vdev_id"
186 remove "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
187 remove "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
188 remove "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
189 remove "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
190 remove "$INSTALL_SYSCONF_DIR/zfs/draid.d"
191 remove "$INSTALL_PYTHON_DIR/libzfs_core"
192 remove "/lib/libzfs_core.so"
193 remove "/lib/libnvpair.so"
194 ldconfig
197 exit 0