blob: 77f3f10036da98eb62fbfa68296498c7e1bf76b3 (
plain)
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
|
#!/bin/sh
set -e
[ $# -ge 1 ] || {
echo "Usage: uchroot ROOT [CMD] [ARG].." >&2
exit 1
}
if [ "$(id -u)" != "0" ]; then
exec uroot "$0" "$@"
fi
###############################################################
ROOT="$1"
shift
[ -d "$ROOT" ] || {
echo "There is no such directory: $ROOT" >&2
exit 1
}
[ -d "$ROOT/proc" -a -d "$ROOT/dev" -a -d "$ROOT/sys" ] || {
echo "Root seems to not contain valid rootfs: $ROOT" >&2
exit 1
}
mount -t proc none "$ROOT/proc"
mount --rbind /dev "$ROOT/dev"
mount --rbind /sys "$ROOT/sys"
cp -f /etc/resolv.conf "$ROOT/etc/resolv.conf"
if [ $# -lt 1 ]; then
set "/bin/sh"
fi
exec chroot "$ROOT" "$@"
|