Path: blob/main/sys/contrib/openzfs/scripts/zfs-helpers.sh
48266 views
#!/bin/sh1# shellcheck disable=SC21542#3# This script is designed to facilitate in-tree development and testing4# by installing symlinks on your system which refer to in-tree helper5# utilities. These helper utilities must be installed to in order to6# exercise all ZFS functionality. By using symbolic links and keeping7# the scripts in-tree during development they can be easily modified8# and those changes tracked.9#10# Use the following configuration option to override the installation11# paths for these scripts. The correct path is automatically set for12# 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]17# --sysconfdir=DIR install zfs configuration files [PREFIX/etc]18#1920BASE_DIR=${0%/*}21SCRIPT_COMMON=common.sh22if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then23. "${BASE_DIR}/${SCRIPT_COMMON}"24else25echo "Missing helper script ${SCRIPT_COMMON}" && exit 126fi2728PROG=zfs-helpers.sh29DRYRUN="no"30INSTALL="no"31REMOVE="no"32VERBOSE="no"3334fail() {35echo "${PROG}: $1" >&236exit 137}3839msg() {40if [ "$VERBOSE" = "yes" ]; then41echo "$@"42fi43}4445usage() {46cat << EOF47USAGE:48$0 [-dhirv]4950DESCRIPTION:51Install/remove the ZFS helper utilities.5253OPTIONS:54-d Dry run55-h Show this message56-i Install the helper utilities57-r Remove the helper utilities58-v Verbose5960$0 -iv61$0 -r6263EOF64}6566while getopts 'hdirv' OPTION; do67case $OPTION in68h)69usage70exit 171;;72d)73DRYRUN="yes"74;;75i)76INSTALL="yes"77;;78r)79REMOVE="yes"80;;81v)82VERBOSE="yes"83;;84?)85usage86exit87;;88*)89;;90esac91done9293if [ "$INSTALL" = "yes" ] && [ "$REMOVE" = "yes" ]; then94fail "Specify -i or -r but not both"95fi9697if [ "$INSTALL" = "no" ] && [ "$REMOVE" = "no" ]; then98fail "Either -i or -r must be specified"99fi100101if [ "$(id -u)" != "0" ] && [ "$DRYRUN" = "no" ]; then102fail "Must run as root"103fi104105if [ "$INTREE" != "yes" ]; then106fail "Must be run in-tree"107fi108109if [ "$VERBOSE" = "yes" ]; then110echo "--- Configuration ---"111echo "udevdir: $INSTALL_UDEV_DIR"112echo "udevruledir: $INSTALL_UDEV_RULE_DIR"113echo "mounthelperdir: $INSTALL_MOUNT_HELPER_DIR"114echo "sysconfdir: $INSTALL_SYSCONF_DIR"115echo "pythonsitedir: $INSTALL_PYTHON_DIR"116echo "dryrun: $DRYRUN"117echo118fi119120install() {121src=$1122dst=$2123124# We may have an old symlink pointing to different ZFS workspace.125# Remove the old symlink if it doesn't point to our workspace.126if [ -h "$dst" ] && [ "$(readlink -f """$dst""")" != "$src" ] ; then127echo "Removing old symlink: $dst -> $(readlink """$dst""")"128rm "$dst"129fi130131if [ -h "$dst" ]; then132echo "Symlink exists: $dst"133elif [ -e "$dst" ]; then134echo "File exists: $dst"135elif ! [ -e "$src" ]; then136echo "Source missing: $src"137else138msg "ln -s $src $dst"139140if [ "$DRYRUN" = "no" ]; then141DIR=${dst%/*}142mkdir -p "$DIR" >/dev/null 2>&1143ln -s "$src" "$dst"144fi145fi146}147148remove() {149dst=$1150151if [ -h "$dst" ]; then152msg "rm $dst"153rm "$dst"154DIR=${dst%/*}155rmdir "$DIR" >/dev/null 2>&1156elif [ -e "$dst" ]; then157echo "Expected symlink: $dst"158fi159}160161if [ "${INSTALL}" = "yes" ]; then162for cmd in "mount.zfs" "fsck.zfs"; do163install "$CMD_DIR/$cmd" "$INSTALL_MOUNT_HELPER_DIR/$cmd"164done165for udev in "$UDEV_CMD_DIR/zvol_id" "$UDEV_SCRIPT_DIR/vdev_id"; do166install "$udev" "$INSTALL_UDEV_DIR/${udev##*/}"167done168for rule in "60-zvol.rules" "69-vdev.rules" "90-zfs.rules"; do169install "$UDEV_RULE_DIR/$rule" "$INSTALL_UDEV_RULE_DIR/$rule"170done171install "$ZPOOL_SCRIPT_DIR" "$INSTALL_SYSCONF_DIR/zfs/zpool.d"172install "$ZPOOL_COMPAT_DIR" "$INSTALL_PKGDATA_DIR/compatibility.d"173install "$CONTRIB_DIR/pyzfs/libzfs_core" "$INSTALL_PYTHON_DIR/libzfs_core"174# Ideally we would install these in the configured ${libdir}, which is175# by default "/usr/local/lib and unfortunately not included in the176# dynamic linker search path.177install "$LIB_DIR"/libzfs_core.so.?.?.? "/lib/libzfs_core.so"178install "$LIB_DIR"/libnvpair.so.?.?.? "/lib/libnvpair.so"179[ "$DRYRUN" = "no" ] && ldconfig180else181remove "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"182remove "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"183remove "$INSTALL_UDEV_DIR/zvol_id"184remove "$INSTALL_UDEV_DIR/vdev_id"185remove "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"186remove "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"187remove "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"188remove "$INSTALL_SYSCONF_DIR/zfs/zpool.d"189remove "$INSTALL_PKGDATA_DIR/compatibility.d"190remove "$INSTALL_PYTHON_DIR/libzfs_core"191remove "/lib/libzfs_core.so"192remove "/lib/libnvpair.so"193ldconfig194fi195196exit 0197198199