crappy quality ezjail replacement

root / host-hook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

set -ex

path="$1"
epair="$2"
action="$3"

if [ -z "$epair" -o -z "$action" -o -z "$path" ] ; then
	printf 'Error: %s <jail-path> <epair> { pre-start | post-start | pre-stop | post-stop }\n' "$0" >&2
	exit 1
fi

alias testif='>/dev/null 2>&1 ifconfig '

case "$action" in

post-stop)
	# Umount remaining directories mounted into the jail
	mount | awk '{print $3}' | grep "$path" | while read line; do
		umount "$line"
	done

	# Deconfigure and destroy the epair interface if available
	if testif ${epair}a; then
		ifconfig bridge0 deletem ${epair}a
		ifconfig ${epair}a destroy
	fi
;;

pre-stop)
	
;;

pre-start)
	# Test if the epair interface already exists.
	# If so, assume that it was already set up and added to the bridge.
	# Otherwise, create it and add it to the bridge.
	if ! testif ${epair}a; then
		ifconfig $epair create
		ifconfig bridge0 addm ${epair}a
		ifconfig ${epair}a up
	fi
;;

post-start)

;;

*)
	printf 'Error: %s <jail-path> <epair> { pre-start | post-start | pre-stop | post-stop }\n' "$0" >&2
	exit 1
;;
esac