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