mirror of
https://github.com/outbackdingo/scratchpkg.git
synced 2026-02-06 01:16:34 +00:00
update vchroot
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
#!/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 $?
|
||||
73
extra/vchroot
Executable file
73
extra/vchroot
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
printhelp() {
|
||||
cat << EOF
|
||||
|
||||
Usage:
|
||||
$(basename $0) <newroot> <command>
|
||||
|
||||
(omit command to chroot only)
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
msgerr() {
|
||||
echo -e "ERROR: $@"
|
||||
}
|
||||
|
||||
if [ "$UID" != "0" ]; then
|
||||
msgerr "$(basename $0) need root access!"
|
||||
printhelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LFS=$1
|
||||
|
||||
if [ -z $1 ]; then
|
||||
msgerr "Please set directory for chroot!"
|
||||
printhelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $LFS ]; then
|
||||
msgerr "Directory '$LFS' not exist"
|
||||
printhelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
|
||||
CMD=$@
|
||||
if [ -z $2 ]; then
|
||||
CMD="/bin/bash --login"
|
||||
fi
|
||||
|
||||
pushd $LFS &>/dev/null
|
||||
|
||||
mount --bind /dev $LFS/dev
|
||||
mount -t devpts devpts $LFS/dev/pts -o gid=5,mode=620
|
||||
mount -t proc proc $LFS/proc
|
||||
mount -t sysfs sysfs $LFS/sys
|
||||
mount -t tmpfs tmpfs $LFS/run
|
||||
|
||||
if [ -h $LFS/dev/shm ]; then
|
||||
mkdir -p $LFS/$(readlink $LFS/dev/shm)
|
||||
fi
|
||||
|
||||
cp -L /etc/resolv.conf $LFS/etc
|
||||
|
||||
chroot "$LFS" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="$TERM" \
|
||||
PS1='\u:\w\$ ' \
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin $CMD
|
||||
|
||||
popd &>/dev/null
|
||||
|
||||
umount $LFS/dev/pts
|
||||
umount $LFS/dev
|
||||
umount $LFS/run
|
||||
umount $LFS/proc
|
||||
umount $LFS/sys
|
||||
|
||||
exit $?
|
||||
Reference in New Issue
Block a user