summaryrefslogtreecommitdiff
path: root/src/chroot-tools/librechroot
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/librechroot')
-rwxr-xr-xsrc/chroot-tools/librechroot130
1 files changed, 69 insertions, 61 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 8830c39..c3c7374 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -1,52 +1,27 @@
-#!/bin/bash
-# LibreChRoot
-# Enters a chroot
+#!/bin/bash -euE
+# librechroot
# Copyright 2010 Nicolás Reynolds
# Copyright 2011 Joshua Haase
# Copyright 2012 Luke Shumaker
-
-# ---------- GNU General Public License 3 ----------
-
+#
# This file is part of Parabola.
-
+#
# Parabola 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.
-
+#
# Parabola 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 Parabola. If not, see <http://www.gnu.org/licenses/>.
. /etc/libretools.conf
-cmd=${0##*/}
-
-clean_pacman() {
- msg "Cleaning chroot with pacman: ${copydir}"
-
- cp -a "$(dirname $0)/chcleanup" "${copydir}/clean"
- mkdir -p "$copydir/build"
- archroot "${copydir}" -r "cd /build; /clean"
-}
-
-clean_repo() {
- msg "Cleaning repo for chroot: ${copydir}"
-
- if [ -d "${copydir}/repo" ]; then
- find "${copydir}/repo/" -mindepth 1 -delete
- else
- mkdir -p "${copydir}/repo"
- fi
- bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null
- ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db"
-}
-
##
# This function is almost verbatim from makechrootpkg
##
@@ -62,8 +37,7 @@ sync() {
local use_rsync=false
if type -P btrfs >/dev/null; then
[[ -d $copydir ]] && btrfs subvolume delete "$copydir" &>/dev/null
- btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null ||
- use_rsync=true
+ btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null || use_rsync=true
else
use_rsync=true
fi
@@ -77,48 +51,49 @@ sync() {
lock_close 8
}
-update() {
- msg "Updating chroot: ${copydir}"
- archroot "${copydir}" -u
-}
-
-enter() {
- msg "Entering chroot: ${copydir}"
- archroot "${copydir}" -r "bash"
-}
-
usage() {
- echo "Usage: $cmd [OPTIONS] [CHROOT]"
+ echo "Usage: $cmd [OPTIONS] [CHROOT] "
echo 'Interacts with a chroot.'
echo ''
echo "The default CHROOT is \`${CHROOT}'."
echo ''
echo 'Options:'
echo ' Settings:'
- echo ' -l <copy> Use this as the chroot copy instead of basing it'
+ echo ' -l <COPY> Use this as the chroot copy instead of basing it'
echo ' on the username'
- echo ' Modes:'
- echo ' -h Show this message'
- echo ' -c Clean the chroot using pacman'
- echo " -C Clean the chroot by syncing it with 'root' copy"
- echo ' -r Clean /repo in the chroot'
+ echo ' -N Disable networking in the chroot'
+ echo ''
+ echo ' Modes: (the last mode given will be used)'
+ echo ' -C Clean /repo in the chroot'
+ echo ' -c Clean the packages installed in the chroot'
+ echo ' -I <FILE> Install the package FILE into the chroot'
+ echo ' -i <PKG> Install the package PKG from repos into the chroot'
+ echo ' -n No-op, just make sure that the chroot exists'
+ echo ' -r <CMD> Run CMD in the chroot'
+ echo " -s Sync the copy with the 'root' copy"
echo ' -u Update the chroot'
+ echo ' -h Print this message'
}
main() {
- # The logic for setting CHROOTCOPY is mirred from makechrootpkg
- CHROOTCOPY=$USER
- [[ -n $SUDO_USER ]] && CHROOTCOPY=$SUDO_USER
- [[ -z $CHROOTCOPY || $CHROOTCOPY = root ]] && CHROOTCOPY=copy
+ CHROOTCOPY=$LIBREUSER
+ [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy
local mode=enter
- while getopts 'hrcud:l:' arg; do
+ local archroot_args=()
+ local ARG=''
+ while getopts 'l:NCcI:i:nrsuh' arg; do
case $arg in
l) CHROOTCOPY=$OPTARG;;
+ N) archroot_args+=(-N);;
+ C) mode=clean_repo
c) mode=clean_pacman;;
- C) mode=sync;;
- r) mode=clean_repo;;
+ I) mode=install_file; ARG=$OPTARG;;
+ I) mode=install_pkg; ARG=$OPTARG;;
+ n) mode=noop;;
+ r) mode=run; ARG=$OPTARG;;
+ s) mode=sync;;
u) mode=update;;
h) usage; exit 0;;
@@ -154,10 +129,43 @@ main() {
fi
case "$mode" in
- clean_pacman) clean_pacman; exit $?;;
- clean_repo) clean_repo; exit $?;;
- update) update; exit $?;;
- enter) enter; exit $?;;
+ clean_repo)
+ msg "Cleaning local pacman repository"
+ rm -rf "${copydir}/repo"
+ mkdir "${copydir}/repo"
+ bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null
+ ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db"
+ ;;
+ clean_pacman)
+ msg "Intelligently cleaning packages"
+ cp -a "$(dirname $0)/chcleanup" "${copydir}/clean"
+ mkdir -p "$copydir/build"
+ archroot "${archroot_args[@]}" "${copydir}" -r "cd /build; /clean"
+ ;;
+ install_file)
+ msg "Installing package file: $ARG"
+ cp "$ARG" "$copydir/${ARG##*/}"
+ archroot "${archroot_args[@]}" "$copydir" -r "pacman -U /${ARG##*/} --noconfirm"
+ rm "$copydir/${ARG##*/}"
+ ;;
+ install_pkg)
+ msg "Installing package(s): $ARG"
+ archroot "${archroot_args[@]}" "$copydir" -i $ARG
+ ;;
+ noop) :;;
+ run)
+ msg "Running command"
+ archroot "${archroot_args[@]}" "${copydir}" -r "$ARG"
+ ;;
+ sync) sync;;
+ update)
+ msg "Updating chroot"
+ archroot "${archroot_args[@]}" "${copydir}" -u
+ ;;
+ enter)
+ msg "Entering chroot"
+ archroot "${archroot_args[@]}" "${copydir}" -r bash
+ ;;
esac
}