comparison sbin/ftjail @ 235:85aea8ca1ab8

Some work on datasets-tmpl
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 08 Sep 2022 09:43:31 +0200
parents 8682cfa74f6a
children 661e35a9d6e5
comparison
equal deleted inserted replaced
234:8682cfa74f6a 235:85aea8ca1ab8
26 26
27 -h Print this help message to stdout and exit 27 -h Print this help message to stdout and exit
28 28
29 COMMANDS: 29 COMMANDS:
30 30
31 datasets [OPTIONS] PARENT-BASE PARENT-SKELETON NAME 31 datasets-tmpl [OPTIONS] PARENT-BASE PARENT-SKELETON NAME
32 32
33 Create ZFS datasets for the ro base and the rw skeleton to be used 33 Create the ZFS template datasets, i.e. the ro base and the rw
34 within for jails 34 skeleton to be used within thin jails jails
35 35
36 PARENT-BASE and PARENT-SKELETON must exist already and NAME must 36 PARENT-BASE and PARENT-SKELETON must exist already and NAME must
37 not exist. 37 not exist.
38 38
39 The datasets will not be mounted. 39 The datasets will not be mounted.
73 } 73 }
74 } 74 }
75 75
76 76
77 # 77 #
78 # "datasets" -- create the ZFS dataset tree 78 # "datasets-tmpl" -- create the ZFS dataset tree
79 # 79 #
80 # PARENT-BASE PARENT-SKELETON NAME 80 # PARENT-BASE PARENT-SKELETON NAME
81 # 81 #
82 command_datasets() { 82 command_datasets_tmpl() {
83 # parent ZFS dataset -- child ZFS dataset name 83 # parent ZFS dataset -- child ZFS dataset name
84 local _p_base _p_skel _name 84 local _p_base _p_skel _name
85 local _zfsopts 85 local _zfsopts
86 86 local _ds_base _ds_skel
87 _zfsopts="-u" 87
88 _zfsopts="-u -o canmount=noauto"
88 89
89 _p_base="$1" 90 _p_base="$1"
90 _p_skel="$2" 91 _p_skel="$2"
91 _name="$3" 92 _name="$3"
92 93
96 fi 97 fi
97 if [ -z "${_p_skel}" ]; then 98 if [ -z "${_p_skel}" ]; then
98 echo "ERROR: no parent dataset for skeleton given" >&2 99 echo "ERROR: no parent dataset for skeleton given" >&2
99 return 2 100 return 2
100 fi 101 fi
101 if [ -z "${_pname}" ]; then 102 if [ -z "${_name}" ]; then
102 echo "ERROR: no name given" >&2 103 echo "ERROR: no name given" >&2
103 return 2 104 return 2
104 fi 105 fi
105 106
106 _ds="${_pds}/${_cds}" 107 _ds_base="${_p_base}/${_name}"
107 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'" 108 _ds_skel="${_p_skel}/${_name}"
108 if zfs list -H -o mountpoint -t filesystem "${_ds}" >/dev/null 2>/dev/null; then 109 echo "Resulting new root datasets:"
109 echo "ERROR: dataset \`${_ds}' does already exist" >&2 110 printf "\\t%s\\n" "${_ds_base}"
110 return 1 111 printf "\\t%s\\n" "${_ds_skel}"
111 fi 112 if ! zfs list -H -o mountpoint -t filesystem "${_p_base}" >/dev/null 2>/dev/null; then
113 echo "ERROR: parent dataset \`${_p_base}' does not exist" >&2
114 return 1
115 fi
116 if zfs list -H -o mountpoint -t filesystem "${_ds_base}" >/dev/null 2>/dev/null; then
117 echo "ERROR: dataset \`${_ds_base}' does already exist" >&2
118 return 1
119 fi
120 if ! zfs list -H -o mountpoint -t filesystem "${_p_skel}" >/dev/null 2>/dev/null; then
121 echo "ERROR: parent dataset \`${_p_skel}' does not exist" >&2
122 return 1
123 fi
124 if zfs list -H -o mountpoint -t filesystem "${_ds_skel}" >/dev/null 2>/dev/null; then
125 echo "ERROR: dataset \`${_ds_skel}' does already exist" >&2
126 return 1
127 fi
128 return 0
112 129
113 # 130 #
114 # NOTE: For BEs these directory will be *excluded* from the BE 131 # NOTE: For BEs these directory will be *excluded* from the BE
115 # 132 #
116 # /tmp 133 # /tmp
404 421
405 command="$1" 422 command="$1"
406 shift 423 shift
407 424
408 case "${command}" in 425 case "${command}" in
409 datasets) 426 datasets-tmpl)
410 command_datasets "$@" 427 command_datasets_tmpl "$@"
411 ;; 428 ;;
412 populate) 429 populate)
413 command_populate "$@" 430 command_populate "$@"
414 ;; 431 ;;
415 *) 432 *)