Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
annotate sbin/fjail @ 204:ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 21 Aug 2022 13:23:10 +0200 |
| parents | eb95c986cc59 |
| children | fcfa674c8444 |
| rev | line source |
|---|---|
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
1 #!/bin/sh |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
2 # -*- indent-tabs-mode: nil; -*- |
|
86
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
3 : 'A very minimal BSD Jail management tool. |
|
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
4 |
|
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
5 :Author: Franz Glasner |
| 193 | 6 :Copyright: (c) 2019-2022 Franz Glasner. |
|
86
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
7 All rights reserved. |
|
104
6f6058939e48
Use the "Full name" in the license section for "fjail" also
Franz Glasner <fzglas.hg@dom66.de>
parents:
93
diff
changeset
|
8 :License: BSD 3-Clause "New" or "Revised" License. |
|
86
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
9 See LICENSE for details. |
|
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
10 If you cannot find LICENSE see |
|
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
11 <https://opensource.org/licenses/BSD-3-Clause> |
| 93 | 12 :ID: @(#)@@PKGORIGIN@@ $HGid$ |
|
86
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
13 |
|
a3b9d4fe560e
Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents:
85
diff
changeset
|
14 ' |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
15 |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
16 set -eu |
| 73 | 17 |
| 18 VERSION="@@VERSION@@" | |
| 19 | |
|
105
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
20 USAGE=' |
| 75 | 21 USAGE: fjail [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ] |
| 22 | |
| 23 OPTIONS: | |
| 24 | |
|
81
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
25 -V Print the program name and version number to stdout and exit |
|
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
26 |
| 75 | 27 -h Print this help message to stdout and exit |
| 28 | |
| 29 COMMANDS: | |
| 30 | |
| 31 datasets [-u] PARENT CHILD | |
| 32 | |
| 33 Create ZFS datasets to be used within a jail | |
| 34 | |
| 35 PARENT must exist already and CHILD must not exist. | |
| 36 | |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
37 -A Set "canmount=auto" for datasets |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
38 -s Also create a dataset for freebsd-update data files |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
39 -t Create a more tiny set of datasets |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
40 -T Create only an extra tiny set of datasets |
| 75 | 41 -u Do not automatically mount newly created datasets |
| 42 | |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
43 mount [-u] [-n] DATASET MOUNTPOINT |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
44 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
45 Mount the ZFS dataset DATASET and all its children to mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
46 MOUNTPOINT |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
47 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
48 -n Do not really mount but show what would be mounted where |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
49 -u Alias of -n |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
50 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
51 umount DATASET |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
52 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
53 Unmount the mounted DATASET and all its children |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
54 |
| 75 | 55 privs MOUNTPOINT |
| 56 | |
| 57 Adjust some Unix privileges to mounted jail datasets | |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
58 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
59 populate MOUNTPOINT BASETXZ |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
60 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
61 Populate the jail directory in MOUNTPOINT with the base system in BASETXZ |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
62 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
63 copy SOURCE-DATASET DEST-DATASET |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
64 |
|
105
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
65 Copy a tree of ZFS datasets with "zfs send -R" and "zfs receive". |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
66 Note that the destination dataset must not exist already. |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
67 |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
68 -r Copy the datasets with the -Lec options (aka "raw") |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
69 -u Do not automatically mount received datasets |
|
105
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
70 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
71 ENVIRONMENT: |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
72 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
73 All environment variables that affect "zfs" are effective also. |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
74 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
75 DESCRIPTION: |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
76 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
77 All commands with the exception of "populate" require ZFS as |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
78 filesystem. |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
79 ' |
| 75 | 80 |
| 81 | |
| 73 | 82 # Reset to standard umask |
| 83 umask 0022 | |
| 84 | |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
85 |
|
161
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
86 _get_dataset_for_mountpoint() { |
|
196
a4fd3bcbbf1c
Use "mount -p" instead of "zfs mount" when determining devices for the real mountpoints
Franz Glasner <fzglas.hg@dom66.de>
parents:
195
diff
changeset
|
87 : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint. |
|
161
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
88 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
89 ' |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
90 local _mountpoint |
|
196
a4fd3bcbbf1c
Use "mount -p" instead of "zfs mount" when determining devices for the real mountpoints
Franz Glasner <fzglas.hg@dom66.de>
parents:
195
diff
changeset
|
91 local _ds _mount _rest |
|
161
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
92 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
93 _mountpoint="$1" |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
94 |
|
197
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
95 mount -t zfs -p \ |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
96 | { |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
97 while IFS=' '$'\t' read -r _ds _mount _rest ; do |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
98 if [ "$_mount" = "$_mountpoint" ]; then |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
99 echo "${_ds}" |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
100 return 0 |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
101 fi |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
102 done |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
103 return 1 |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
104 } |
|
161
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
105 } |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
106 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
107 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
108 _get_dataset_for_varempty() { |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
109 : 'Allow special handling for <mountpoint>/var/empty which may be |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
110 mounted read-only. |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
111 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
112 ' |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
113 local _mountpoint |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
114 local _ve_mount |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
115 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
116 _mountpoint="$1" |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
117 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
118 if [ "$_mountpoint" = '/' ]; then |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
119 _ve_mount='/var/empty' |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
120 else |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
121 _ve_mount="${_mountpoint}/var/empty" |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
122 fi |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
123 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
124 _get_dataset_for_mountpoint "${_ve_mount}" |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
125 } |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
126 |
|
57b9b899bf77
Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents:
157
diff
changeset
|
127 |
| 73 | 128 # |
| 129 # "datasets" -- create the ZFS dataset tree | |
| 130 # | |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
131 # command_datasets [ -u ] parent-dataset child-dataset |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
132 # |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
133 # -u do not automatically mount newly created datasets |
| 73 | 134 # |
| 135 command_datasets() { | |
| 136 # parent ZFS dataset -- child ZFS dataset name | |
| 137 local _pds _cds | |
| 138 # and its mount point | |
|
202
6b7a084ddf1d
Replace all calls to "zfs get" to "zfs list -o".
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
139 local _pmp _get |
| 73 | 140 # full name of the dataset |
| 141 local _ds | |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
142 # dynamic ZFS options -- create cache for freebsd-update -- use a more tiny layout |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
143 local _zfsopts _fbsdupdate _tiny _zfsnoauto |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
144 |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
145 _zfsopts="" |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
146 _fbsdupdate="" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
147 _tiny="no" |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
148 _zfsnoauto="" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
149 while getopts "ustAT" _opt ; do |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
150 case ${_opt} in |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
151 A) |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
152 # |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
153 # set canmount=noauto where otherwise canmount=on would have been set |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
154 # or inherited |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
155 # |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
156 _zfsnoauto="-o canmount=noauto" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
157 ;; |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
158 t) |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
159 # use a more tiny layout |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
160 _tiny="yes" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
161 ;; |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
162 T) # extra tiny layout |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
163 _tiny="extra" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
164 ;; |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
165 u) |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
166 # do not mount newly created datasets |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
167 _zfsopts="${_zfsopts} -u" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
168 ;; |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
169 s) |
|
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
170 # create also a dataset for freebsd-update data |
|
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
171 _fbsdupdate="yes" |
|
179
6c144aca8ac5
FIX: Proper case-switch termination
Franz Glasner <hg@dom66.de>
parents:
178
diff
changeset
|
172 ;; |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
173 \?|:) |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
174 return 2; |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
175 ;; |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
176 esac |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
177 done |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
178 shift $((OPTIND-1)) |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
179 OPTIND=1 |
| 73 | 180 |
| 181 _pds="$1" | |
| 182 if [ -z "${_pds}" ]; then | |
| 183 echo "ERROR: no parent dataset given" >&2 | |
| 184 return 2 | |
| 185 fi | |
|
203
eb95c986cc59
Use -t filesystem in all "zfs list" calls
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
186 _pmp=$(zfs list -H -o mountpoint -t filesystem "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; } |
| 73 | 187 case "${_pmp}" in |
| 188 none) | |
| 189 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2 | |
| 190 return 1 | |
| 191 ;; | |
| 192 legacy) | |
| 193 echo "ERROR: dataset \`${_pds}' has a \`${_mp}' mountpoint" >&2 | |
| 194 return 1 | |
| 195 ;; | |
| 196 *) | |
| 197 # VOID | |
| 198 ;; | |
| 199 esac | |
| 200 _cds="$2" | |
| 201 if [ -z "${_cds}" ]; then | |
| 202 echo "ERROR: no child dataset given" >&2 | |
| 203 return 2 | |
| 204 fi | |
| 205 _ds="${_pds}/${_cds}" | |
| 206 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'" | |
|
203
eb95c986cc59
Use -t filesystem in all "zfs list" calls
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
207 if zfs list -H -o mountpoint -t filesystem "${_ds}" >/dev/null 2>/dev/null; then |
| 73 | 208 echo "ERROR: dataset \`${_ds}' does already exist" >&2 |
| 209 return 1 | |
| 210 fi | |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
211 |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
212 # |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
213 # NOTE: For BEs these directory will be *excluded* from the BE |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
214 # |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
215 # /tmp |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
216 # /usr/home |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
217 # /usr/ports |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
218 # /usr/src |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
219 # /var/audit |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
220 # /var/crash |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
221 # /var/log |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
222 # /var/mail |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
223 # /var/tmp |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
224 # |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
225 zfs create ${_zfsopts} ${_zfsnoauto} -o atime=off "${_ds}" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
226 zfs create ${_zfsopts} ${_zfsnoauto} -o sync=disabled -o setuid=off "${_ds}/tmp" |
|
182
dbd62c32b3fd
FIX: Do expansion then comparing
Franz Glasner <hg@dom66.de>
parents:
181
diff
changeset
|
227 if [ "${_tiny}" != "extra" ]; then |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
228 if [ "${_tiny}" = "yes" ]; then |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
229 zfs create ${_zfsopts} -o canmount=off "${_ds}/usr" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
230 else |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
231 zfs create ${_zfsopts} ${_zfsnoauto} "${_ds}/usr" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
232 fi |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
233 zfs create ${_zfsopts} ${_zfsnoauto} -o setuid=off "${_ds}/usr/home" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
234 zfs create ${_zfsopts} ${_zfsnoauto} "${_ds}/usr/local" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
235 fi |
|
182
dbd62c32b3fd
FIX: Do expansion then comparing
Franz Glasner <hg@dom66.de>
parents:
181
diff
changeset
|
236 if [ \( "${_tiny}" = "yes" \) -o \( "${_tiny}" = "extra" \) ]; then |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
237 zfs create ${_zfsopts} -o canmount=off "${_ds}/var" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
238 else |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
239 zfs create ${_zfsopts} ${_zfsnoauto} "${_ds}/var" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
240 fi |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
241 if [ "${_tiny}" != "extra" ]; then |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
242 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off "${_ds}/var/audit" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
243 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off "${_ds}/var/cache" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
244 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off -o primarycache=metadata -o compression=off "${_ds}/var/cache/pkg" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
245 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off -o compression=off "${_ds}/var/crash" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
246 fi |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
247 if [ "$_fbsdupdate" = "yes" ]; then |
|
182
dbd62c32b3fd
FIX: Do expansion then comparing
Franz Glasner <hg@dom66.de>
parents:
181
diff
changeset
|
248 if [ \( "${_tiny}" = "yes" \) -o \( "${_tiny}" = "extra" \) ]; then |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
249 zfs create ${_zfsopts} -o canmount=off -o exec=off -o setuid=off "${_ds}/var/db" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
250 else |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
251 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off "${_ds}/var/db" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
252 fi |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
253 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off -o primarycache=metadata -o compression=off "${_ds}/var/db/freebsd-update" |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
254 fi |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
255 zfs create ${_zfsopts} ${_zfsnoauto} -o readonly=on -o exec=off -o setuid=off "${_ds}/var/empty" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
256 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off -o primarycache=metadata "${_ds}/var/log" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
257 zfs create ${_zfsopts} ${_zfsnoauto} -o exec=off -o setuid=off -o atime=on "${_ds}/var/mail" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
258 zfs create ${_zfsopts} ${_zfsnoauto} -o sync=disabled -o exec=off -o setuid=off -o compression=off -o primarycache=all "${_ds}/var/run" |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
259 zfs create ${_zfsopts} ${_zfsnoauto} -o sync=disabled -o setuid=off "${_ds}/var/tmp" |
| 73 | 260 } |
| 261 | |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
262 |
| 73 | 263 # |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
264 # "populate" -- populate the datasets with content from a FreeBSD base.txz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
265 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
266 # command_populate mountpoint basetxz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
267 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
268 command_populate() { |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
269 # MOUNTPOINT -- base.txz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
270 local _mp _basetxz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
271 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
272 _mp="$1" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
273 _basetxz="$2" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
274 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
275 if [ -z "${_mp}" ]; then |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
276 echo "ERROR: no mountpoint given" >&2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
277 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
278 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
279 if [ -z "${_basetxz}" ]; then |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
280 echo "ERROR: no base.txz given" >&2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
281 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
282 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
283 if [ ! -d "${_mp}" ]; then |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
284 echo "ERROR: mountpoint \`${_mp}' does not exist" >&2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
285 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
286 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
287 if [ ! -r "${_basetxz}" ]; then |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
288 echo "ERROR: file \`${_basetxz}' is not readable" >&2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
289 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
290 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
291 |
|
173
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
292 # |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
293 # Handle /var/empty separately later: could be already there and |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
294 # mounted read-only. |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
295 # |
|
164
b62b8bc6184f
Because of mtree errors in freebsd-update: let the directory tree in /boot stay as expanded but delete all regular files
Franz Glasner <hg@dom66.de>
parents:
163
diff
changeset
|
296 tar -C "${_mp}" --exclude=./var/empty -xJp -f "${_basetxz}" || { echo "ERROR: tar encountered errors" >&2; return 1; } |
|
173
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
297 if [ -d "${_mp}/var/empty" ]; then |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
298 # |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
299 # If /var/empty exists already try to extract with changing the |
|
183
ea491007d7fb
FIX: Because of set -eu: ignore errors from tar explicitely
Franz Glasner <hg@dom66.de>
parents:
182
diff
changeset
|
300 # flags (e.g. `schg'). But be ignore errors here. |
|
173
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
301 # |
|
184
2e7d0c967c36
Print a message when tar errors regaring ./var/empty are ignored
Franz Glasner <hg@dom66.de>
parents:
183
diff
changeset
|
302 tar -C "${_mp}" -xJp -f "${_basetxz}" ./var/empty || { echo "tar warnings for handling ./var/empty ignored because ./var/empty exists already" >&2; } |
|
173
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
303 else |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
304 # Just extract /var/empty normally |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
305 tar -C "${_mp}" -xJp -f "${_basetxz}" ./var/empty || { echo "ERROR: tar encountered errors" >&2; return 1; } |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
306 fi |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
307 |
|
164
b62b8bc6184f
Because of mtree errors in freebsd-update: let the directory tree in /boot stay as expanded but delete all regular files
Franz Glasner <hg@dom66.de>
parents:
163
diff
changeset
|
308 find "${_mp}/boot" -type f -delete |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
309 } |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
310 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
311 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
312 # |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
313 # "copy" -- ZFS copy of datasets |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
314 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
315 # command_copy source-dataset destination-dataset |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
316 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
317 command_copy() { |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
318 # source dataset -- destination dataset |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
319 local _source _dest |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
320 # dynamic ZFS options -- ZFS copy options |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
321 local _zfsopts _zfscopyopts |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
322 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
323 _zfsopts="" |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
324 _zfscopyopts="" |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
325 while getopts "ru" _opt ; do |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
326 case ${_opt} in |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
327 r) |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
328 # Use raw datasets |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
329 _zfscopyopts="-Lec" |
|
179
6c144aca8ac5
FIX: Proper case-switch termination
Franz Glasner <hg@dom66.de>
parents:
178
diff
changeset
|
330 ;; |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
331 u) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
332 # do not mount newly created datasets |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
333 _zfsopts="${_zfsopts} -u" |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
334 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
335 \?|:) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
336 return 2; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
337 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
338 esac |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
339 done |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
340 shift $((OPTIND-1)) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
341 OPTIND=1 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
342 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
343 _source="$1" |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
344 if [ -z "${_source}" ]; then |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
345 echo "ERROR: no source dataset given" >&2 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
346 return 2 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
347 fi |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
348 _dest="$2" |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
349 if [ -z "${_dest}" ]; then |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
350 echo "ERROR: no source dataset given" >&2 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
351 return 2 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
352 fi |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
353 zfs send -R ${_zfscopyopts} -n -v "${_source}" || { echo "ERROR: ZFS operation failed in no-op mode" >&2; return 1; } |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
354 zfs send -R ${_zfscopyopts} "${_source}" | zfs receive ${_zfsopts} "${_dest}" || { echo "ERROR: ZFS operation failed" >&2; return 1; } |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
355 } |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
356 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
357 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
358 # |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
359 # "mount" -- recursively mount a dataset including subordinate datasets |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
360 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
361 # command_mount dataset mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
362 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
363 command_mount() { |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
364 local _dsname _mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
365 local _name _mp _canmount _mounted |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
366 local _rootds_mountpoint _relative_mp _real_mp |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
367 local _dry_run |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
368 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
369 _dry_run="" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
370 while getopts "nu" _opt ; do |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
371 case ${_opt} in |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
372 n|u) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
373 _dry_run="yes" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
374 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
375 \?|:) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
376 return 2; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
377 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
378 esac |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
379 done |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
380 shift $((OPTIND-1)) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
381 OPTIND=1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
382 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
383 _dsname="${1-}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
384 _mountpoint="${2-}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
385 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
386 if [ -z "${_dsname}" ]; then |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
387 echo "ERROR: no dataset given" >&2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
388 return 2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
389 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
390 if [ -z "${_mountpoint}" ]; then |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
391 echo "ERROR: no mountpoint given" >&2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
392 return 2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
393 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
394 # Remove a trailing slash |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
395 _mountpoint="${_mountpoint%/}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
396 if [ -z "${_mountpoint}" ]; then |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
397 echo "ERROR: would mount over the root filesystem" >&2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
398 return 1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
399 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
400 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
401 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
402 { echo "ERROR: root dataset does not exist" >&2; return 1; } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
403 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
404 zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \ |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
405 | { |
|
195
4a0cb73945a8
Use "read -r" for when mounting/unmounting
Franz Glasner <fzglas.hg@dom66.de>
parents:
194
diff
changeset
|
406 while IFS=$'\t' read -r _name _mp _canmount _mounted ; do |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
407 # Skip filesystems that are already mounted |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
408 [ "${_mounted}" = "yes" ] && continue |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
409 # Skip filesystems that must not be mounted |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
410 [ "${_canmount}" = "off" ] && continue |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
411 case "${_mp}" in |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
412 "none"|"legacy") |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
413 # Do nothing for filesystem with unset or legacy mountpoints |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
414 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
415 "${_rootds_mountpoint}"|"${_rootds_mountpoint}/"*) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
416 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
417 # Handle only mountpoints that have a mountpoint below |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
418 # the parent datasets mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
419 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
420 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
421 # Determine the mountpoint relative to the parent mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
422 _relative_mp="${_mp#${_rootds_mountpoint}}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
423 # Remove a trailing slash |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
424 _relative_mp="${_relative_mp%/}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
425 _real_mp="${_mountpoint}${_relative_mp}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
426 if [ "${_dry_run}" = "yes" ]; then |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
427 echo "Would mount ${_name} on ${_real_mp}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
428 else |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
429 mkdir -p "${_real_mp}" 1> /dev/null 2> /dev/null || \ |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
430 { echo "ERROR: cannot create mountpoint ${_real_mp}" >&2; return 1; } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
431 echo "Mounting ${_name} on ${_real_mp}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
432 mount -t zfs "${_name}" "${_real_mp}" || return 1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
433 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
434 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
435 *) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
436 # XXX FIXME Option to do a zfs mount $_name ??? |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
437 echo "Skipping ${_name} because its configured mountpoint is not relative to given root dataset" 2>&1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
438 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
439 esac |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
440 done |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
441 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
442 return 0 |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
443 } |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
444 } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
445 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
446 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
447 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
448 # "umount" -- Recursively unmount ZFS datasets |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
449 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
450 # command_umount dataset |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
451 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
452 command_umount() { |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
453 local _dsname |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
454 local _name _mp _rest |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
455 local _rootds_mountpoint |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
456 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
457 _dsname="${1-}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
458 [ -z "${_dsname}" ] && \ |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
459 { echo "ERROR: no dataset given" >&2; return 2; } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
460 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
461 # Just determine whether the given dataset name exists |
|
200
8f739dd15d7f
FIX: Use "||" instead of "|" when handling an error case
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
462 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || { echo "ERROR: dataset not found" >&2; return 1; } |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
463 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
464 mount -t zfs -p \ |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
465 | grep -E "^${_dsname}(/|\s)" \ |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
466 | sort -n -r \ |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
467 | { |
|
195
4a0cb73945a8
Use "read -r" for when mounting/unmounting
Franz Glasner <fzglas.hg@dom66.de>
parents:
194
diff
changeset
|
468 while IFS=' '$'\t' read -r _name _mp _rest ; do |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
469 echo "Umounting ${_name} on ${_mp}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
470 umount "${_mp}" || return 1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
471 done |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
472 return 0 |
|
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
473 } |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
474 } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
475 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
476 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
477 # |
| 73 | 478 # "privs" -- adjust privileges |
| 479 # | |
| 480 # To be used when all ZFS datasets are mounted. | |
| 481 # | |
| 482 command_privs() { | |
| 483 # mountpoint | |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
484 local _mp _d _veds _get _vestatus |
| 73 | 485 |
| 486 _mp="$1" | |
| 487 if [ -z "${_mp}" ]; then | |
| 488 echo "ERROR: no mountpoint given" >&2 | |
| 489 return 2 | |
| 490 fi | |
| 491 if [ ! -d "${_mp}" ]; then | |
| 492 echo "ERROR: directory \`${_mp}' does not exist" >&2 | |
| 493 return 1 | |
| 494 fi | |
| 495 for _d in tmp var/tmp ; do | |
| 496 chmod 01777 "${_mp}/${_d}" | |
| 497 done | |
| 498 chown root:mail "${_mp}/var/mail" | |
| 499 chmod 0775 "${_mp}/var/mail" | |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
500 |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
501 # |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
502 # Handle <mountpoint>/var/empty specially: |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
503 # make it writeable temporarily if it is mounted read-only: |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
504 # |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
505 _vestatus="" |
|
196
a4fd3bcbbf1c
Use "mount -p" instead of "zfs mount" when determining devices for the real mountpoints
Franz Glasner <fzglas.hg@dom66.de>
parents:
195
diff
changeset
|
506 _veds="$(_get_dataset_for_varempty "${_mp}")" |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
507 if [ $? -eq 0 ]; then |
|
203
eb95c986cc59
Use -t filesystem in all "zfs list" calls
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
508 _vestatus=$(zfs list -H -o readonly -t filesystem ${_veds} 2>/dev/null) || { echo "ERROR: cannot determine readonly status of ${_mp}/var/empty" >&2; return 1; } |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
509 if [ "${_vestatus}" = "on" ]; then |
|
199
a8b6584d24ec
FIX: Do not suppress stderr messages from some "zfs set" calls.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
510 zfs set readonly=off ${_veds} 1> /dev/null || { echo "ERROR: cannot reset readonly-status of ${_mp}/var/empty" >&2; return 1; } |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
511 fi |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
512 fi |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
513 # Set the access rights and the file flags as given in mtree |
|
198
dd8a9bbdf8c0
Better error handling when changing privileges and flags of var/empty
Franz Glasner <fzglas.hg@dom66.de>
parents:
197
diff
changeset
|
514 chmod 0555 "${_mp}/var/empty" || { echo "WARNING: Cannot chmod on var/empty" >&2; } |
|
dd8a9bbdf8c0
Better error handling when changing privileges and flags of var/empty
Franz Glasner <fzglas.hg@dom66.de>
parents:
197
diff
changeset
|
515 chflags schg "${_mp}/var/empty" || { echo "WARNING: Cannot chflags on var/empty" >&2; } |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
516 # Reset the read-only status of the mountpoint as it was before |
|
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
517 if [ "${_vestatus}" = "on" ]; then |
|
199
a8b6584d24ec
FIX: Do not suppress stderr messages from some "zfs set" calls.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
518 zfs set readonly=on ${_veds} 1> /dev/null || { echo "ERROR: cannot reactivate readonly-status of ${_mp}/var/empty" >&2; return 1; } |
|
162
9bd38c55a75c
When executing the "privs" command try to make <mountpoint>/var/empty writeable temporarily to set proper permissions and file flags
Franz Glasner <hg@dom66.de>
parents:
161
diff
changeset
|
519 fi |
| 73 | 520 } |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
521 |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
522 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
523 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
524 # Global option handling |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
525 # |
|
81
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
526 while getopts "Vh" _opt ; do |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
527 case ${_opt} in |
|
81
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
528 V) |
|
144
6be3742d21f7
- FIX: Really print the version in check-ports
Franz Glasner <hg@dom66.de>
parents:
128
diff
changeset
|
529 printf 'fjail v%s (rv:%s)\n' "${VERSION}" '@@HGREVISION@@' |
|
81
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
530 exit 0 |
|
124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
Franz Glasner <fzglas.hg@dom66.de>
parents:
80
diff
changeset
|
531 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
532 h) |
| 75 | 533 echo "${USAGE}" |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
534 exit 0 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
535 ;; |
|
80
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
536 \?) |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
537 exit 2; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
538 ;; |
|
80
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
539 *) |
|
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
540 echo "ERROR: option handling failed" >&2 |
|
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
541 exit 2 |
|
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
542 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
543 esac |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
544 done |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
545 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
546 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
547 # Reset the Shell's option handling system to prepare for handling |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
548 # command-local options. |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
549 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
550 shift $((OPTIND-1)) |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
551 OPTIND=1 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
552 |
|
92
a8e76893140f
Extra error message if no command is given
Franz Glasner <fzglas.hg@dom66.de>
parents:
86
diff
changeset
|
553 test $# -gt 0 || { echo "ERROR: no command given" >&2; exit 2; } |
|
a8e76893140f
Extra error message if no command is given
Franz Glasner <fzglas.hg@dom66.de>
parents:
86
diff
changeset
|
554 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
555 command="$1" |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
556 shift |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
557 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
558 case "${command}" in |
| 73 | 559 datasets) |
| 560 command_datasets "$@" | |
| 561 ;; | |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
562 mount) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
563 command_mount "$@" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
564 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
565 umount|unmount) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
566 command_umount "$@" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
567 ;; |
| 73 | 568 privs) |
| 569 command_privs "$@" | |
| 570 ;; | |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
571 populate) |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
572 command_populate "$@" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
573 ;; |
|
77
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
574 copy) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
575 command_copy "$@" |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
576 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
577 *) |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
578 echo "ERROR: unknown command \`${command}'" >&2 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
579 exit 2 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
580 ;; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
581 esac |
