32
32
. /usr/local/etc/bastille/bastille.conf
33
33
34
34
usage () {
35
- error_exit " Usage: bastille clone TARGET NEW_NAME IP_ADDRESS"
36
-
35
+ error_notify " Usage: bastille clone [option(s)] TARGET NEW_NAME IP_ADDRESS"
37
36
cat << EOF
38
37
Options:
39
-
40
- -r | --restart -- Start/Restart jail(s) on completion.
41
- -f | --force -- Stop the jail if it is running.
42
- Mandatory for UFS, optional for ZFS.
38
+
39
+ -l | --live -- Clone a running jail. ZFS only.
40
+ Jail must be running.
41
+ Cannot be used with [-f|--force].
42
+ -f | --force -- Stop the jail if it is running.
43
+ Cannot be used with [-l|--live].
44
+ -s | --start -- Start jail(s) when complete.
43
45
44
46
EOF
45
47
exit 1
46
48
}
47
49
48
50
# Handle options.
51
+ LIVE=0
49
52
FORCE=0
50
- RESTART =0
53
+ START =0
51
54
while [ " $# " -gt 0 ]; do
52
55
case " ${1} " in
53
56
-h|--help|help)
54
57
usage
55
58
;;
56
- -r|--restart)
57
- RESTART=1
58
- shift
59
+ -l|--live)
60
+ if ! checkyesno bastille_zfs_enable; then
61
+ error_exit " [-l|--live] can only be used with ZFS."
62
+ else
63
+ LIVE=1
64
+ shift
65
+ fi
59
66
;;
60
67
-f|--force)
61
- FORCE=1
68
+ if [ " ${LIVE} " -eq 1 ]; then
69
+ error_exit " [-f|--force] cannot be used with [-l|--live]."
70
+ else
71
+ FORCE=1
72
+ shift
73
+ fi
74
+ ;;
75
+ -s|--start)
76
+ START=1
62
77
shift
63
78
;;
64
79
-* )
@@ -161,8 +176,8 @@ update_jailconf_vnet() {
161
176
sed -i ' ' " s|e\([0-9]\{1,\}\)b_${NEWNAME} |e${uniq_epair_bridge} b_${NEWNAME} |g" " ${JAIL_CONFIG} "
162
177
sed -i ' ' " s|epair\([0-9]\{1,\}\)|epair${uniq_epair_bridge} |g" " ${JAIL_CONFIG} "
163
178
sed -i ' ' " s|exec.prestart += \" ifconfig e0a_bastille\([0-9]\{1,\}\).*description.*|exec.prestart += \" ifconfig e0a_${uniq_epair} description \\\\\" vnet host interface for Bastille jail ${NEWNAME} \\\\\"\" ;|" " ${JAIL_CONFIG} "
164
- sed -i ' ' " s|ether.*:.*:.*:.*:.*:.*a|ether ${macaddr} a|" " ${JAIL_CONFIG} "
165
- sed -i ' ' " s|ether.*:.*:.*:.*:.*:.*b|ether ${macaddr} b|" " ${JAIL_CONFIG} "
179
+ sed -i ' ' " s|ether.*:.*:.*:.*:.*:.*a |ether ${macaddr} a |" " ${JAIL_CONFIG} "
180
+ sed -i ' ' " s|ether.*:.*:.*:.*:.*:.*b |ether ${macaddr} b |" " ${JAIL_CONFIG} "
166
181
break
167
182
fi
168
183
fi
@@ -205,8 +220,13 @@ clone_jail() {
205
220
206
221
if ! [ -d " ${bastille_jailsdir} /${NEWNAME} " ]; then
207
222
if checkyesno bastille_zfs_enable; then
208
- check_target_is_stopped " ${TARGET} " || if [ " ${FORCE} " -eq 1 ]; then
209
- bastille stop " ${TARGET} "
223
+ if [ " ${LIVE} " -eq 1 ]; then
224
+ check_target_is_running " ${TARGET} " || error_exit " [-l|--live] can only be used with a running jail."
225
+ elif [ " ${FORCE} " -eq 1 ]; then
226
+ check_target_is_stopped " ${TARGET} " || bastille stop " ${TARGET} "
227
+ else
228
+ error_notify " Jail is running."
229
+ error_exit " Use [-f|--force] to force stop the jail, or [-l|--live] (ZFS only) to clone a running jail."
210
230
fi
211
231
if [ -n " ${bastille_zfs_zpool} " ]; then
212
232
# Replicate the existing container
@@ -226,10 +246,11 @@ clone_jail() {
226
246
# Perform container file copy (archive mode)
227
247
check_target_is_stopped " ${TARGET} " || if [ " ${FORCE} " -eq 1 ]; then
228
248
bastille stop " ${TARGET} "
229
- cp -a " ${bastille_jailsdir} /${TARGET} " " ${bastille_jailsdir} /${NEWNAME} "
230
249
else
231
- exit
250
+ error_notify " Jail is running."
251
+ error_exit " Use [-f|--force] to force stop the jail."
232
252
fi
253
+ cp -a " ${bastille_jailsdir} /${TARGET} " " ${bastille_jailsdir} /${NEWNAME} "
233
254
fi
234
255
else
235
256
error_exit " ${NEWNAME} already exists."
@@ -245,6 +266,12 @@ clone_jail() {
245
266
else
246
267
info " Cloned '${TARGET} ' to '${NEWNAME} ' successfully."
247
268
fi
269
+ if [ " ${START} " -eq 1 ]; then
270
+ if [ " ${LIVE} " -eq 0 ]; then
271
+ bastille start " ${TARGET} "
272
+ fi
273
+ bastille start " ${NEWNAME} "
274
+ fi
248
275
}
249
276
250
277
# Check if IP address is valid.
0 commit comments