comparison bin/fjail @ 76:fea2ef3ff89a

Populate an existing directory tree with the contents of base.txz
author Franz Glasner <hg@dom66.de>
date Thu, 15 Aug 2019 17:01:02 +0200
parents 2e3ac70bdfc8
children 5aab3a28895f
comparison
equal deleted inserted replaced
75:2e3ac70bdfc8 76:fea2ef3ff89a
1 #!/bin/sh 1 #!/bin/sh
2 # -*- indent-tabs-mode: nil; -*- 2 # -*- indent-tabs-mode: nil; -*-
3 # @(#)$HGid$ 3 # @(#)$HGid$
4 4
5 set -eu 5 set -e
6 6
7 VERSION="@@VERSION@@" 7 VERSION="@@VERSION@@"
8 8
9 USAGE=" 9 USAGE="
10 USAGE: fjail [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ] 10 USAGE: fjail [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ]
24 -u Do not automatically mount newly created datasets 24 -u Do not automatically mount newly created datasets
25 25
26 privs MOUNTPOINT 26 privs MOUNTPOINT
27 27
28 Adjust some Unix privileges to mounted jail datasets 28 Adjust some Unix privileges to mounted jail datasets
29
30 populate MOUNTPOINT BASETXZ
31
32 Populate the jail directory in MOUNTPOINT with the base system in BASETXZ
29 " 33 "
30 34
31 35
32 # Reset to standard umask 36 # Reset to standard umask
33 umask 0022 37 umask 0022
115 zfs create ${_zfsopts} -o sync=disabled -o setuid=off "${_ds}/var/tmp" 119 zfs create ${_zfsopts} -o sync=disabled -o setuid=off "${_ds}/var/tmp"
116 } 120 }
117 121
118 122
119 # 123 #
124 # "populate" -- populate the datasets with content from a FreeBSD base.txz
125 #
126 # command_populate mountpoint basetxz
127 #
128 command_populate() {
129 # MOUNTPOINT -- base.txz
130 local _mp _basetxz
131
132 _mp="$1"
133 _basetxz="$2"
134
135 if [ -z "${_mp}" ]; then
136 echo "ERROR: no mountpoint given" >&2
137 return 2
138 fi
139 if [ -z "${_basetxz}" ]; then
140 echo "ERROR: no base.txz given" >&2
141 return 2
142 fi
143 if [ ! -d "${_mp}" ]; then
144 echo "ERROR: mountpoint \`${_mp}' does not exist" >&2
145 return 1
146 fi
147 if [ ! -r "${_basetxz}" ]; then
148 echo "ERROR: file \`${_basetxz}' is not readable" >&2
149 return 1
150 fi
151
152 tar -C "${_mp}" --exclude=./var/empty -xJp -f "${_basetxz}" || { echo "ERROR: tar encountered errors" >&2; return 1; }
153 }
154
155
156 #
120 # "privs" -- adjust privileges 157 # "privs" -- adjust privileges
121 # 158 #
122 # To be used when all ZFS datasets are mounted. 159 # To be used when all ZFS datasets are mounted.
123 # 160 #
124 command_privs() { 161 command_privs() {
172 command_datasets "$@" 209 command_datasets "$@"
173 ;; 210 ;;
174 privs) 211 privs)
175 command_privs "$@" 212 command_privs "$@"
176 ;; 213 ;;
214 populate)
215 command_populate "$@"
216 ;;
177 *) 217 *)
178 echo "ERROR" >&2 218 echo "ERROR: unknown command \`${command}'" >&2
179 exit 2 219 exit 2
180 ;; 220 ;;
181 esac 221 esac