blob: 6aa76b21adcc1028ff0f310997e80e38e6433f4e (
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
34
35
|
#!/bin/sh
set -e
[ $# -ge 2 ] || {
echo "Usage: uchroot ROOT USER[:GROUP] [CMD] [ARG].." >&2
exit 1
}
if [ "$(id -u)" != "0" ]; then
exec uroot "$0" "$@"
fi
###############################################################
ROOT="$1"
USERSPEC="$2"
shift 2
[ -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"
cp -f /etc/hosts "$ROOT/etc/hosts"
if [ $# -lt 1 ]; then
set "/bin/sh"
fi
exec chroot --userspec="$USERSPEC" "$ROOT" "$@"
|