Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
annotate sbin/fjail @ 224:6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
But do not overwrite an existing resolv.conf.
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Wed, 31 Aug 2022 13:01:35 +0200 |
| parents | dce9ba905c32 |
| children | ffd24013d346 |
| 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 | |
|
205
fcfa674c8444
FIX: in the help message: improve documentation of OPTIONS
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
31 datasets [OPTIONS] PARENT CHILD |
| 75 | 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 |
|
211
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
38 -o Do not create var/empty as read-only dataset but with normal settings |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
39 -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
|
40 -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
|
41 -T Create only an extra tiny set of datasets |
| 75 | 42 -u Do not automatically mount newly created datasets |
| 43 | |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
44 mount [-O] [-u] [-n] DATASET [MOUNTPOINT] |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
45 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
46 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
|
47 MOUNTPOINT |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
48 |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
49 -O Also mount datasets at mountpoints outside of their "natural" |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
50 and inherited mountpoints |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
51 -N Mount at their "natural" configured ZFS mountpoints (MOUNTPOINT is not required) |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
52 -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
|
53 -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
|
54 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
55 umount DATASET |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
56 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
57 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
|
58 |
| 75 | 59 privs MOUNTPOINT |
| 60 | |
| 61 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
|
62 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
63 populate MOUNTPOINT BASETXZ |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
64 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
65 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
|
66 |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
67 configure MOUNPOINT |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
68 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
69 Configure some basic parts of the system at MOUNTPOINT: |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
70 disable root password, syslog and other basic configuration settings |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
71 |
|
205
fcfa674c8444
FIX: in the help message: improve documentation of OPTIONS
Franz Glasner <fzglas.hg@dom66.de>
parents:
204
diff
changeset
|
72 copy [OPTIONS] SOURCE-DATASET DEST-DATASET |
|
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
|
73 |
|
105
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
74 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
|
75 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
|
76 |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
77 -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
|
78 -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
|
79 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
80 ENVIRONMENT: |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
81 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
82 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
|
83 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
84 DESCRIPTION: |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
85 |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
86 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
|
87 filesystem. |
|
52523a19797e
Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents:
104
diff
changeset
|
88 ' |
| 75 | 89 |
| 90 | |
| 73 | 91 # Reset to standard umask |
| 92 umask 0022 | |
| 93 | |
|
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
|
94 |
|
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
|
95 _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
|
96 : '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
|
97 |
|
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
|
98 ' |
|
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
|
99 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
|
100 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
|
101 |
|
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
|
102 _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
|
103 |
|
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
|
104 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
|
105 | { |
|
3181a6b5758e
FIX: Using a pipeline within a function correctly with regard to return values:
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 } |
|
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
|
114 } |
|
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 |
|
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 _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
|
118 : '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
|
119 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
|
120 |
|
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 ' |
|
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 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
|
123 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
|
124 |
|
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 _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
|
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 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
|
128 _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
|
129 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
|
130 _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
|
131 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
|
132 |
|
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
|
133 _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
|
134 } |
|
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
|
135 |
|
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
|
136 |
| 73 | 137 # |
| 138 # "datasets" -- create the ZFS dataset tree | |
| 139 # | |
|
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
|
140 # 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
|
141 # |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
142 # -u do not automatically mount newly created datasets |
| 73 | 143 # |
| 144 command_datasets() { | |
| 145 # parent ZFS dataset -- child ZFS dataset name | |
| 146 local _pds _cds | |
| 147 # 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
|
148 local _pmp _get |
| 73 | 149 # full name of the dataset |
| 150 local _ds | |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
151 # dynamic ZFS options -- create cache for freebsd-update -- use a more tiny layout |
|
211
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
152 local _zfsopts _fbsdupdate _tiny _zfsnoauto _varempty_ro |
|
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
|
153 |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
154 _zfsopts="" |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
155 _fbsdupdate="" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
156 _tiny="no" |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
157 _zfsnoauto="" |
|
211
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
158 _varempty_ro="-o readonly=on" |
|
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
159 while getopts "oustAT" _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
|
160 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
|
161 A) |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
162 # |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
163 # 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
|
164 # or inherited |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
165 # |
|
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
166 _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
|
167 ;; |
|
211
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
168 o) |
|
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
169 # Clear out the default setting of creating var/empty as read-only dataset |
|
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
170 _varempty_ro="" |
|
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
171 ;; |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
172 t) |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
173 # 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
|
174 _tiny="yes" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
175 ;; |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
176 T) # extra tiny layout |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
177 _tiny="extra" |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
178 ;; |
|
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
|
179 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
|
180 # 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
|
181 _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
|
182 ;; |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
183 s) |
|
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
184 # 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
|
185 _fbsdupdate="yes" |
|
179
6c144aca8ac5
FIX: Proper case-switch termination
Franz Glasner <hg@dom66.de>
parents:
178
diff
changeset
|
186 ;; |
|
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
|
187 \?|:) |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
188 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
|
189 ;; |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 OPTIND=1 |
| 73 | 194 |
| 195 _pds="$1" | |
| 196 if [ -z "${_pds}" ]; then | |
| 197 echo "ERROR: no parent dataset given" >&2 | |
| 198 return 2 | |
| 199 fi | |
|
203
eb95c986cc59
Use -t filesystem in all "zfs list" calls
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
200 _pmp=$(zfs list -H -o mountpoint -t filesystem "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; } |
| 73 | 201 case "${_pmp}" in |
| 202 none) | |
| 203 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2 | |
| 204 return 1 | |
| 205 ;; | |
| 206 legacy) | |
| 207 echo "ERROR: dataset \`${_pds}' has a \`${_mp}' mountpoint" >&2 | |
| 208 return 1 | |
| 209 ;; | |
| 210 *) | |
| 211 # VOID | |
| 212 ;; | |
| 213 esac | |
| 214 _cds="$2" | |
| 215 if [ -z "${_cds}" ]; then | |
| 216 echo "ERROR: no child dataset given" >&2 | |
| 217 return 2 | |
| 218 fi | |
| 219 _ds="${_pds}/${_cds}" | |
| 220 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
|
221 if zfs list -H -o mountpoint -t filesystem "${_ds}" >/dev/null 2>/dev/null; then |
| 73 | 222 echo "ERROR: dataset \`${_ds}' does already exist" >&2 |
| 223 return 1 | |
| 224 fi | |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
225 |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
226 # |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
227 # 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
|
228 # |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
229 # /tmp |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
230 # /usr/home |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
231 # /usr/ports |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
232 # /usr/src |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
233 # /var/audit |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
234 # /var/crash |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
235 # /var/log |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
236 # /var/mail |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
237 # /var/tmp |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
238 # |
|
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} -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
|
240 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
|
241 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
|
242 if [ "${_tiny}" = "yes" ]; then |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
243 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
|
244 else |
|
204
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} "${_ds}/usr" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
246 fi |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
247 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
|
248 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
|
249 fi |
|
182
dbd62c32b3fd
FIX: Do expansion then comparing
Franz Glasner <hg@dom66.de>
parents:
181
diff
changeset
|
250 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
|
251 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
|
252 else |
|
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} "${_ds}/var" |
|
181
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
254 fi |
|
d30a68e66d60
More dataset creation options: -t (tiny) and -T (extra tiny)
Franz Glasner <hg@dom66.de>
parents:
180
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 fi |
|
177
9ffbe53dbc35
Flag for creating a separatate dataset for freebsd-update data.
Franz Glasner <hg@dom66.de>
parents:
176
diff
changeset
|
261 if [ "$_fbsdupdate" = "yes" ]; then |
|
182
dbd62c32b3fd
FIX: Do expansion then comparing
Franz Glasner <hg@dom66.de>
parents:
181
diff
changeset
|
262 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
|
263 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
|
264 else |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
265 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
|
266 fi |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
267 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
|
268 fi |
|
211
ee9b32ab0e9a
Implement the "-o" option for "datasets" to create var/empty with the default "readonly" setting instead of "readonly=on"
Franz Glasner <fzglas.hg@dom66.de>
parents:
210
diff
changeset
|
269 zfs create ${_zfsopts} ${_zfsnoauto} ${_varempty_ro} -o exec=off -o setuid=off "${_ds}/var/empty" |
|
204
ef397b84b047
Implement a "-A" flat for dataset creation: set canmount=noauto
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 zfs create ${_zfsopts} ${_zfsnoauto} -o sync=disabled -o setuid=off "${_ds}/var/tmp" |
| 73 | 274 } |
| 275 | |
|
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
|
276 |
| 73 | 277 # |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
278 # "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
|
279 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
280 # 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
|
281 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
282 command_populate() { |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
283 # MOUNTPOINT -- base.txz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
284 local _mp _basetxz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
285 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
286 _mp="$1" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
287 _basetxz="$2" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
288 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
289 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
|
290 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
|
291 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
292 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
293 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
|
294 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
|
295 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
296 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
297 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
|
298 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
|
299 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
300 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
301 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
|
302 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
|
303 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
304 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
305 |
|
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
|
306 # |
|
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 # 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
|
308 # 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
|
309 # |
|
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
|
310 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
|
311 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
|
312 # |
|
6782ac823f86
Handle /var/empty more sanely when populating datasets from a base.txz image
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
313 # 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
|
314 # 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
|
315 # |
|
184
2e7d0c967c36
Print a message when tar errors regaring ./var/empty are ignored
Franz Glasner <hg@dom66.de>
parents:
183
diff
changeset
|
316 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
|
317 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
|
318 # 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
|
319 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
|
320 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
|
321 |
|
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
|
322 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
|
323 } |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
324 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
325 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
326 # |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
327 # "configure" -- configure the mountpoint |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
328 # |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
329 # command_configure mountpoint |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
330 # |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
331 command_configure() { |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
332 # mountpoint |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
333 local _mp |
|
223
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
334 local _new_hostuuid _new_hostid |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
335 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
336 _mp="$1" |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
337 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
338 if [ -z "${_mp}" ]; then |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
339 echo "ERROR: no mountpoint given" >&2 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
340 return 2 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
341 fi |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
342 if [ ! -d "${_mp}" ]; then |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
343 echo "ERROR: mountpoint \`${_mp}' does not exist" >&2 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
344 return 1 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
345 fi |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
346 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
347 # Deactive the by default empty root password |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
348 pw -R "${_mp}" usermod -w no -n root |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
349 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
350 sysrc -R "${_mp}" sendmail_enable=NONE |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
351 sysrc -R "${_mp}" clear_tmp_enable=YES |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
352 sysrc -R "${_mp}" clear_tmp_X=NO |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
353 sysrc -R "${_mp}" syslogd_flags=-ss |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
354 sysrc -R "${_mp}" bsdstats_enable=NO # no automatic BSD stats when booting |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
355 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
356 # Timezone to CET |
|
222
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
357 if [ ! -f "${_mp}/etc/localtime" ]; then |
|
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
358 echo "Setting timezone to Europe/Berlin" |
|
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
359 ln -s ../usr/share/zoneinfo/Europe/Berlin "${_mp}/etc/localtime" |
|
223
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
360 echo "Europe/Berlin" > "${_mp}/var/db/zoneinfo" |
|
222
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
361 else |
|
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
362 echo "WARNING: \"${_mp}/etc/localtime\" exists already -- not changed" |
|
16238e9032a9
Skip configuring a timezone when there already exists such a file /etc/localtime
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
221
diff
changeset
|
363 fi |
|
221
f62f8ec6a19b
Mark a todo for setting a "hostid"
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
220
diff
changeset
|
364 |
|
224
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
365 # resolv.conf |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
366 if [ ! -f "${_mp}/etc/resolv.conf" ]; then |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
367 echo "Copying the host's resolv.conf into the jail" |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
368 cp -p /etc/resolv.conf "${_mp}/etc/resolv.conf" |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
369 else |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
370 echo "WARNING: \"${_mp}/etc/resolv.conf\" exists already -- not changed" |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
371 fi |
|
6713d97b4180
Copy the host's resolv.conf into a jail when configuring it.
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
223
diff
changeset
|
372 |
|
223
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
373 # |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
374 # hostid and hostuuid should be set (at least for consistency ressons) |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
375 # in vnet jails (see /etc/rc.d/hostid and /etc/rc.d/hostid_save). |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
376 # They can be set in the jail.conf. |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
377 # Print one here that can be pasted into the jail.conf if needed. |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
378 # |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
379 # hostid and hostuuid for non-vnet jails are inherited from the parent/host. |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
380 # |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
381 # See also /etc/rc.d/hostid and /etc/rc.d/hostid_save. |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
382 # |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
383 _new_hostuuid="$(uuidgen)" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
384 _new_hostid="$(echo -n ${_new_hostuuid} | /sbin/md5)" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
385 _new_hostid="0x${_new_hostid%%????????????????????????}" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
386 |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
387 echo "Proposed hostuuid/hostid:" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
388 echo " host.hostuuid = \"${_new_hostuuid}\";" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
389 echo " host.hostid = $((_new_hostid));" |
|
dce9ba905c32
Propose settings for host.hostuuid and host.hostid when configuring jails
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
222
diff
changeset
|
390 #echo " host.hostid = ${_new_hostid};" |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
391 } |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
392 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
393 |
|
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
394 # |
|
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
|
395 # "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
|
396 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
397 # 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
|
398 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
399 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
|
400 # 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
|
401 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
|
402 # 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
|
403 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
|
404 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
405 _zfsopts="" |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
406 _zfscopyopts="" |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
407 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
|
408 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
|
409 r) |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
410 # Use raw datasets |
|
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
411 _zfscopyopts="-Lec" |
|
179
6c144aca8ac5
FIX: Proper case-switch termination
Franz Glasner <hg@dom66.de>
parents:
178
diff
changeset
|
412 ;; |
|
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
|
413 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
|
414 # 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
|
415 _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
|
416 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
417 \?|:) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
418 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
|
419 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 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
|
424 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
425 _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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 _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
|
431 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
|
432 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
|
433 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
|
434 fi |
|
178
00fbf2b4b44f
Allow to copy ZFS datasets in "raw" mode (with "-Lec" set)
Franz Glasner <hg@dom66.de>
parents:
177
diff
changeset
|
435 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
|
436 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
|
437 } |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
438 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
439 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
440 # |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
441 # "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
|
442 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
443 # 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
|
444 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
445 command_mount() { |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
446 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
|
447 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
|
448 local _rootds_mountpoint _relative_mp _real_mp |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
449 local _dry_run _mount_outside _mount_natural |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
450 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
451 _dry_run="" |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
452 _mount_outside="" |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
453 _mount_natural="" |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
454 while getopts "ONnu" _opt ; do |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
455 case ${_opt} in |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
456 O) |
|
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
457 _mount_outside="yes" |
|
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
458 ;; |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
459 N) |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
460 _mount_natural="yes" |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
461 ;; |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
462 n|u) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
463 _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
|
464 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
465 \?|:) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
466 return 2; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
467 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
468 esac |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
469 done |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
470 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
|
471 OPTIND=1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
472 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
473 _dsname="${1-}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
474 _mountpoint="${2-}" |
|
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 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
|
477 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
|
478 return 2 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
479 fi |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
480 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
481 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
482 { echo "ERROR: root dataset does not exist" >&2; return 1; } |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
483 |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
484 if [ -z "${_mountpoint}" ]; then |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
485 if [ "${_mount_natural}" = "yes" ]; then |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
486 _mountpoint="${_rootds_mountpoint}" |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
487 else |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
488 echo "ERROR: no mountpoint given" >&2 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
489 return 2 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
490 fi |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
491 else |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
492 if [ "${_mount_natural}" = "yes" ]; then |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
493 echo "ERROR: Cannot have a custom mountpoint when \"-O\" is given" >&2 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
494 return 2 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
495 fi |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
496 fi |
|
207
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
497 |
|
a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
Franz Glasner <fzglas.hg@dom66.de>
parents:
206
diff
changeset
|
498 # Eventually remove a trailing slash |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
499 _mountpoint="${_mountpoint%/}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
500 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
|
501 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
|
502 return 1 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
503 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
504 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
505 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
|
506 | { |
|
195
4a0cb73945a8
Use "read -r" for when mounting/unmounting
Franz Glasner <fzglas.hg@dom66.de>
parents:
194
diff
changeset
|
507 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
|
508 # 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
|
509 [ "${_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
|
510 # 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
|
511 [ "${_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
|
512 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
|
513 "none"|"legacy") |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
514 # 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
|
515 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
516 "${_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
|
517 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
518 # 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
|
519 # 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
|
520 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
521 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
522 # 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
|
523 _relative_mp="${_mp#${_rootds_mountpoint}}" |
| 209 | 524 # Eventually remove a trailing slash |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
525 _relative_mp="${_relative_mp%/}" |
| 209 | 526 # The real effective full mountpoint |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
527 _real_mp="${_mountpoint}${_relative_mp}" |
|
210
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
528 |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
529 # |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
530 # Consistency and sanity check: computed real mountpoint must |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
531 # be equal to the configured mountpoint when no custom mountpoint |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
532 # is given. |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
533 # |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
534 if [ "${_mount_natural}" = "yes" ]; then |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
535 if [ "${_real_mp}" != "${_mp}" ]; then |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
536 echo "ERROR: mountpoint mismatch" >&2 |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
537 return 1 |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
538 fi |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
539 fi |
|
4d7e00b500a1
Implement a sanity and consistency check when doing "natural" mounts
Franz Glasner <fzglas.hg@dom66.de>
parents:
209
diff
changeset
|
540 |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
541 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
|
542 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
|
543 else |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
544 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
|
545 { 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
|
546 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
|
547 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
|
548 fi |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
549 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
550 *) |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
551 if [ "${_mount_outside}" = "yes" ]; then |
|
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
552 if [ "${_dry_run}" = "yes" ]; then |
| 208 | 553 echo "Would mount ${_name} on configured ZFS dataset mountpoint ${_mp}" |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
554 else |
| 208 | 555 echo "Mounting ${_name} on configured ZFS dataset mountpoint ${_mp}" |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
556 zfs mount "${_name}" || return 1 |
|
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
557 fi |
|
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
558 else |
| 208 | 559 echo "Skipping ${_name} because its configured ZFS mountpoint is not relative to given root dataset" 2>&1 |
|
206
92e5db34eb2b
Implent a "-O" flag for mounts that allows to mount also datasets with configured mountpoints outside their "natural" mountpoints within the dataset hierarchy
Franz Glasner <fzglas.hg@dom66.de>
parents:
205
diff
changeset
|
560 fi |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
561 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
562 esac |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
563 done |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
564 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
565 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
|
566 } |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
567 } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
568 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
569 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
570 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
571 # "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
|
572 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
573 # 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
|
574 # |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
575 command_umount() { |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
576 local _dsname |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
577 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
|
578 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
|
579 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
580 _dsname="${1-}" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
581 [ -z "${_dsname}" ] && \ |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
582 { 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
|
583 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
584 # 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
|
585 _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
|
586 |
|
201
687210f46b8f
FIX: In mount and unmount commands handle pipeline return values correctly now
Franz Glasner <fzglas.hg@dom66.de>
parents:
200
diff
changeset
|
587 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
|
588 | 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
|
589 | 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
|
590 | { |
|
195
4a0cb73945a8
Use "read -r" for when mounting/unmounting
Franz Glasner <fzglas.hg@dom66.de>
parents:
194
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 } |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
597 } |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
598 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
599 |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
600 # |
| 73 | 601 # "privs" -- adjust privileges |
| 602 # | |
| 603 # To be used when all ZFS datasets are mounted. | |
| 604 # | |
| 605 command_privs() { | |
| 606 # 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
|
607 local _mp _d _veds _get _vestatus |
| 73 | 608 |
| 609 _mp="$1" | |
| 610 if [ -z "${_mp}" ]; then | |
| 611 echo "ERROR: no mountpoint given" >&2 | |
| 612 return 2 | |
| 613 fi | |
| 614 if [ ! -d "${_mp}" ]; then | |
| 615 echo "ERROR: directory \`${_mp}' does not exist" >&2 | |
| 616 return 1 | |
| 617 fi | |
| 618 for _d in tmp var/tmp ; do | |
| 619 chmod 01777 "${_mp}/${_d}" | |
| 620 done | |
| 621 chown root:mail "${_mp}/var/mail" | |
| 622 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
|
623 |
|
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
|
624 # |
|
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
|
625 # 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
|
626 # 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
|
627 # |
|
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
|
628 _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
|
629 _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
|
630 if [ $? -eq 0 ]; then |
|
203
eb95c986cc59
Use -t filesystem in all "zfs list" calls
Franz Glasner <fzglas.hg@dom66.de>
parents:
202
diff
changeset
|
631 _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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 # 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
|
637 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
|
638 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
|
639 # 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
|
640 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
|
641 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
|
642 fi |
| 73 | 643 } |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
644 |
|
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
|
645 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
646 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
647 # Global option handling |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
648 # |
|
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
|
649 while getopts "Vh" _opt ; do |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
650 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
|
651 V) |
|
144
6be3742d21f7
- FIX: Really print the version in check-ports
Franz Glasner <hg@dom66.de>
parents:
128
diff
changeset
|
652 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
|
653 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
|
654 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
655 h) |
| 75 | 656 echo "${USAGE}" |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
657 exit 0 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
658 ;; |
|
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
|
659 \?) |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
660 exit 2; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
661 ;; |
|
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
|
662 *) |
|
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
663 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
|
664 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
|
665 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
666 esac |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
667 done |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
668 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
669 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
670 # 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
|
671 # command-local options. |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
672 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
673 shift $((OPTIND-1)) |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
674 OPTIND=1 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
675 |
|
92
a8e76893140f
Extra error message if no command is given
Franz Glasner <fzglas.hg@dom66.de>
parents:
86
diff
changeset
|
676 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
|
677 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
678 command="$1" |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
679 shift |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
680 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
681 case "${command}" in |
| 73 | 682 datasets) |
| 683 command_datasets "$@" | |
| 684 ;; | |
|
194
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
685 mount) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
686 command_mount "$@" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
687 ;; |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
688 umount|unmount) |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
689 command_umount "$@" |
|
379d3178f3ce
mount and umount support for ZFS datasets: recursively mount and unmount
Franz Glasner <fzglas.hg@dom66.de>
parents:
193
diff
changeset
|
690 ;; |
| 73 | 691 privs) |
| 692 command_privs "$@" | |
| 693 ;; | |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
694 populate) |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
695 command_populate "$@" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
696 ;; |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
697 configure) |
|
220
9addf133d208
FIX: Typo when calling the internal implementation of "configure"
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
219
diff
changeset
|
698 command_configure "$@" |
|
219
39b736a91d0d
Begin a "configure" command for jails
Franz Glasner <fzglas.hg@dom66.de>
parents:
211
diff
changeset
|
699 ;; |
|
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
|
700 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
|
701 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
|
702 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
703 *) |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
704 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
|
705 exit 2 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
706 ;; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
707 esac |
