annotate sbin/fzfs @ 492:312aebce590c

FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 30 Aug 2024 14:17:45 +0200
parents a2011285f054
children eb42828c0cbf
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
438
9c3b1966ba91 Extend copyright to 2024
Franz Glasner <fzglas.hg@dom66.de>
parents: 429
diff changeset
7 #: :Copyright: (c) 2022-2024 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
442
a2011285f054 Move "_get_local_zfs_properties_for_create()" into common.subr
Franz Glasner <fzglas.hg@dom66.de>
parents: 441
diff changeset
44 _p_datadir="$(dirname "$0")"/../share/local-bsdtools
a2011285f054 Move "_get_local_zfs_properties_for_create()" into common.subr
Franz Glasner <fzglas.hg@dom66.de>
parents: 441
diff changeset
45 . "${_p_datadir}/common.subr"
380
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
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
48 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
49 #: 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
50 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 #: 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
52 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53 command_mount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
54 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
55 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
56 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
57
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
58 local _name _mp _canmount _mounted _rootds_mountpoint _rootds_mountpoint_prefix _relative_mp _real_mp
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60 _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
61 _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
62 _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
63 _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
64 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
65 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
66 O)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 _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
68 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 N)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 _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
71 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
72 P)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
73 _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
74 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
75 n|u)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
76 _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
77 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
78 \?|:)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
79 return 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
80 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
81 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
82 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
83 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
84 OPTIND=1
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 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
87 _mountpoint="${2-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 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
90 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
91 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94 _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
95 { 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
96
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97 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
98 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
99 _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
100 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 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
102 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105 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
106 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
107 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 # 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
112 _mountpoint="${_mountpoint%/}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113 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
114 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
115 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
118 if [ "${_rootds_mountpoint}" = "/" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
119 _rootds_mountpoint_prefix="/"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
120 else
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
121 _rootds_mountpoint_prefix="${_rootds_mountpoint}/"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
122 fi
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
123
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
124 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
125 | {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
126 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
127 # 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
128 [ "${_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
129 # 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
130 [ "${_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
131 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
132 # 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
133 # if required
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
134 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
135 [ \( "${_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
136 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
137 "none"|"legacy")
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
138 # 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
139 ;;
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
140 "${_rootds_mountpoint}"|"${_rootds_mountpoint_prefix}"*)
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 # Handle only mountpoints that have a mountpoint below
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
143 # or exactly at the parent datasets mountpoint
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
146 #
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
147 # Determine the mountpoint relative to the parent
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
148 # mountpoint. Extra effort is needed because the root
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
149 # filesystem mount is just a single slash.
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
150 #
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
151 if [ "${_mp}" = "${_rootds_mountpoint}" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
152 if [ "${_name}" != "${_dsname}" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
153 echo "ERRROR: child dataset mounts over root dataset" >&2
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
154 return 1
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
155 fi
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
156 _relative_mp=""
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
157 _real_mp="${_mountpoint}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
158 else
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
159 _relative_mp="${_mp#${_rootds_mountpoint_prefix}}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
160 # Eventually remove a trailing slash
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
161 _relative_mp="${_relative_mp%/}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
162 if [ -z "${_relative_mp}" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
163 echo "ERROR: got an empty relative mountpoint in child" >&2
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
164 return 1
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
165 fi
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
166 # The real effective full mountpoint
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
167 _real_mp="${_mountpoint}/${_relative_mp}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
168 fi
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
169
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 # 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
172 # 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
173 # is given.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
174 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
175 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
176 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
177 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
178 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
179 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
180 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
181
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
182 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
183 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
184 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
185 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
186 { 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
187 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
188 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
189 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
190 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
191 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
192 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
193 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
194 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
195 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
196 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
197 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
198 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
199 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
200 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
201 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
202 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
203 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
204 done
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 return 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
207 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
208 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
209
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
210
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
211 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
212 #: 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
213 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
214 #: 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
215 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
216 command_umount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
217 local _dsname
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
218
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
219 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
220
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
221 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
222 [ -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
223
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
224 # 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
225 _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
226
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
227 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
228 | 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
229 | 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
230 | {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
231 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
232 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
233 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
234 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
235 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
236 return 0
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
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
239
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
240 #:
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
241 #: Implementation of "copy-tree"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
242 #:
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
243 command_copy_tree() {
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
244 local _ds_source _ds_target
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
245 local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_keep _opt_dry_run
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
246
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
247 local _ds_source_base _ds_source_snapshot _snapshot_suffix
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
248 local _ds_tree _ds _ds_relname _ds_canmount
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
249 local _arg_canmount _arg_mp1 _arg_mp2
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
250
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
251 _opt_mountpoint=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
252 _opt_mount_noauto=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
253 _opt_nomount=""
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
254 _opt_keep=""
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
255 _opt_dry_run=""
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
256
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
257 while getopts "AM:knu" _opt ; do
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
258 case ${_opt} in
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
259 A)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
260 _opt_mount_noauto="-o canmount=noauto"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
261 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
262 M)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
263 _opt_mountpoint="${OPTARG}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
264 ;;
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
265 k)
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
266 _opt_keep="yes"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
267 ;;
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
268 n)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
269 _opt_dry_run="-n"
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 u)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
272 _opt_nomount="-u"
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 \?)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
275 return 2;
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 esac
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
278 done
422
4363929b0a3e FIX: Typo in variable name "OPTID" -> "OPTIND"
Franz Glasner <fzglas.hg@dom66.de>
parents: 421
diff changeset
279 shift $((OPTIND-1))
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
280 OPTIND=1
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
281
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
282 _ds_source="${1-}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
283 _ds_target="${2-}"
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 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; }
423
1d6ee78f06ef FIX: Another typo in variable name (COPY-PASTE)
Franz Glasner <fzglas.hg@dom66.de>
parents: 422
diff changeset
286 [ -z "${_ds_target}" ] && { echo "ERROR: no target name given" 1>&2; return 2; }
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
287
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
288 if ! zfs get -H name "${_ds_source}" >/dev/null 2>&1; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
289 echo "ERROR: source dataset does not exist: ${_ds_source}" 1>&2;
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
290 return 1;
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
291 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
292 if zfs get -H name "${_ds_target}" >/dev/null 2>&1; then
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
293 echo "ERROR: target dataset already exists: ${_ds_target}" 1>&2;
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
294 return 1;
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
295 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
296
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
297 _ds_source_base="${_ds_source%@*}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
298 _ds_source_snapshot="${_ds_source##*@}"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
299 _snapshot_suffix="@${_ds_source_snapshot}"
421
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 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
302 # No snapshot given
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
303 [ "${_ds_source_base}" = "${_ds_source}" ] || { echo "ERROR:" 1>&2; return 1; }
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
304 _ds_source_snapshot=""
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
305 _snapshot_suffix=""
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
306 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
307
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
308 _ds_tree=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
309
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
310 while IFS=$'\n' read -r _ds; do
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
311 if [ -z "${_ds_tree}" ]; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
312 _ds_tree="${_ds}"
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
313 else
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
314 _ds_tree="${_ds_tree}"$'\n'"${_ds}"
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
315 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
316 done <<EOF20ee7ea0781414fab8c305d3875d15e
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
317 $(zfs list -H -r -t filesystem -o name -s name "${_ds_source_base}")
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
318 EOF20ee7ea0781414fab8c305d3875d15e
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
319 # Check the existence of all intermediate datasets and their shapshots
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
320 IFS=$'\n'
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
321 for _ds in ${_ds_tree}; do
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
322 if ! zfs get -H name "${_ds}${_snapshot_suffix}" >/dev/null 2>&1; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
323 echo "ERROR: child dataset does not exist: ${_ds}${_snapshot_suffix}" 1>&2
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
324 return 1
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
325 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
326 done
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
327 IFS=$'\n'
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
328 for _ds in ${_ds_tree}; do
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
329 # Reset IFS
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
330 IFS=$' \t\n'
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
331
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
332 # Determine the relative name of the dataset
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
333 _ds_relname="${_ds#${_ds_source_base}}"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
334
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
335 _ds_canmount=$(zfs get -H -o value canmount "${_ds}")
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
336
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
337 if [ "${_ds_canmount}" = "off" ]; then
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
338 _arg_canmount="-o canmount=off"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
339 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
340 _arg_canmount="${_opt_mount_noauto}"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
341 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
342
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
343 if [ -z "${_ds_relname}" ]; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
344 #
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
345 # Source root to target root
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
346 #
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
347 if [ -z "${_opt_mountpoint}" ]; then
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
348 _arg_mp1=-x
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
349 _arg_mp2=mountpoint
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
350 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
351 _arg_mp1=-o
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
352 _arg_mp2="mountpoint=${_opt_mountpoint}"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
353 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
354 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
355 _arg_mp1=-x
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
356 _arg_mp2=mountpoint
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
357 fi
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
358 if [ -z "${_opt_dry_run}" ]; then
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
359 zfs send -Lec -p -v "${_ds}${_snapshot_suffix}" | zfs receive -v ${_opt_nomount} ${_arg_canmount} ${_arg_mp1} "${_arg_mp2}" "${_ds_target}${_ds_relname}"
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
360 else
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
361 echo "Would execute: zfs send -Lec -p -v '${_ds}${_snapshot_suffix}' | zfs receive -v ${_opt_nomount} ${_arg_canmount} ${_arg_mp1} '${_arg_mp2}' '${_ds_target}${_ds_relname}'"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
362 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
363 # for the loop
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
364 IFS=$'\n'
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
365 done
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
366 # Reset to default
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
367 IFS=$' \t\n'
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
368 # Remove received snapshots by default
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
369 if [ -n "${_ds_source_snapshot}" ]; then
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
370 if [ -z "${_opt_keep}" ]; then
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
371 if [ -z "${_opt_dry_run}" ]; then
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
372 zfs destroy -rv "${_ds_target}${_snapshot_suffix}"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
373 else
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
374 echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
375 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
376 fi
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
377 fi
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
378 }
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
379
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
380
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
381 #:
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
382 #: Implement the "create-tree" command
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 #: 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
385 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
386 command_create_tree() {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
387 local _source_ds _target_ds
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
388 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
389
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
390 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
391
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
392 _opt_noauto=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
393 _opt_dry_run=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
394 _opt_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
395 _opt_nomount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
396 _opt_canmount_parent_only=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
397
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
398 while getopts "AM:npu" _opt ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
399 case ${_opt} in
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
400 A)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
401 _opt_noauto="-o canmount=noauto"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
402 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
403 M)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
404 _opt_mountpoint="${OPTARG}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
405 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
406 n)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
407 _opt_dry_run="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
408 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
409 p)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
410 _opt_canmount_parent_only="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
411 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
412 u)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
413 _opt_nomount="-u"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
414 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
415 \?|:)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
416 return 2;
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 esac
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
419 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
420 shift $((OPTIND-1))
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
421 OPTIND=1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
422
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
423 _source_ds="${1-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
424 _target_ds="${2-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
425
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
426 [ -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
427 [ -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
428
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
429 _source_name="${_source_ds%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
430 if [ "${_source_name}" != "${_source_ds}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
431 _snapshot_name="${_source_ds##*@}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
432 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
433 _snapshot_name=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
434 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
435
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
436 [ -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
437
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
438 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
439 | {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
440 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
441 # Determine the relative name of the dataset
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
442 _relative_name="${_current_name#${_source_name}}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
443 _relative_name="${_relative_name%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
444 if [ "${_current_type}" != "filesystem" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
445 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
446 return 1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
447 fi
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
448 _zfs_opts="$(_get_local_zfs_properties_for_create "${_current_name}" atime exec setuid compression primarycache sync readonly)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
449 if [ -z "${_relative_name}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
450 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
451 # Root
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
452 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
453 if [ -z "${_opt_noauto}" ]; then
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
454 _zfs_canmount="$(_get_local_zfs_properties_for_create "${_current_name}" canmount)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
455 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
456 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
457 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
458 if [ -n "${_opt_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
459 _zfs_mountpoint="${_opt_mountpoint}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
460 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
461 _zfs_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
462 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
463
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
464 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
465 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
466 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
467 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
468 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
469 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
470 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
471 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
472 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
473 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
474 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
475 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
476 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
477 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
478 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
479 # Children
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
480 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
481 if [ -z "${_opt_noauto}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
482 if [ "${_opt_canmount_parent_only}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
483 _zfs_canmount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
484 else
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
485 _zfs_canmount="$(_get_local_zfs_properties_for_create "${_current_name}" canmount)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
486 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
487 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
488 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
489 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
490 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
491 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
492 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
493 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
494 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
495 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
496 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
497 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
498 return 0
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
499 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
500
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
501
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
502 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
503 # 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
504 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
505 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
506 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
507 V)
408
bb0a0384b5da FIX: Program name in fzfs's version string
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 386
diff changeset
508 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
509 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
510 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
511 h)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
512 echo "${USAGE}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
513 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
514 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
515 \?)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
516 exit 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
517 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
518 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
519 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
520 exit 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
521 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
522 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
523 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
524 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
525 # 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
526 # 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
527 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
528 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
529 OPTIND=1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
530
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
531 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
532
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
533 command="$1"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
534 shift
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
535
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
536 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
537 mount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
538 command_mount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
539 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
540 umount|unmount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
541 command_umount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
542 ;;
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
543 copy-tree)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
544 command_copy_tree "$@"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
545 ;;
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
546 create-tree)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
547 command_create_tree "$@"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
548 ;;
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
549 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
550 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
551 exit 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
552 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
553 esac