aboutsummaryrefslogtreecommitdiff
path: root/alpine-chroot-deactivate
blob: ce6e6ab9716f37b252c630b86f33d68b21fe25e5 (plain) (blame)
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
#!/bin/sh

err() {
	echo "$@" >&2
	exit 1
}

if [ "$(id -u)" -ne 0 ]; then
	err 'Please run as root'
fi

if [ -z "$1" ]
then
	err 'Specify path as the first argument'
fi

ensure() {  
	{ set +x; } 2>/dev/null
        [ $# -lt 1 ] && return 0
	$@ || err failed executing: "$@"
	set -x
}

set -xu

umask 022

ensure export chroot_dir="$(ensure realpath -- "$1")"

umount "${chroot_dir}/dev"
umount "${chroot_dir}/proc"
umount "${chroot_dir}/sys"