summaryrefslogtreecommitdiff
path: root/librechroot
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-21 20:18:44 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-21 20:18:44 -0300
commitf98753091219274bc92cf8a90b7786e288d8219f (patch)
tree7f72f30a2aaf304fa7b21daf06a8e001bf4efdb7 /librechroot
parent9c4f19b5e3f590002c19758cded5cb6ed691a8fd (diff)
parentde28a019385b3a4465ffeadf39e51f0411771edf (diff)
Merge branch 'master' of ssh://vparabola/srv/git/projects/libretoolsv20110321
Diffstat (limited to 'librechroot')
-rwxr-xr-xlibrechroot48
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