-#!/bin/bash
+#!/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
# --sysconfdir=DIR install zfs configuration files [PREFIX/etc]
#
-basedir="$(dirname $0)"
-
+BASE_DIR=$(dirname "$0")
SCRIPT_COMMON=common.sh
-if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
-. "${basedir}/${SCRIPT_COMMON}"
+if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
+ . "${BASE_DIR}/${SCRIPT_COMMON}"
else
-echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
+ echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
fi
PROG=zfs-helpers.sh
-DRYRUN=
-INSTALL=
-REMOVE=
-VERBOSE=
+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
exit 1
;;
d)
- DRYRUN=1
+ DRYRUN="yes"
;;
i)
- INSTALL=1
+ INSTALL="yes"
;;
r)
- REMOVE=1
+ REMOVE="yes"
;;
v)
- VERBOSE=1
+ VERBOSE="yes"
;;
?)
usage
esac
done
-if [ "${INSTALL}" -a "${REMOVE}" ]; then
- usage
- die "Specify -i or -r but not both"
+if [ "$INSTALL" = "yes" ] && [ "$REMOVE" = "yes" ]; then
+ fail "Specify -i or -r but not both"
+fi
+
+if [ "$INSTALL" = "no" ] && [ "$REMOVE" = "no" ]; then
+ fail "Either -i or -r must be specified"
fi
-if [ ! "${INSTALL}" -a ! "${REMOVE}" ]; then
- usage
- die "Either -i or -r must be specified"
+if [ "$(id -u)" != "0" ]; then
+ fail "Must run as root"
fi
-if [ $(id -u) != 0 ]; then
- die "Must run as root"
+if [ "$INTREE" != "yes" ]; then
+ fail "Must be run in-tree"
fi
-if [ "$VERBOSE" ]; then
+if [ "$VERBOSE" = "yes" ]; then
echo "--- Configuration ---"
- echo "udevdir: $udevdir"
- echo "udevruledir: $udevruledir"
- echo "mounthelperdir: $mounthelperdir"
- echo "sysconfdir: $sysconfdir"
- echo "DRYRUN: $DRYRUN"
+ echo "udevdir: $INSTALL_UDEV_DIR"
+ echo "udevruledir: $INSTALL_UDEV_RULE_DIR"
+ echo "mounthelperdir: $INSTALL_MOUNT_HELPER_DIR"
+ echo "sysconfdir: $INSTALL_SYSCONF_DIR"
+ echo "pythonsitedir: $INSTALL_PYTHON_DIR"
+ echo "dryrun: $DRYRUN"
echo
fi
install() {
- local src=$1
- local dst=$2
+ src=$1
+ dst=$2
- if [ -h $dst ]; then
+ if [ -h "$dst" ]; then
echo "Symlink exists: $dst"
- elif [ -e $dst ]; then
+ elif [ -e "$dst" ]; then
echo "File exists: $dst"
- elif [ ! -e $src ]; then
+ elif [ ! -e "$src" ]; then
echo "Source missing: $src"
else
msg "ln -s $src $dst"
- if [ ! "$DRYRUN" ]; then
- mkdir -p $(dirname $dst) &>/dev/null
- 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
+ dst=$1
- if [ -h $dst ]; then
+ if [ -h "$dst" ]; then
msg "rm $dst"
- rm $dst
- rmdir $(dirname $dst) &>/dev/null
+ rm "$dst"
+ DIR=$(dirname "$dst")
+ rmdir "$DIR" >/dev/null 2>&1
+ elif [ -e "$dst" ]; then
+ echo "Expected symlink: $dst"
fi
}
-if [ ${INSTALL} ]; then
- install $CMDDIR/mount_zfs/mount.zfs $mounthelperdir/mount.zfs
- install $CMDDIR/fsck_zfs/fsck.zfs $mounthelperdir/fsck.zfs
- install $CMDDIR/zvol_id/zvol_id $udevdir/zvol_id
- install $CMDDIR/vdev_id/vdev_id $udevdir/vdev_id
- install $UDEVRULEDIR/60-zvol.rules $udevruledir/60-zvol.rules
- install $UDEVRULEDIR/69-vdev.rules $udevruledir/69-vdev.rules
- install $UDEVRULEDIR/90-zfs.rules $udevruledir/90-zfs.rules
- install $CMDDIR/zpool/zpool.d $sysconfdir/zfs/zpool.d
+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"
+ install "$CONTRIB_DIR/pyzfs/libzfs_core" \
+ "$INSTALL_PYTHON_DIR/libzfs_core"
+ # Ideally we would install these in the configured ${libdir}, which is
+ # by default "/usr/local/lib and unfortunately not included in the
+ # dynamic linker search path.
+ install "$(find "$LIB_DIR/libzfs_core" -type f -name 'libzfs_core.so*')" \
+ "/lib/libzfs_core.so"
+ install "$(find "$LIB_DIR/libnvpair" -type f -name 'libnvpair.so*')" \
+ "/lib/libnvpair.so"
+ ldconfig
else
- remove $mounthelperdir/mount.zfs
- remove $mounthelperdir/fsck.zfs
- remove $udevdir/zvol_id
- remove $udevdir/vdev_id
- remove $udevruledir/60-zvol.rules
- remove $udevruledir/69-vdev.rules
- remove $udevruledir/90-zfs.rules
- remove $sysconfdir/zfs/zpool.d
+ 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"
+ remove "$INSTALL_PYTHON_DIR/libzfs_core"
+ remove "/lib/libzfs_core.so"
+ remove "/lib/libnvpair.so"
+ ldconfig
fi
exit 0