annotate sbin/fzfs @ 421:a571a30bcf8a

Begin the implementation of "fzfs copy-tree"
author Franz Glasner <hg@dom66.de>
date Tue, 19 Sep 2023 19:35:29 +0200
parents bb0a0384b5da
children 4363929b0a3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 #!/bin/sh
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 # -*- indent-tabs-mode: nil; -*-
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 #: A ZFS management helper tool.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 #: :Author: Franz Glasner
386
84d2735fe7f6 Simplified version tagging a lot: it is also faster now.
Franz Glasner <fzglas.hg@dom66.de>
parents: 380
diff changeset
7 #: :Copyright: (c) 2022-2023 Franz Glasner.
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 #: All rights reserved.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9 #: :License: BSD 3-Clause "New" or "Revised" License.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10 #: See LICENSE for details.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11 #: If you cannot find LICENSE see
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12 #: <https://opensource.org/licenses/BSD-3-Clause>
386
84d2735fe7f6 Simplified version tagging a lot: it is also faster now.
Franz Glasner <fzglas.hg@dom66.de>
parents: 380
diff changeset
13 #: :ID: @(#)@@SIMPLEVERSIONTAG@@
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 set -eu
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 VERSION="@@VERSION@@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 USAGE='
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21 USAGE: fzfs [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ]
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 OPTIONS:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 -V Print the program name and version number to stdout and exit
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 -h Print this help message to stdout and exit
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29 COMMANDS:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
31 copy-tree [-A] [-M MOUNTPOINT] [-n] [-u] SOURCE-DATASET DEST-DATASET
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
32
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
33 create-tree [-A] [-M MOUNTPOINT] [-n] [-p] [-u] SOURCE-DATASET DEST-DATASET
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
34
283
1fc3b04b39fa Build and package manual pages for fzfs, fzfs-mount and fzfs-umount.
Franz Glasner <fzglas.hg@dom66.de>
parents: 276
diff changeset
35 mount [-O] [-N] [-P] [-u] [-n] DATASET [MOUNTPOINT]
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37 umount DATASET
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39 unmount
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 '
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
43
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
44 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
45 #: Determine some important dataset properties that are set locally
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
46 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
47 #: Args:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
48 #: $1: the dataset
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
49 #: $2 ...: the properties to check for
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
50 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
51 #: Output (stdout):
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
52 #: An option string suited for use in "zfs create"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
53 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
54 _get_local_properties() {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
55 local ds
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
56
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
57 local _res _prop _value _source
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
58
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
59 ds="${1}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
60 shift
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
61
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
62 _res=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
63
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
64 for _prop in "$@" ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
65 IFS=$'\t' read -r _value _source <<EOF73GHASGJKKJ354
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
66 $(zfs get -H -p -o value,source "${_prop}" "${ds}")
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
67 EOF73GHASGJKKJ354
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
68 case "${_source}" in
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
69 local)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
70 if [ -z "${_res}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
71 _res="-o ${_prop}=${_value}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
72 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
73 _res="${_res} -o ${_prop}=${_value}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
74 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
75 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
76 *)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
77 # VOID
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
78 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
79 esac
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
80 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
81 echo "${_res}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
82 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
83
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
84
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
85 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
86 #: Implementation of the "mount" command.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
87 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88 #: Mount a dataset and recursively all its children datasets.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
90 command_mount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
91 local _dsname _mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92 local _opt_dry_run _opt_mount_outside _opt_mount_natural
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93 local _opt_mount_children_only
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
95 local _name _mp _canmount _mounted _rootds_mountpoint _relative_mp _real_mp
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
96
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97 _opt_dry_run=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
98 _opt_mount_outside=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
99 _opt_mount_natural=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
100 _opt_mount_children_only=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 while getopts "ONPnu" _opt ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
102 case ${_opt} in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 O)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104 _opt_mount_outside="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
106 N)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
107 _opt_mount_natural="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 P)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110 _opt_mount_children_only="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
112 n|u)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113 _opt_dry_run="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
114 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
115 \?|:)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 return 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
118 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
119 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120 shift $((OPTIND-1))
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
121 OPTIND=1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
122
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
123 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
124 _mountpoint="${2-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
125
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
126 if [ -z "${_dsname}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
127 echo "ERROR: no dataset given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
128 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
129 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
130
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
131 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
132 { echo "ERROR: root dataset does not exist" >&2; return 1; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
133
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
134 if [ -z "${_mountpoint}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
135 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
136 _mountpoint="${_rootds_mountpoint}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
137 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
138 echo "ERROR: no mountpoint given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
139 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
140 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
143 echo "ERROR: Cannot have a custom mountpoint when \"-O\" is given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
146 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
148 # Eventually remove a trailing slash
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149 _mountpoint="${_mountpoint%/}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 if [ -z "${_mountpoint}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
151 echo "ERROR: would mount over the root filesystem" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
152 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
153 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
154
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
155 zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
156 | {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
157 while IFS=$'\t' read -r _name _mp _canmount _mounted ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
158 # Skip filesystems that are already mounted
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
159 [ "${_mounted}" = "yes" ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
160 # Skip filesystems that must not be mounted
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
161 [ "${_canmount}" = "off" ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
162 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
163 # Mount only the children and skip the given parent dataset
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
164 # if required
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
165 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
166 [ \( "${_opt_mount_children_only}" = "yes" \) -a \( "${_name}" = "${_dsname}" \) ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
167 case "${_mp}" in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
168 "none"|"legacy")
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
169 # Do nothing for filesystem with unset or legacy mountpoints
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
170 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
171 "${_rootds_mountpoint}"|"${_rootds_mountpoint}/"*)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
172 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
173 # Handle only mountpoints that have a mountpoint below
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
174 # the parent datasets mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
175 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
176
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
177 # Determine the mountpoint relative to the parent mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
178 _relative_mp="${_mp#${_rootds_mountpoint}}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
179 # Eventually remove a trailing slash
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
180 _relative_mp="${_relative_mp%/}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
181 # The real effective full mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
182 _real_mp="${_mountpoint}${_relative_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
183
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
184 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
185 # Consistency and sanity check: computed real mountpoint must
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
186 # be equal to the configured mountpoint when no custom mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
187 # is given.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
188 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
189 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
190 if [ "${_real_mp}" != "${_mp}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
191 echo "ERROR: mountpoint mismatch" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
192 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
193 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
194 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
195
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
196 if [ "${_opt_dry_run}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
197 echo "Would mount ${_name} on ${_real_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
198 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
199 mkdir -p "${_real_mp}" 1> /dev/null 2> /dev/null || \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
200 { echo "ERROR: cannot create mountpoint ${_real_mp}" >&2; return 1; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
201 echo "Mounting ${_name} on ${_real_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
202 mount -t zfs "${_name}" "${_real_mp}" || return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
203 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
204 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
205 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
206 if [ "${_opt_mount_outside}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
207 if [ "${_opt_dry_run}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
208 echo "Would mount ${_name} on configured ZFS dataset mountpoint ${_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
209 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
210 echo "Mounting ${_name} on configured ZFS dataset mountpoint ${_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
211 zfs mount "${_name}" || return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
212 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
213 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
214 echo "Skipping ${_name} because its configured ZFS mountpoint is not relative to given root dataset" 2>&1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
215 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
216 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
217 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
218 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
219
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
220 return 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
221 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
222 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
223
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
224
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
225 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
226 #: Implement the "umount" command.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
227 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
228 #: Umount a datasets and recursively all its children datasets.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
229 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
230 command_umount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
231 local _dsname
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
232
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
233 local _name _mp _rest _rootds_mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
234
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
235 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
236 [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" 1>&2; return 2; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
237
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
238 # Just determine whether the given dataset name exists
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
239 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || { echo "ERROR: dataset not found" 1>&2; return 1; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
240
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
241 mount -t zfs -p \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
242 | grep -E "^${_dsname}(/|\s)" \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
243 | sort -n -r \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
244 | {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
245 while IFS=' '$'\t' read -r _name _mp _rest ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
246 echo "Umounting ${_name} on ${_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
247 umount "${_mp}" || return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
248 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
249 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
250 return 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
251 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
252
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
253
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
254 #:
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
255 #: Implementation of "copy-tree"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
256 #:
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
257 command_copy_tree() {
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
258 local _ds_source _ds_target
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
259 local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_dry_run
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
260
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
261 local _ds_source_base _ds_source_snapshot
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
262
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
263 while getopts "AM:nu" _opt ; do
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
264 case ${_opt} in
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
265 A)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
266 _opt_mount_noauto="-o canmount=noauto"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
267 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
268 M)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
269 _opt_mountpoint="${OPTARG}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
270 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
271 n)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
272 _opt_dry_run="-n"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
273 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
274 u)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
275 _opt_nomount="-u"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
276 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
277 \?)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
278 return 2;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
279 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
280 esac
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
281 done
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
282 shift $((OPTID-1))
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
283 OPTIND=1
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
284
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
285 _ds_source="${1-}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
286 _ds_target="${2-}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
287
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
288 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; }
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
289 [ -z "${_snapshot_name}" ] && { echo "ERROR: no snapshot name given" 1>&2; return 2; }
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
290
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
291 _ds_source_base="${_ds_source%@*}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
292 _ds_source_snapshot="${_ds_source##*@}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
293
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
294 if [ "${_ds_source_snapshot}" = "${_ds_source_base}" ]; then
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
295 # No snapshot given
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
296 _ds_source_snapshot=""
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
297 fi
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
298 }
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
299
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
300
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
301 #:
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
302 #: Implement the "create-tree" command
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
303 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
304 #: Create a ZFS dataset tree from a source tree tree including important properties
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
305 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
306 command_create_tree() {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
307 local _source_ds _target_ds
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
308 local _opt_dry_run _opt_mountpoint _opt_noauto _opt_nomount _opt_canmount_parent_only
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
309
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
310 local _opt _source_name _snapshot_name _current_name _current_type _relative_name _zfs_opts _zfs_canmount _zfs_mountpoint
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
311
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
312 _opt_noauto=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
313 _opt_dry_run=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
314 _opt_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
315 _opt_nomount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
316 _opt_canmount_parent_only=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
317
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
318 while getopts "AM:npu" _opt ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
319 case ${_opt} in
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
320 A)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
321 _opt_noauto="-o canmount=noauto"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
322 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
323 M)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
324 _opt_mountpoint="${OPTARG}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
325 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
326 n)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
327 _opt_dry_run="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
328 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
329 p)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
330 _opt_canmount_parent_only="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
331 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
332 u)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
333 _opt_nomount="-u"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
334 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
335 \?|:)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
336 return 2;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
337 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
338 esac
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
339 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
340 shift $((OPTIND-1))
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
341 OPTIND=1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
342
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
343 _source_ds="${1-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
344 _target_ds="${2-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
345
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
346 [ -z "${_source_ds}" ] && { echo "ERROR: no source dataset given" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
347 [ -z "${_target_ds}" ] && { echo "ERROR: no destination dataset given" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
348
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
349 _source_name="${_source_ds%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
350 if [ "${_source_name}" != "${_source_ds}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
351 _snapshot_name="${_source_ds##*@}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
352 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
353 _snapshot_name=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
354 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
355
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
356 [ -n "${_snapshot_name}" ] && { echo "ERROR: No snapshot sources are supported yet" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
357
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
358 zfs list -H -r -t filesystem -o name,type "${_source_ds}" \
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
359 | {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
360 while IFS=$'\t' read -r _current_name _current_type ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
361 # Determine the relative name of the dataset
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
362 _relative_name="${_current_name#${_source_name}}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
363 _relative_name="${_relative_name%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
364 if [ "${_current_type}" != "filesystem" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
365 echo "ERROR: Got a snapshot but expected a filesystem" 1>&2
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
366 return 1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
367 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
368 _zfs_opts="$(_get_local_properties "${_current_name}" atime exec setuid compression primarycache sync readonly)"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
369 if [ -z "${_relative_name}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
370 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
371 # Root
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
372 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
373 if [ -z "${_opt_noauto}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
374 _zfs_canmount="$(_get_local_properties "${_current_name}" canmount)"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
375 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
376 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
377 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
378 if [ -n "${_opt_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
379 _zfs_mountpoint="${_opt_mountpoint}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
380 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
381 _zfs_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
382 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
383
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
384 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
385 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
386 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
387 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
388 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} -o mountpoint=${_zfs_mountpoint} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
389 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
390 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
391 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
392 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
393 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
394 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} -o "mountpoint=${_zfs_mountpoint}" "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
395 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
396 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
397 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
398 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
399 # Children
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
400 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
401 if [ -z "${_opt_noauto}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
402 if [ "${_opt_canmount_parent_only}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
403 _zfs_canmount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
404 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
405 _zfs_canmount="$(_get_local_properties "${_current_name}" canmount)"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
406 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
407 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
408 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
409 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
410 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
411 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
412 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
413 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
414 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
415 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
416 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
417 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
418 return 0
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
419 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
420
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
421
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
422 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
423 # Global option handling
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
424 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
425 while getopts "Vh" _opt ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
426 case ${_opt} in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
427 V)
408
bb0a0384b5da FIX: Program name in fzfs's version string
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 386
diff changeset
428 printf 'fzfs %s\n' '@@SIMPLEVERSIONSTR@@'
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
429 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
430 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
431 h)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
432 echo "${USAGE}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
433 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
434 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
435 \?)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
436 exit 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
437 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
438 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
439 echo "ERROR: option handling failed" 1>&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
440 exit 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
441 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
442 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
443 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
444 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
445 # Reset the Shell's option handling system to prepare for handling
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
446 # command-local options.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
447 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
448 shift $((OPTIND-1))
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
449 OPTIND=1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
450
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
451 test $# -gt 0 || { echo "ERROR: no command given" 1>&2; exit 2; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
452
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
453 command="$1"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
454 shift
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
455
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
456 case "${command}" in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
457 mount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
458 command_mount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
459 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
460 umount|unmount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
461 command_umount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
462 ;;
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
463 copy-tree)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
464 command_copy_tree "$@"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
465 ;;
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
466 create-tree)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
467 command_create_tree "$@"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
468 ;;
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
469 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
470 echo "ERROR: unknown command \`${command}'" 1>&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
471 exit 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
472 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
473 esac