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