diff options
-rwxr-xr-x | librechroot | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/librechroot b/librechroot index 63bf9b4..99adcc0 100755 --- a/librechroot +++ b/librechroot @@ -1,4 +1,7 @@ #!/bin/bash +# LibreChRoot +# Enters a chroot + # Copyright 2010 Nicolás Reynolds # ---------- GNU General Public License 3 ---------- @@ -18,37 +21,38 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see <http://www.gnu.org/licenses/>. -[[ -z "${1}" ]] && { - echo "This scripts enters into the build chroot." - echo "Usage: $0 <chroot name>" - echo "Example: \`$0 root\` enters the 'root' chroot" +[[ "$UID" != "0" ]] && { + echo "This script must be run as root." exit 1 } -[[ $UID -ne 0 ]] && { - echo "This script must be run as root" - exit 2 -} - source /etc/libretools.conf -custom_config=$XDG_CONFIG_HOME/libretools/libretools.conf -[[ -e $custom_config ]] && source $custom_config +custom_config=${XDG_CONFIG_HOME}/libretools/libretools.conf +[[ -e ${custom_config} ]] && source ${custom_config} -[[ ! -d $CHROOTDIR/$1/ ]] && { - echo "There's no $CHROOTDIR/$1" - exit 3 +# Enter the chroot copy by default +root=${1:-$CHCOPY} +CACHEDIR=${CACHEDIR:-/var/cache/pacman/pkg} + +[[ ! -d ${CHROOTDIR}/${root} ]] && { + echo "${CHROOTDIR}/$root is not a dir." + exit 1 } -mount -t proc proc $CHROOTDIR/$1/proc/ -mount -t sysfs sys $CHROOTDIR/$1/sys/ -mount -o bind /dev $CHROOTDIR/$1/dev/ +mount -t proc proc ${CHROOTDIR}/${root}/proc/ +mount -t sysfs sys ${CHROOTDIR}/${root}/sys/ +mount -o bind /dev ${CHROOTDIR}/${root}/dev/ + +# Share pacman cache +mount -o bind ${CACHEDIR} ${CHROOTDIR}/${root}/var/cache/pacman/pkg -cp -L /etc/resolv.conf $CHROOTDIR/$1/etc/resolv.conf >/dev/null 2>&1 +cp -L /etc/resolv.conf ${CHROOTDIR}/${root}/etc/resolv.conf -chroot $CHROOTDIR/$1 /bin/bash +chroot ${CHROOTDIR}/${root} /bin/bash -umount $CHROOTDIR/$1/proc/ -umount $CHROOTDIR/$1/sys/ -umount $CHROOTDIR/$1/dev/ +umount ${CHROOTDIR}/${root}/proc/ +umount ${CHROOTDIR}/${root}/sys/ +umount ${CHROOTDIR}/${root}/dev/ +umount ${CHROOTDIR}/${root}/var/cache/pacman/pkg exit 0 |