]>
Commit | Line | Data |
---|---|---|
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 | ||
19 | basedir="$(dirname $0)" | |
20 | ||
21 | SCRIPT_COMMON=common.sh | |
22 | if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then | |
23 | . "${basedir}/${SCRIPT_COMMON}" | |
24 | else | |
25 | echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 | |
26 | fi | |
27 | ||
28 | PROG=zfs-helpers.sh | |
29 | DRYRUN= | |
30 | INSTALL= | |
31 | REMOVE= | |
32 | VERBOSE= | |
33 | ||
34 | usage() { | |
35 | cat << EOF | |
36 | USAGE: | |
37 | $0 [dhirv] | |
38 | ||
39 | DESCRIPTION: | |
40 | Install/remove the ZFS helper utilities. | |
41 | ||
42 | OPTIONS: | |
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 | ||
52 | EOF | |
53 | } | |
54 | ||
55 | while 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 | |
78 | done | |
79 | ||
80 | if [ "${INSTALL}" -a "${REMOVE}" ]; then | |
81 | usage | |
82 | die "Specify -i or -r but not both" | |
83 | fi | |
84 | ||
85 | if [ ! "${INSTALL}" -a ! "${REMOVE}" ]; then | |
86 | usage | |
87 | die "Either -i or -r must be specified" | |
88 | fi | |
89 | ||
90 | if [ $(id -u) != 0 ]; then | |
91 | die "Must run as root" | |
92 | fi | |
93 | ||
94 | if [ "$VERBOSE" ]; then | |
95 | echo "--- Configuration ---" | |
96 | echo "udevdir: $udevdir" | |
97 | echo "udevruledir: $udevruledir" | |
98 | echo "mounthelperdir: $mounthelperdir" | |
99 | echo "DRYRUN: $DRYRUN" | |
100 | echo | |
101 | fi | |
102 | ||
103 | install() { | |
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 | ||
122 | remove() { | |
123 | local dst=$1 | |
124 | ||
125 | if [ -h $dst ]; then | |
126 | msg "rm $dst" | |
127 | rm $dst | |
128 | fi | |
129 | } | |
130 | ||
131 | if [ ${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 | |
139 | else | |
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 | |
147 | fi | |
148 | ||
149 | exit 0 |