summaryrefslogtreecommitdiff
path: root/src/chroot-tools/librechroot
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/librechroot')
-rwxr-xr-xsrc/chroot-tools/librechroot101
1 files changed, 56 insertions, 45 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 6594f15..89fb644 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -20,7 +20,10 @@
# 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
+. /usr/share/libretools/conf.sh
+load_conf_libretools_chroot
+
+. "$(which libremessages)"
# This file (librechroot) is GPLv3+, but I would like to use some code
# modified from devtools' "makechrootpkg", which is GPLv2.
@@ -28,30 +31,40 @@
# This gives us the functions:
# - sync
+cleanup=(':');
+cleanup() {
+ for cmd in "${cleanup[@]}"; do
+ $cmd
+ done
+}
+
cmd=${0##*/}
usage() {
echo "Usage: $cmd [OPTIONS] "
echo 'Interacts with a chroot.'
echo ''
- echo "The default CHROOT is \`${CHROOT}'."
+ echo 'This command will make the following configuration changes in'
+ echo 'the chroot:'
+ echo " - overwrite \`/etc/libretools.d/chroot.conf'"
+ echo " - overwrite \`/etc/pacman.d/mirrorlist'"
+ echo " - set \`CacheDir' in \`/etc/pacman.conf'"
echo ''
echo 'Options:'
echo ' Settings:'
- echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'"
- echo ' -l <COPY> Use this as the chroot copy instead of basing it'
- echo ' on the username'
- echo ' -N Disable networking in the chroot'
+ echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'"
+ echo " -l <COPY> Use this chroot copy instead \`$CHROOTCOPY'"
+ 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 ' -m Make sure the chroot exists; do nothing else'
- 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'
+ 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 ' -m Make sure the chroot exists; do nothing else'
+ echo ' -r <CMD> Run CMD in the chroot'
+ echo " -s Sync the copy with the \`root' copy"
+ echo ' -u Update the chroot'
+ echo ' -h Show this message'
}
main() {
@@ -61,7 +74,7 @@ main() {
local mode=enter
local archroot_args=(-f)
local ARG=''
- while getopts 'n:l:NCcI:i:mrsuh' arg; do
+ while getopts 'n:l:NCcI:i:mr:suh' arg; do
case $arg in
n) CHROOT=$OPTARG;;
l) CHROOTCOPY=$OPTARG;;
@@ -99,7 +112,8 @@ main() {
# Keep this lock as long as we are running
# Note that '9' is the same FD number as in (mk)archroot
- lock_open_write 9 "$copydir" "Locking chroot copy '$CHROOTCOPY'"
+ lock_open_write 9 "$copydir" \
+ "Waiting for existing lock on \`$copydir' to be released"
if [[ ! -d $rootdir ]]; then
libremkchroot "$CHROOT"
@@ -109,49 +123,46 @@ main() {
sync
fi
+ mkdir -p $copydir/etc/libretools.d
+ {
+ if [[ -n ${CHROOTEXTRAPKG[@]:-} ]]; then
+ printf 'CHROOTEXTRAPKG=('
+ printf "'%s' " "${CHROOTEXTRAPKG[@]}"
+ printf ')\n'
+ else
+ printf 'CHROOTEXTRAPKG=()\n'
+ fi
+ } > $copydir/etc/libretools.d/chroot.conf
+
########################################################################
+ trap cleanup EXIT
case "$mode" in
clean_repo)
- msg "Cleaning local pacman repository"
- rm -rf "${copydir}/repo"
- mkdir "${copydir}/repo"
+ rm -rf "${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"
+ cleanup+=("rm -f $copydir/clean $copydir/chrootexec")
cp -a "$(which chcleanup)" "${copydir}/clean"
- echo '#!/bin/bash' > "${copydir}/cleanstrap"
- echo 'mkdir /build' >> "${copydir}/cleanstrap"
- echo 'cd /build; /clean' >> "${copydir}/cleanstrap"
- chmod 755 "${copydir}/cleanstrap"
- archroot "${archroot_args[@]}" "${copydir}" -r /cleanstrap
+ echo '#!/bin/bash' > "${copydir}/chrootexec"
+ echo 'mkdir /build' >> "${copydir}/chrootexec"
+ echo 'cd /build; /clean' >> "${copydir}/chrootexec"
+ chmod 755 "${copydir}/chrootexec"
+ archroot "${archroot_args[@]}" "${copydir}" -r /chrootexec
;;
install_file)
- msg "Installing package file: $ARG"
+ cleanup+=("rm $copydir/${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
+ archroot "${archroot_args[@]}" "${copydir}" -r "pacman -U /${ARG##*/} --noconfirm"
;;
+ install_pkg) archroot "${archroot_args[@]}" "${copydir}" -i $ARG ;;
noop) :;;
- run)
- msg "Running command"
- archroot "${archroot_args[@]}" "${copydir}" -r "$ARG"
- ;;
+ run) 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
- ;;
+ update) archroot "${archroot_args[@]}" "${copydir}" -u ;;
+ enter) archroot "${archroot_args[@]}" "${copydir}" -r bash ;;
esac
}