summaryrefslogtreecommitdiff
path: root/librechroot
diff options
context:
space:
mode:
Diffstat (limited to 'librechroot')
-rwxr-xr-xlibrechroot39
1 files changed, 26 insertions, 13 deletions
diff --git a/librechroot b/librechroot
index ec437de..b308b7d 100755
--- a/librechroot
+++ b/librechroot
@@ -23,6 +23,19 @@
source /etc/libretools.conf
+function usage {
+ echo "Usage: $0 chrootname"
+ echo "Change to a chroot in $CHROOTDIR. Use it as root."
+ echo
+ echo "Default chroot name: $CHCOPY"
+}
+
+while getopts 'h' arg; do
+ case $arg in
+ h) usage; exit 0 ;;
+ esac
+done
+
[[ "$UID" != "0" ]] && {
error "This script must be run as root."
exit 1
@@ -32,28 +45,28 @@ custom_config=${XDG_CONFIG_HOME}/libretools/libretools.conf
[[ -e ${custom_config} ]] && source ${custom_config}
# Enter the chroot copy by default
-root=${1:-$CHCOPY}
+chrootname=${1:-$CHCOPY}
CACHEDIR=${CACHEDIR:-/var/cache/pacman/pkg}
-[[ ! -d ${CHROOTDIR}/${root} ]] && {
- error "${CHROOTDIR}/$root is not a dir."
+[[ ! -d ${CHROOTDIR}/${chrootname} ]] && {
+ error "${CHROOTDIR}/${chrootname} is not a dir."
exit 1
}
-mount -t proc proc ${CHROOTDIR}/${root}/proc/
-mount -t sysfs sys ${CHROOTDIR}/${root}/sys/
-mount -o bind /dev ${CHROOTDIR}/${root}/dev/
+mount -t proc proc ${CHROOTDIR}/${chrootname}/proc/
+mount -t sysfs sys ${CHROOTDIR}/${chrootname}/sys/
+mount -o bind /dev ${CHROOTDIR}/${chrootname}/dev/
# Share pacman cache
-mount -o bind ${CACHEDIR} ${CHROOTDIR}/${root}/var/cache/pacman/pkg
+mount -o bind ${CACHEDIR} ${CHROOTDIR}/${chrootname}/var/cache/pacman/pkg
-cp -L /etc/resolv.conf ${CHROOTDIR}/${root}/etc/resolv.conf
+cp -L /etc/resolv.conf ${CHROOTDIR}/${chrootname}/etc/resolv.conf
-chroot ${CHROOTDIR}/${root} /bin/bash
+chroot ${CHROOTDIR}/${chrootname} /bin/bash
-umount ${CHROOTDIR}/${root}/proc/
-umount ${CHROOTDIR}/${root}/sys/
-umount ${CHROOTDIR}/${root}/dev/
-umount ${CHROOTDIR}/${root}/var/cache/pacman/pkg
+umount ${CHROOTDIR}/${chrootname}/proc/
+umount ${CHROOTDIR}/${chrootname}/sys/
+umount ${CHROOTDIR}/${chrootname}/dev/
+umount ${CHROOTDIR}/${chrootname}/var/cache/pacman/pkg
exit 0