mirror_zfs/scripts/zfs-helpers.sh
Brian Behlendorf c8f9061fc7 Retire legacy test infrastructure
* Removed zpios kmod, utility, headers and man page.

* Removed unused scripts zpios-profile/*, zpios-test/*,
  zpool-config/*, smb.sh, zpios-sanity.sh, zpios-survey.sh,
  zpios.sh, and zpool-create.sh.

* Removed zfs-script-config.sh.in.  When building 'make' generates
  a common.sh with in-tree path information from the common.sh.in
  template.  This file and sourced by the test scripts and used
  for in-tree testing, it is not included in the packages.  When
  building packages 'make install' uses the same template to
  create a new common.sh which is appropriate for the packaging.

* Removed unused functions/variables from scripts/common.sh.in.
  Only minimal path information and configuration environment
  variables remain.

* Removed unused scripts from scripts/ directory.

* Remaining shell scripts in the scripts directory updated to
  cleanly pass shellcheck and added to checked scripts.

* Renamed tests/test-runner/cmd/ to tests/test-runner/bin/ to
  match install location name.

* Removed last traces of the --enable-debug-dmu-tx configure
  options which was retired some time ago.

Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #6509
2017-08-15 17:26:38 -07:00

180 lines
3.9 KiB
Bash
Executable File

#!/bin/sh
#
# This script is designed to facilitate in-tree development and testing
# by installing symlinks on your system which refer to in-tree helper
# utilities. These helper utilities must be installed to in order to
# exercise all ZFS functionality. By using symbolic links and keeping
# the scripts in-tree during development they can be easily modified
# and those changes tracked.
#
# Use the following configuration option to override the installation
# paths for these scripts. The correct path is automatically set for
# most distributions but you can optionally set it for your environment.
#
# --with-mounthelperdir=DIR install mount.zfs in dir [/sbin]
# --with-udevdir=DIR install udev helpers [default=check]
# --with-udevruledir=DIR install udev rules [default=UDEVDIR/rules.d]
# --sysconfdir=DIR install zfs configuration files [PREFIX/etc]
#
BASE_DIR=$(dirname "$0")
SCRIPT_COMMON=common.sh
if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
. "${BASE_DIR}/${SCRIPT_COMMON}"
else
echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
fi
PROG=zfs-helpers.sh
DRYRUN="no"
INSTALL="no"
REMOVE="no"
VERBOSE="no"
fail() {
echo "${PROG}: $1" >&2
exit 1
}
msg() {
if [ "$VERBOSE" = "yes" ]; then
echo "$@"
fi
}
usage() {
cat << EOF
USAGE:
$0 [dhirv]
DESCRIPTION:
Install/remove the ZFS helper utilities.
OPTIONS:
-d Dry run
-h Show this message
-i Install the helper utilities
-r Remove the helper utilities
-v Verbose
$0 -iv
$0 -r
EOF
}
while getopts 'hdirv' OPTION; do
case $OPTION in
h)
usage
exit 1
;;
d)
DRYRUN="yes"
;;
i)
INSTALL="yes"
;;
r)
REMOVE="yes"
;;
v)
VERBOSE="yes"
;;
?)
usage
exit
;;
esac
done
if [ "$INSTALL" = "yes" -a "$REMOVE" = "yes" ]; then
fail "Specify -i or -r but not both"
fi
if [ "$INSTALL" = "no" -a "$REMOVE" = "no" ]; then
fail "Either -i or -r must be specified"
fi
if [ "$(id -u)" != "0" ]; then
fail "Must run as root"
fi
if [ "$INTREE" != "yes" ]; then
fail "Must be run in-tree"
fi
if [ "$VERBOSE" = "yes" ]; then
echo "--- Configuration ---"
echo "udevdir: $INSTALL_UDEV_DIR"
echo "udevruledir: $INSTALL_UDEV_RULE_DIR"
echo "mounthelperdir: $INSTALL_MOUNT_HELPER_DIR"
echo "sysconfdir: $INSTALL_SYSCONF_DIR"
echo "dryrun: $DRYRUN"
echo
fi
install() {
local src=$1
local dst=$2
if [ -h "$dst" ]; then
echo "Symlink exists: $dst"
elif [ -e "$dst" ]; then
echo "File exists: $dst"
elif [ ! -e "$src" ]; then
echo "Source missing: $src"
else
msg "ln -s $src $dst"
if [ "$DRYRUN" = "no" ]; then
DIR=$(dirname "$dst")
mkdir -p "$DIR" >/dev/null 2>&1
ln -s "$src" "$dst"
fi
fi
}
remove() {
local dst=$1
if [ -h "$dst" ]; then
msg "rm $dst"
rm "$dst"
DIR=$(dirname "$dst")
rmdir "$DIR" >/dev/null 2>&1
elif [ -e "$dst" ]; then
echo "Expected symlink: $dst"
fi
}
if [ "${INSTALL}" = "yes" ]; then
install "$CMD_DIR/mount_zfs/mount.zfs" \
"$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
install "$CMD_DIR/fsck_zfs/fsck.zfs" \
"$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
install "$CMD_DIR/zvol_id/zvol_id" \
"$INSTALL_UDEV_DIR/zvol_id"
install "$CMD_DIR/vdev_id/vdev_id" \
"$INSTALL_UDEV_DIR/vdev_id"
install "$UDEV_RULE_DIR/60-zvol.rules" \
"$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
install "$UDEV_RULE_DIR/69-vdev.rules" \
"$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
install "$UDEV_RULE_DIR/90-zfs.rules" \
"$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
install "$CMD_DIR/zpool/zpool.d" \
"$INSTALL_SYSCONF_DIR/zfs/zpool.d"
else
remove "$INSTALL_MOUNT_HELPER_DIR/mount.zfs"
remove "$INSTALL_MOUNT_HELPER_DIR/fsck.zfs"
remove "$INSTALL_UDEV_DIR/zvol_id"
remove "$INSTALL_UDEV_DIR/vdev_id"
remove "$INSTALL_UDEV_RULE_DIR/60-zvol.rules"
remove "$INSTALL_UDEV_RULE_DIR/69-vdev.rules"
remove "$INSTALL_UDEV_RULE_DIR/90-zfs.rules"
remove "$INSTALL_SYSCONF_DIR/zfs/zpool.d"
fi
exit 0