annotate sbin/fjail @ 161:57b9b899bf77

Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 20 Nov 2019 09:11:48 +0100
parents 3f9cae8f5862
children 9bd38c55a75c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a3b9d4fe560e Provide "module" doc-strings
Franz Glasner <fzglas.hg@dom66.de>
parents: 85
diff changeset
6 :Copyright: (c) 2019 Franz Glasner.
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
c95726f83f84 Style: :Id: -> :ID:
Franz Glasner <fzglas.hg@dom66.de>
parents: 92
diff changeset
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
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
17
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
18 VERSION="@@VERSION@@"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
19
105
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
20 USAGE='
75
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
21 USAGE: fjail [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ]
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
22
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
23 OPTIONS:
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
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
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
27 -h Print this help message to stdout and exit
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
28
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
29 COMMANDS:
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
30
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
31 datasets [-u] PARENT CHILD
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
32
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
33 Create ZFS datasets to be used within a jail
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
34
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
35 PARENT must exist already and CHILD must not exist.
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
36
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
37 -u Do not automatically mount newly created datasets
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
38
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
39 privs MOUNTPOINT
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
40
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
41 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
42
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
43 populate MOUNTPOINT BASETXZ
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
44
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
45 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
46
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
47 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
48
105
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
49 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
50 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
51
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
52 -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
53
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
54 ENVIRONMENT:
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
55
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
56 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
57
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
58 DESCRIPTION:
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
59
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
60 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
61 filesystem.
52523a19797e Docu: Enhance the docu of fjail
Franz Glasner <fzglas.hg@dom66.de>
parents: 104
diff changeset
62 '
75
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
63
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
64
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
65 # Reset to standard umask
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
66 umask 0022
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
67
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
68
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
69 _get_dataset_for_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
70 : 'Use `zfs mount` to determine the ZFS dataset for a given 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
71
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
72 '
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
73 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
74 local _ds _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
75
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
76 _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
77
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
78 while read -r _ds _mount; do
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
79 if [ "$_mount" = "$_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
80 echo $_ds
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
81 return 0
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
82 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
83 done <<EOF__GDSFM
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
84 $(zfs 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
85 EOF__GDSFM
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
86 return 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
87 }
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
88
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
89
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
90 _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
91 : '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
92 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
93
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
94 '
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 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
96 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
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 _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
99
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
100 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
101 _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
102 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
103 _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
104 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
105
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
106 _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
107 }
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
108
57b9b899bf77 Provide functions that will be the base for "/var/empty" handling (manipulate the "readonly" property when doing some special operations)
Franz Glasner <fzglas.hg@dom66.de>
parents: 157
diff changeset
109
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
110 #
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
111 # "datasets" -- create the ZFS dataset tree
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
112 #
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
113 # 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
114 #
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 # -u do not automatically mount newly created datasets
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
116 #
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
117 command_datasets() {
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
118 # parent ZFS dataset -- child ZFS dataset name
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
119 local _pds _cds
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
120 # and its mount point
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
121 local _pmp _get _dummy
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
122 # full name of the dataset
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
123 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
124 # 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
125 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
126
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 _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
128 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
129 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
130 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
131 # 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
132 _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
133 ;;
247d35f910ca fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents: 73
diff changeset
134 \?|:)
247d35f910ca fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents: 73
diff changeset
135 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
136 ;;
247d35f910ca fjail datasets now recognized a "-u" command option to not automatically mount created datasets
Franz Glasner <hg@dom66.de>
parents: 73
diff changeset
137 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
138 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
139 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
140 OPTIND=1
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
141
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
142 _pds="$1"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
143 if [ -z "${_pds}" ]; then
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
144 echo "ERROR: no parent dataset given" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
145 return 2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
146 fi
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
147 _get=$(zfs get -H mountpoint "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; }
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
148 IFS=$'\t' read _dummy _dummy _pmp _dummy <<EOF
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
149 ${_get}
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
150 EOF
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
151 case "${_pmp}" in
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
152 none)
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
153 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
154 return 1
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
155 ;;
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
156 legacy)
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
157 echo "ERROR: dataset \`${_pds}' has a \`${_mp}' mountpoint" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
158 return 1
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
159 ;;
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
160 *)
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
161 # VOID
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
162 ;;
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
163 esac
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
164 _cds="$2"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
165 if [ -z "${_cds}" ]; then
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
166 echo "ERROR: no child dataset given" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
167 return 2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
168 fi
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
169 _ds="${_pds}/${_cds}"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
170 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
171 if zfs get -H mountpoint "${_ds}" >/dev/null 2>/dev/null; then
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
172 echo "ERROR: dataset \`${_ds}' does already exist" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
173 return 1
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
174 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
175 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
176 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
177 zfs create ${_zfsopts} "${_ds}/usr"
157
3f9cae8f5862 Also create a DS/usr/local dataset perdefault in jails
Franz Glasner <fzglas.hg@dom66.de>
parents: 144
diff changeset
178 zfs create ${_zfsopts} "${_ds}/usr/local"
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 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 zfs create ${_zfsopts} -o sync=disabled -o setuid=off "${_ds}/var/tmp"
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
191 }
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
192
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
193
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
194 #
76
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
195 # "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
196 #
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
197 # 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
198 #
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
199 command_populate() {
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
200 # MOUNTPOINT -- base.txz
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
201 local _mp _basetxz
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
202
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
203 _mp="$1"
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
204 _basetxz="$2"
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
205
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
206 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
207 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
208 return 2
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
209 fi
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
210 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
211 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
212 return 2
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
213 fi
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
214 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
215 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
216 return 1
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
217 fi
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
218 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
219 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
220 return 1
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
221 fi
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
222
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
223 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
224 }
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
225
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
226
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
227 #
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
228 # "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
229 #
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
230 # 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
231 #
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
232 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
233 # 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
234 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
235 # 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
236 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
237
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
238 _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
239 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
240 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
241 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
242 # 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
243 _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
244 ;;
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
245 \?|:)
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
246 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
247 ;;
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
248 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
249 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
250 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
251 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
252
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
253 _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
254 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
255 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
256 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
257 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
258 _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
259 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
260 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
261 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
262 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
263 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
264 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
265 }
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
266
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
267
5aab3a28895f Implemented a "copy" command to employ zfs send/receive for recursively copying jail datasets
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
268 #
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
269 # "privs" -- adjust privileges
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
270 #
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
271 # To be used when all ZFS datasets are mounted.
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
272 #
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
273 command_privs() {
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
274 # mountpoint
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
275 local _mp _d
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
276
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
277 _mp="$1"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
278 if [ -z "${_mp}" ]; then
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
279 echo "ERROR: no mountpoint given" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
280 return 2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
281 fi
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
282 if [ ! -d "${_mp}" ]; then
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
283 echo "ERROR: directory \`${_mp}' does not exist" >&2
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
284 return 1
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
285 fi
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
286 for _d in tmp var/tmp ; do
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
287 chmod 01777 "${_mp}/${_d}"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
288 done
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
289 chown root:mail "${_mp}/var/mail"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
290 chmod 0775 "${_mp}/var/mail"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
291 }
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
292
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
293
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
294 #
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
295 # Global option handling
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
296 #
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
297 while getopts "Vh" _opt ; do
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
298 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
299 V)
144
6be3742d21f7 - FIX: Really print the version in check-ports
Franz Glasner <hg@dom66.de>
parents: 128
diff changeset
300 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
301 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
302 ;;
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
303 h)
75
2e3ac70bdfc8 A fairly usable usage message
Franz Glasner <hg@dom66.de>
parents: 74
diff changeset
304 echo "${USAGE}"
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
305 exit 0
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
306 ;;
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
307 \?)
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
308 exit 2;
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
309 ;;
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
310 *)
f5cf08e8d246 Handle the error case when option handling fails because of wrong case labels
Franz Glasner <fzglas.hg@dom66.de>
parents: 77
diff changeset
311 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
312 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
313 ;;
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
314 esac
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
315 done
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
316
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
317 #
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
318 # 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
319 # command-local options.
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
320 #
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
321 shift $((OPTIND-1))
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
322 OPTIND=1
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
323
92
a8e76893140f Extra error message if no command is given
Franz Glasner <fzglas.hg@dom66.de>
parents: 86
diff changeset
324 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
325
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
326 command="$1"
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
327 shift
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
328
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
329 case "${command}" in
73
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
330 datasets)
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
331 command_datasets "$@"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
332 ;;
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
333 privs)
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
334 command_privs "$@"
2e991a00035b Creation of Jail datasets done
Franz Glasner <hg@dom66.de>
parents: 72
diff changeset
335 ;;
76
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
336 populate)
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
337 command_populate "$@"
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
338 ;;
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
339 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
340 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
341 ;;
72
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
342 *)
76
fea2ef3ff89a Populate an existing directory tree with the contents of base.txz
Franz Glasner <hg@dom66.de>
parents: 75
diff changeset
343 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
344 exit 2
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
345 ;;
929051be7845 Begin a simple (ZFS-related) jail setup tool
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
346 esac