]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/zfs-helpers.sh
4.10 compat - BIO flag changes and others
[mirror_zfs.git] / scripts / zfs-helpers.sh
CommitLineData
f00828e5
BB
1#!/bin/bash
2#
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.
9#
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.
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#
18
19basedir="$(dirname $0)"
20
21SCRIPT_COMMON=common.sh
22if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
23. "${basedir}/${SCRIPT_COMMON}"
24else
25echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
26fi
27
28PROG=zfs-helpers.sh
29DRYRUN=
30INSTALL=
31REMOVE=
32VERBOSE=
33
34usage() {
35cat << EOF
36USAGE:
37$0 [dhirv]
38
39DESCRIPTION:
40 Install/remove the ZFS helper utilities.
41
42OPTIONS:
43 -d Dry run
44 -h Show this message
45 -i Install the helper utilties
46 -r Remove the helper utilities
47 -v Verbose
48
49$0 -iv
50$0 -r
51
52EOF
53}
54
55while getopts 'hdirv' OPTION; do
56 case $OPTION in
57 h)
58 usage
59 exit 1
60 ;;
61 d)
62 DRYRUN=1
63 ;;
64 i)
65 INSTALL=1
66 ;;
67 r)
68 REMOVE=1
69 ;;
70 v)
71 VERBOSE=1
72 ;;
73 ?)
74 usage
75 exit
76 ;;
77 esac
78done
79
80if [ "${INSTALL}" -a "${REMOVE}" ]; then
81 usage
82 die "Specify -i or -r but not both"
83fi
84
85if [ ! "${INSTALL}" -a ! "${REMOVE}" ]; then
86 usage
87 die "Either -i or -r must be specified"
88fi
89
90if [ $(id -u) != 0 ]; then
91 die "Must run as root"
92fi
93
94if [ "$VERBOSE" ]; then
95 echo "--- Configuration ---"
96 echo "udevdir: $udevdir"
97 echo "udevruledir: $udevruledir"
98 echo "mounthelperdir: $mounthelperdir"
99 echo "DRYRUN: $DRYRUN"
100 echo
101fi
102
103install() {
104 local src=$1
105 local dst=$2
106
107 if [ -h $dst ]; then
108 echo "Symlink exists: $dst"
109 elif [ -e $dst ]; then
110 echo "File exists: $dst"
111 elif [ ! -e $src ]; then
112 echo "Source missing: $src"
113 else
114 msg "ln -s $src $dst"
115
116 if [ ! "$DRYRUN" ]; then
117 ln -s $src $dst
118 fi
119 fi
120}
121
122remove() {
123 local dst=$1
124
125 if [ -h $dst ]; then
126 msg "rm $dst"
127 rm $dst
128 fi
129}
130
131if [ ${INSTALL} ]; then
132 install $CMDDIR/mount_zfs/mount.zfs $mounthelperdir/mount.zfs
133 install $CMDDIR/fsck_zfs/fsck.zfs $mounthelperdir/fsck.zfs
134 install $CMDDIR/zvol_id/zvol_id $udevdir/zvol_id
135 install $CMDDIR/vdev_id/vdev_id $udevdir/vdev_id
136 install $UDEVRULEDIR/60-zvol.rules $udevruledir/60-zvol.rules
137 install $UDEVRULEDIR/69-vdev.rules $udevruledir/69-vdev.rules
138 install $UDEVRULEDIR/90-zfs.rules $udevruledir/90-zfs.rules
139else
140 remove $mounthelperdir/mount.zfs
141 remove $mounthelperdir/fsck.zfs
142 remove $udevdir/zvol_id
143 remove $udevdir/vdev_id
144 remove $udevruledir/60-zvol.rules
145 remove $udevruledir/69-vdev.rules
146 remove $udevruledir/90-zfs.rules
147fi
148
149exit 0