Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
annotate bin/fjail @ 81:124faa20ae80
Implemented a "-V" global option to print the program's name and version number to stdout
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 16 Aug 2019 09:16:27 +0200 |
| parents | f5cf08e8d246 |
| children | 56dd768b5fdd |
| 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; -*- |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
3 # @(#)$HGid$ |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
4 |
|
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
|
5 set -eu |
| 73 | 6 |
| 7 VERSION="@@VERSION@@" | |
| 8 | |
| 75 | 9 USAGE=" |
| 10 USAGE: fjail [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ] | |
| 11 | |
| 12 OPTIONS: | |
| 13 | |
|
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
|
14 -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
|
15 |
| 75 | 16 -h Print this help message to stdout and exit |
| 17 | |
| 18 COMMANDS: | |
| 19 | |
| 20 datasets [-u] PARENT CHILD | |
| 21 | |
| 22 Create ZFS datasets to be used within a jail | |
| 23 | |
| 24 PARENT must exist already and CHILD must not exist. | |
| 25 | |
| 26 -u Do not automatically mount newly created datasets | |
| 27 | |
| 28 privs MOUNTPOINT | |
| 29 | |
| 30 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
|
31 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
32 populate MOUNTPOINT BASETXZ |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
33 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
34 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
|
35 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
36 copy SOURCE-DATASET DEST-DATASET |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
37 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
38 Copy a tree of ZFS datasets with \"zfs send -R\" and \"zfs receive\". |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
39 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
|
40 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
41 -u Do not automatically mount received datasets |
| 75 | 42 " |
| 43 | |
| 44 | |
| 73 | 45 # Reset to standard umask |
| 46 umask 0022 | |
| 47 | |
|
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
|
48 |
| 73 | 49 # |
| 50 # "datasets" -- create the ZFS dataset tree | |
| 51 # | |
|
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
|
52 # 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
|
53 # |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
54 # -u do not automatically mount newly created datasets |
| 73 | 55 # |
| 56 command_datasets() { | |
| 57 # parent ZFS dataset -- child ZFS dataset name | |
| 58 local _pds _cds | |
| 59 # and its mount point | |
| 60 local _pmp _get _dummy | |
| 61 # full name of the dataset | |
| 62 local _ds | |
|
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
|
63 # dynamic ZFS options |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
64 local _zfsopts |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
65 |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
66 _zfsopts="" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
67 while getopts "u" _opt ; do |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
68 case ${_opt} in |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
69 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
|
70 # 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
|
71 _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
|
72 ;; |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
73 \?|:) |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
74 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
|
75 ;; |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 OPTIND=1 |
| 73 | 80 |
| 81 _pds="$1" | |
| 82 if [ -z "${_pds}" ]; then | |
| 83 echo "ERROR: no parent dataset given" >&2 | |
| 84 return 2 | |
| 85 fi | |
| 86 _get=$(zfs get -H mountpoint "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; } | |
| 87 IFS=$'\t' read _dummy _dummy _pmp _dummy <<EOF | |
| 88 ${_get} | |
| 89 EOF | |
| 90 case "${_pmp}" in | |
| 91 none) | |
| 92 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2 | |
| 93 return 1 | |
| 94 ;; | |
| 95 legacy) | |
| 96 echo "ERROR: dataset \`${_pds}' has a \`${_mp}' mountpoint" >&2 | |
| 97 return 1 | |
| 98 ;; | |
| 99 *) | |
| 100 # VOID | |
| 101 ;; | |
| 102 esac | |
| 103 _cds="$2" | |
| 104 if [ -z "${_cds}" ]; then | |
| 105 echo "ERROR: no child dataset given" >&2 | |
| 106 return 2 | |
| 107 fi | |
| 108 _ds="${_pds}/${_cds}" | |
| 109 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'" | |
| 110 if zfs get -H mountpoint "${_ds}" >/dev/null 2>/dev/null; then | |
| 111 echo "ERROR: dataset \`${_ds}' does already exist" >&2 | |
| 112 return 1 | |
| 113 fi | |
|
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
|
114 zfs create ${_zfsopts} -o atime=off "${_ds}" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
115 zfs create ${_zfsopts} -o sync=disabled -o setuid=off "${_ds}/tmp" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
116 zfs create ${_zfsopts} "${_ds}/usr" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
117 zfs create ${_zfsopts} "${_ds}/var" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
118 zfs create ${_zfsopts} -o exec=off -o setuid=off "${_ds}/var/audit" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
119 zfs create ${_zfsopts} -o exec=off -o setuid=off "${_ds}/var/cache" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
120 zfs create ${_zfsopts} -o exec=off -o setuid=off -o compression=off "${_ds}/var/cache/pkg" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
121 zfs create ${_zfsopts} -o exec=off -o setuid=off -o compression=off "${_ds}/var/crash" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
122 zfs create ${_zfsopts} -o exec=off -o setuid=off "${_ds}/var/db" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
123 zfs create ${_zfsopts} -o exec=on -o setuid=off "${_ds}/var/db/pkg" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
124 zfs create ${_zfsopts} -o readonly=on -o exec=off -o setuid=off "${_ds}/var/empty" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
125 zfs create ${_zfsopts} -o exec=off -o setuid=off -o primarycache=metadata "${_ds}/var/log" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
126 zfs create ${_zfsopts} -o exec=off -o setuid=off -o atime=on "${_ds}/var/mail" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
127 zfs create ${_zfsopts} -o sync=disabled -o exec=off -o setuid=off -o compression=off -o primarycache=all "${_ds}/var/run" |
|
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
128 zfs create ${_zfsopts} -o sync=disabled -o setuid=off "${_ds}/var/tmp" |
| 73 | 129 } |
| 130 | |
|
74
247d35f910ca
fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents:
73
diff
changeset
|
131 |
| 73 | 132 # |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
133 # "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
|
134 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
135 # 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
|
136 # |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
137 command_populate() { |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
138 # MOUNTPOINT -- base.txz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
139 local _mp _basetxz |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
140 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
141 _mp="$1" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
142 _basetxz="$2" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
143 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
144 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
|
145 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
|
146 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
147 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
148 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
|
149 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
|
150 return 2 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
151 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
152 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
|
153 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
|
154 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
155 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
156 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
|
157 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
|
158 return 1 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
159 fi |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
160 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
161 tar -C "${_mp}" --exclude=./var/empty -xJp -f "${_basetxz}" || { echo "ERROR: tar encountered errors" >&2; return 1; } |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
162 } |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
163 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
164 |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
165 # |
|
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
|
166 # "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
|
167 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
168 # 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
|
169 # |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
170 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
|
171 # 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
|
172 local _source _dest |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
173 # dynamic ZFS options |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
174 local _zfsopts |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
175 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
176 _zfsopts="" |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
177 while getopts "u" _opt ; do |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
178 case ${_opt} in |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
179 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
|
180 # 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
|
181 _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
|
182 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
183 \?|:) |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
184 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
|
185 ;; |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
191 _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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 _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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 zfs send -R -n -v ${_source} || { echo "ERROR: ZFS operation failed in no-op mode" >&2; return 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
|
202 zfs send -R "${_source}" | zfs receive ${_zfsopts} "${_dest}" || { echo "ERROR: ZFS operation failed" >&2; return 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
|
203 } |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
204 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
205 |
|
5aab3a28895f
Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
206 # |
| 73 | 207 # "privs" -- adjust privileges |
| 208 # | |
| 209 # To be used when all ZFS datasets are mounted. | |
| 210 # | |
| 211 command_privs() { | |
| 212 # mountpoint | |
| 213 local _mp _d | |
| 214 | |
| 215 _mp="$1" | |
| 216 if [ -z "${_mp}" ]; then | |
| 217 echo "ERROR: no mountpoint given" >&2 | |
| 218 return 2 | |
| 219 fi | |
| 220 if [ ! -d "${_mp}" ]; then | |
| 221 echo "ERROR: directory \`${_mp}' does not exist" >&2 | |
| 222 return 1 | |
| 223 fi | |
| 224 for _d in tmp var/tmp ; do | |
| 225 chmod 01777 "${_mp}/${_d}" | |
| 226 done | |
| 227 chown root:mail "${_mp}/var/mail" | |
| 228 chmod 0775 "${_mp}/var/mail" | |
| 229 } | |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
230 |
|
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
|
231 |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
232 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
233 # Global option handling |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
234 # |
|
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
|
235 while getopts "Vh" _opt ; do |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
236 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
|
237 V) |
|
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
|
238 echo "fjail v${VERSION} (rv:@@HGREVISION@@)" |
|
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
|
239 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
|
240 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
241 h) |
| 75 | 242 echo "${USAGE}" |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
243 exit 0 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
244 ;; |
|
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
|
245 \?) |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
246 exit 2; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
247 ;; |
|
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
|
248 *) |
|
f5cf08e8d246
Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents:
77
diff
changeset
|
249 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
|
250 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
|
251 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
252 esac |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
253 done |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
254 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
255 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
256 # 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
|
257 # command-local options. |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
258 # |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
259 shift $((OPTIND-1)) |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
260 OPTIND=1 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
261 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
262 command="$1" |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
263 shift |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
264 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
265 case "${command}" in |
| 73 | 266 datasets) |
| 267 command_datasets "$@" | |
| 268 ;; | |
| 269 privs) | |
| 270 command_privs "$@" | |
| 271 ;; | |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
272 populate) |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
273 command_populate "$@" |
|
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
274 ;; |
|
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
|
275 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
|
276 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
|
277 ;; |
|
72
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
278 *) |
|
76
fea2ef3ff89a
Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents:
75
diff
changeset
|
279 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
|
280 exit 2 |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
281 ;; |
|
929051be7845
Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
282 esac |
