-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullchroot
More file actions
executable file
·70 lines (52 loc) · 1.55 KB
/
fullchroot
File metadata and controls
executable file
·70 lines (52 loc) · 1.55 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# Script to facilitate the use of chroot to Gentoo systems by
# mouting and umnounting the virtual filesystems automatically
# inside the chroot
CHROOT="$1"
if [ -z "$CHROOT" ]; then
echo "Usage: fullchroot <mountpoint>"
exit
fi
shift
source /etc/os-release
function is_gentoo() {
[[ $ID == "gentoo" ]] && [[ $( source ${CHROOT}/etc/os-release; echo $ID ) == "gentoo" ]]
}
function is_another_chroot_is_running() {
# Yes, this has a race-condition, but who cares in this case...
for pid in $(pidof bash); do
path=$(ls -ld "/proc/${pid}/root" | awk '{print $NF}')
[ "$path" = "$CHROOT" ] && return 0
done
return 1
}
function mount_exists() {
mount | grep "${CHROOT}${1}" >/dev/null
}
if ! mount_exists /proc; then
mount -t proc /proc "${CHROOT}/proc"
fi
if ! mount_exists /sys; then
mount --rbind /sys "${CHROOT}/sys"
mount --make-rslave "${CHROOT}/sys"
fi
if ! mount_exists /dev; then
mount --rbind /dev "${CHROOT}/dev"
mount --make-rslave "${CHROOT}/dev"
fi
if is_gentoo && ! mount_exists /usr/portage; then
mount -o bind /usr/portage "${CHROOT}/usr/portage"
fi
if is_gentoo && ! mount_exists /usr/distfiles; then
mount -o bind /usr/distfiles "${CHROOT}/usr/distfiles"
fi
cp -f /etc/resolv.conf "${CHROOT}/etc/resolv.conf"
### Actual chroot call
export PS1="(chroot) \w $ "
chroot "${CHROOT}" /bin/bash "$@"
### Umount stuff if allowed
if [ -z "${KEEP_MOUNTS}" ] && ! is_another_chroot_is_running ; then
umount -l "${CHROOT}"/dev{/shm,/pts,}
umount -l "${CHROOT}"{/sys,/proc}
is_gentoo && umount -f "${CHROOT}/usr/"{portage,distfiles}
fi