Files
scratchpkg/extra/chroot-scratch
2017-12-08 21:13:21 +08:00

52 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
source "/usr/share/scratchpkg/color"
source "/usr/share/scratchpkg/message"
if [ "$UID" != "0" ]; then
msgerr "Chroot need root access!"
exit 1
fi
LFS=$1
if [ -z $1 ]; then
msgerr "Please set mount point for chroot!"
exit 1
fi
if [ ! -d $LFS ]; then
msgerr "Dir '$LFS' not exist"
exit 1
fi
pushd $LFS
mount -v --bind /dev $LFS/dev
mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi
if [ -d $LFS/tools ]; then
chroot "$LFS" /tools/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /tools/bin/bash --login +h
else
chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login
fi
popd
echo chroot exited
echo "Unmounting virtual filesystem"
umount -v $LFS/dev/pts
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys
exit $?