mirror of
https://github.com/outbackdingo/scratchpkg.git
synced 2026-02-06 09:26:35 +00:00
79 lines
1.7 KiB
Bash
Executable File
79 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# scratchpkg
|
|
#
|
|
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
RED='\e[0;31m' #Red
|
|
GREEN='\e[0;32m' #Green
|
|
CRESET='\e[0m' #Reset color
|
|
|
|
msg() {
|
|
echo -e "${GREEN}==>${CRESET} $1"
|
|
}
|
|
|
|
msgerr() {
|
|
echo -e "${RED}==> ERROR:${CRESET} $1"
|
|
}
|
|
|
|
if [ "$UID" != "0" ]; then
|
|
msgerr "Chroot need root access!"
|
|
exit 1
|
|
fi
|
|
|
|
LFS=$1
|
|
|
|
if [ -z $1 ]; then
|
|
msgerr "Please set directory for chroot!"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d $LFS ]; then
|
|
msgerr "Directory '$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
|
|
|
|
chroot "$LFS" /usr/bin/env -i \
|
|
HOME=/root \
|
|
TERM="$TERM" \
|
|
PS1='\u:\w\$ ' \
|
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login
|
|
|
|
popd
|
|
msg "Chroot exited"
|
|
|
|
msg "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 $?
|