diff options
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-x | src/chroot-tools/buildenv | 28 | ||||
-rwxr-xr-x | src/chroot-tools/librechroot | 243 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg | 253 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg.gpl2 | 102 | ||||
-rwxr-xr-x | src/chroot-tools/libremkchroot | 69 |
5 files changed, 449 insertions, 246 deletions
diff --git a/src/chroot-tools/buildenv b/src/chroot-tools/buildenv deleted file mode 100755 index 84a1fc2..0000000 --- a/src/chroot-tools/buildenv +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -trap "umount_all" 0 ERR TERM KILL - -user=${SUDO_USER:-${1}} - -umount_all() { - for mp in home/pkgdest home/srcdest home/${user}; do - msg "Umounting /$mp" - umount $CHROOTDIR/$CHROOT/$mp || error "Couldn't umount" - done -} - -source /etc/libretools.conf - -for mp in home/pkgdest home/srcdest home/${user} var/lib/toru; do - msg "Binding /$mp" - mount -o bind /$mp $CHROOTDIR/$CHROOT/$mp || exit 1 -done - -for etc in etc/makepkg.conf etc/abs.conf etc/mtab; do - msg "Copying config /$etc" - cp --remove-destination /$etc $CHROOTDIR/$CHROOT/$etc || exit 1 -done - -$(dirname $0)/librechroot $CHROOT - -exit $? diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 158828b..e39b105 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -1,113 +1,172 @@ -#!/bin/bash -# LibreChRoot -# Enters a chroot +#!/bin/bash -euE +# librechroot # Copyright 2010 Nicolás Reynolds # Copyright 2011 Joshua Haase - -# ---------- GNU General Public License 3 ---------- - +# Copyright 2012 Luke Shumaker +# # 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/>. -function usage { - - echo "" - echo "Usage: $0 [options] [chrootname]" - echo "Use it as root." - echo "" - echo "Default chroot name: $CHROOT" - echo "Default chrootdir: $CHROOTDIR" - echo "" - echo "OPTIONS:" - echo "" - echo " -c : clean the chroot using pacman" - echo " only 'base', 'base-devel' and 'sudo' on chroot" - echo " -d <chrootdir> : use <chrootdir> instead of default" - echo " -r : clean /repo on the chroot" - echo " -h : this message" - echo " -u : update the chroot" - echo "" - +. /etc/libretools.conf + +## +# This function is almost verbatim from makechrootpkg +## +sync() { + if [[ $CHROOTCOPY = root ]]; then + error "Cannot sync the root copy with itself" + exit 1 + fi + + lock_open_read 8 "$rootdir" "Locking clean chroot" + + stat_busy 'Creating clean working copy' + 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 + else + use_rsync=true + fi + + if $use_rsync; then + mkdir -p "$copydir" + rsync -a --delete -q -W -x "$CHROOTDIR/$CHROOT/root/" "$copydir" + fi + stat_done + + lock_close 8 } -function clean_chroot { # Clean packages with pacman - cp -a "$(dirname $0)/chcleanup" "${CHROOTDIR}/${CHROOTNAME}/clean" - - libremessages="$(grep "libremessages" /etc/libretools.conf | cut -d" " -f2)" - - cat /etc/libretools.conf ${libremessages} | sed "/libremessages/d" > "${CHROOTDIR}/${CHROOTNAME}/etc/libretools.conf" - - - mkarchroot -r "sh -c 'cd /build; /clean'" "${CHROOTDIR}/${CHROOTNAME}" +usage() { + 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 ' on the username' + 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' } -function clean_repo { - msg "Cleaning repo for chroot: ${CHROOTDIR}/${CHROOTNAME}" - if [ -d "${CHROOTDIR}/${CHROOTNAME}/repo" ]; then - find "${CHROOTDIR}/${CHROOTNAME}/repo/" -mindepth 1 -delete - else - mkdir -p "${CHROOTDIR}/${CHROOTNAME}/repo" - fi - bsdtar -czf "${CHROOTDIR}/${CHROOTNAME}/repo/repo.db.tar.gz" -T /dev/null - ln -s "repo.db.tar.gz" "${CHROOTDIR}/${CHROOTNAME}/repo/repo.db" +main() { + CHROOTCOPY=$LIBREUSER + [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + + local mode=enter + 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;; + 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;; + *) usage; exit 1;; + esac + done + shift $(($OPTIND - 1)) + case $# in + 0) :;; + 1) CHROOT="$1";; + *) usage; exit 1;; + esac + + # not local + rootdir="${CHROOTDIR}/${CHROOT}/root" + copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + + if (( EUID )); then + error "This script must be run as root." + exit 1 + fi + + # 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 '$copy'" + + if [[ ! -d $rootdir ]]; then + libremkchroot "$CHROOT" + fi + + if [[ ! -d $copydir ]] && [[ $mode != sync ]]; then + sync + fi + + case "$mode" in + 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 } -source /etc/libretools.conf - -if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then - source "$XDG_CONFIG_HOME/libretools/libretools.conf" -fi - -CLEANCHROOT='false' -UPDATE='false' -CLEANREPO='false' -CHROOTNAME="${CHROOT:-${SUDO_USER:-root}}" - -while getopts 'hrcud:' arg; do - case $arg in - h) usage; exit 0 ;; - c) CLEANCHROOT='true' ;; - u) UPDATE='true' ;; - r) CLEANREPO='true' ;; - d) CHROOTDIR="$(readlink -e $OPTARG)" ;; - esac -done - -[[ "$UID" != "0" ]] && { - error "This script must be run as root." - exit 1 -} - -shift $(($OPTIND - 1)) - -if [ $# -eq 1 ]; then - CHROOTNAME="$1" -fi - -if "$CLEANREPO"; then - clean_repo -fi - -if "$CLEANCHROOT"; then - clean_chroot -elif "$UPDATE"; then - msg "Updating chroot: ${CHROOTDIR}/${CHROOTNAME}" - mkarchroot -u "${CHROOTDIR}/${CHROOTNAME}" -else - msg "Entering chroot: ${CHROOTDIR}/${CHROOTNAME}" - mkarchroot -r "bash" "${CHROOTDIR}/${CHROOTNAME}" -fi -exit 0 +main "$@" diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index f7924f6..b6c84c1 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -1,126 +1,195 @@ -#!/bin/bash +#!/bin/bash -euE +# libremakepkg + # Copyright 2010 - 2011 Nicolás Reynolds # Copyright 2011 Joshua Ismael Haase Hernández - -# ---------- GNU General Public License 3 ---------- - +# Copyright 2012 Luke Shumaker +# # 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 + +shopt -s nullglob + +# This file (libremakepkg) is GPLv3+, but I would like to use some code +# modified from devtools' "makechrootpkg", which is GPLv2. +. "$(dirname "$0")/libremakepkg.gpl2" +# This gives us the functions: +# - chroot_init +# - chroot_extract +# - chroot_build +# - copy_pkgs + +# Boring functions ############################################################# + +## +# copy logs if they exist +## +copy_logs() { + for l in "$copydir"/build/*.log; do + chown "$LIBREUSER" "$l" + mv "$l" . + done +} -# set -x # uncomment for debug - -function copy_log { # copy logs if they exist - - find "${CHROOTDIR}/${CHROOT}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \; - +## +# End inmediately but print a useful message +## +trap_exit() { + copy_logs + error "$*" + exit 1 } +## +# Usage: makepkg_conf_get SETTING [DEFAULT] +## +makepkg_conf_get() { + local setting=$1 + if [[ -f $LIBREHOME/.makepkg.conf ]]; then + eval $(grep "^$setting=" "$LIBREHOME/.makepkg.conf") + fi + if [[ -z ${!setting} ]]; then + eval $(grep "^$setting=" "/etc/makepkg.conf") + fi + if [[ -z ${!setting} && -n ${2} ]]; then + eval "$setting='$2'" + fi +} -function trap_exit { # End inmediately but print a useful message +chroot_makepkg_conf_get() { + local setting=$1 + eval $(grep "^$setting=" "$copydir/etc/makepkg.conf") +} - copy_log - error "$@" - exit 1 +chroot_makepkg_conf_set() { + local key=$1 + local val=$2 + sed -i "/^$KEY=/d" "$copydir/etc/makepkg.conf" + echo "$key='$val'" >> "$copydir/etc/makepkg.conf" +} +# Functions that check for issues with the build ############################### + +libre_check_pkgbuild() { + msg "Checking PKGBUILD for issues" + # TODO + if ! pkgbuild-check-nonfree -f; then + if [[ $? -eq 15 ]]; then + # other errors mean fail, not nonfree + error "PKGBUILD contains non-free issues" + exit 15 + else + warning "PKGBUILD couldn't be check aganist non-free issues" + fi + fi } -# Trap signals from makepkg -set -E -trap 'trap_exit "(libremakepkg): TERM signal caught. Exiting..."' TERM HUP QUIT -trap 'trap_exit "(libremakepkg): Aborted by user! Exiting..."' INT -trap 'trap_exit "(libremakepkg): An unknown error has occurred. Exiting..."' ERR +libre_check_src() { + msg "Checking src directory for issues" + # TODO +} -source /etc/libretools.conf +libre_check_pkg() { + msg "Checking final package for issues" + # TODO +} -CLEANFIRST="false" -UPDATEFIRST="false" -CHECKNONFREE="true" -LIBRECHROOT_ARGS="" -MAKEPKG_ARGS="" -function usage { +# The main program ############################################################# - echo '' +usage() { echo 'cd to a dir containing a PKGBUILD and run:' - echo '$0 [options] [-- makechrootpkg args [-- makepkg args]]' - echo 'This script will build your package on a chroot.' + echo '$0 [options] [-- makepkg args]' + echo 'This script will build your package in a chroot.' echo '' echo 'OPTIONS:' + echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'" + echo ' -l <COPY> Use this chroot copy instead of basing it' + echo ' on the username' echo '' - echo ' -h : show this message.' - echo ' -c : clean the chroot before building.' - echo ' -u : update the chroot before building.' - echo ' -d <chrootdir> : use this dir instead of "$CHROOTDIR"' - echo ' -n <chrootname> : use this dir instead of "$CHROOT".' - echo ' -N : do not check freedom issues' # As fullpkg-check will do that before + echo " -m <MAKEPKG> Use the command MAKEPKG instead of 'makepkg'" + echo " -R Repackage" echo '' - exit 1 + echo ' -h Show this message' +} +main() { + # Parse command line ################################################### + + CHROOTCOPY=$LIBREUSER + [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + + makepkg_args=(-s --noconfirm -L) + REPACKAGE=false + MAKEPKG=makepkg + + while getopts 'n:l:m:Rh' arg ; do + case "${arg}" in + n) CHROOT=$OPTARG;; + l) CHROOTCOPY=$OPTARG;; + m) MAKEPKG=$OPTARG;; + R) REPACKAGE=true; makepkg_args+=(-R);; + h) usage; exit 0;; + *) usage; exit 1;; + esac + done + shift $(($OPTIND - 1)) + # Pass all arguments after -- right to makepkg + makepkg_args+=("$@") + + rootdir="${CHROOTDIR}/${CHROOT}/root" + copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + + # Init ################################################################# + + if (( EUID )); then + error "This script must be run as root" + exit 1 + fi + + if [[ ! -f PKGBUILD ]]; then + error "This must be run in a directory containing a PKGBUILD" + exit 1 + fi + + # Trap signals from makepkg + trap 'trap_exit "(libremakepkg): TERM signal caught. Exiting..."' TERM HUP QUIT + trap 'trap_exit "(libremakepkg): Aborted by user! Exiting..."' INT + trap 'trap_exit "(libremakepkg): An unknown error has occurred. Exiting..."' ERR + + makepkg_conf_get SRCDEST . + makepkg_conf_get PKGDEST . + + # OK, we're starting now ############################################### + + lock_open_write 9 "$copydir.lock" "Locking chroot '$copy'" + + # Set target CARCH as it might be used within the PKGBUILD to select correct sources + chroot_makepkg_conf_get CARCH + export CARCH + + chroot_init + libre_check_pkgbuild + $REPACKAGE || chroot_extract + libre_check_src + chroot_build + libre_check_pkg + copy_pkgs + copy_logs } -while getopts 'hcud:n:N' arg ; do - case "${arg}" in - h) usage ;; - c) CLEANFIRST="true" ;; - u) UPDATEFIRST="true" ;; - d) CHROOTDIR="$OPTARG" - LIBRECHROOT_ARGS='-d "$OPTARG"' ;; - n) CHROOT="$OPTARG" ;; - N) CHECKNONFREE="false" ;; - esac -done - -# Pass all arguments after -- right to makechrootpkg -MAKEPKG_ARGS="$makepkg_args ${*:$OPTIND}" - -if (( EUID )); then - error "This script must be run as root" - exit 1 -fi - -if [ ! -e PKGBUILD ]; then # Check if we are actually on a build directory. Do this early. - error "This isn't a build directory"; usage -fi - -msg "Checking PKGBUILD for non-free issues" -if "$CHECKNONFREE"; then - if ! pkgbuild-check-nonfree; then - - if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree - error "PKGBUILD contains non-free issues" - exit 15 - else - warning "PKGBUILD couldn't be check aganist non-free issues" - fi - fi -fi - -if "$CLEANFIRST"; then - librechroot -c "$LIBRECHROOT_ARGS" "$CHROOT" -fi - -if "$UPDATEFIRST"; then - librechroot -u "$LIBRECHROOT_ARGS" "$CHROOT" -fi - -unset CLEANFIRST UPDATEFIRST LIBRECHROOT_ARGS - -makechrootpkg -d -r "$CHROOTDIR" -l "$CHROOT" -- $MAKEPKG_ARGS -ev="$?" # exit value - -copy_log - -exit $ev +main "$@" diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2 new file mode 100755 index 0000000..1f2d185 --- /dev/null +++ b/src/chroot-tools/libremakepkg.gpl2 @@ -0,0 +1,102 @@ +#!/bin/bash +# Contains code derived from devtools' "makechrootpkg" + +# Copyright 2011-2012 The Arch Linux Development Team +# Copyright 2012 Luke Shumaker +# +# This program 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; version 2 of the License. +# +# This program 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. + +chroot_init() { + # no-op; make sure the chroot exists + librechroot -n -l "$CHROOTCOPY" "$CHROOT" + + if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then + install -D "$HOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg" + fi + + mkdir -p "$copydir/pkgdest" + mkdir -p "$copydir/srcdest" + chroot_makepkg_conf_set PKGDEST /pkgdest + chroot_makepkg_conf_set SRCDEST /srcdest + + cat > "$copydir/etc/sudoers.d/nobody-pacman" <<EOF +Defaults env_keep += "HOME" +nobody ALL = NOPASSWD: /usr/bin/pacman +EOF + chmod 440 "$copydir/etc/sudoers.d/nobody-pacman" +} + +chroot_extract() { + rm -rf "$copydir"/build/* + cp PKGBUILD "$copydir/build/" + ( + source PKGBUILD + + # Copy source files + for file in "${source[@]}"; do + file="${file%%::*}" + file="${file##*://*/}" + if [[ -f $file ]]; then + cp "$file" "$copydir/srcdest/" + elif [[ -f $SRCDEST/$file ]]; then + cp "$SRCDEST/$file" "$copydir/srcdest/" + fi + done + + # Find all changelog and install files, even inside functions + for i in 'changelog' 'install'; do + while read -r file; do + # evaluate any bash variables used + eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" + if [[ -f $file ]]; then + cp "$file" "$copydir/build/" + fi + done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) + done + ) + + chown -R nobody "$copydir"/{build,pkgdest,srcdest} + + local file="$copydir/chrootextract" + echo '#!/bin/bash' > "$file" + echo '. /etc/profile' >> "$file" + echo 'export HOME=/build' >> "$file" + echo 'cd /build' >> "$file" + echo "sudo -u nobody ${MAKEPKG} $makepkg_args -o" >> "$file" + chmod 755 "$file" + archroot "$copydir" -r /chrootextract +} + +chroot_build() { + local file="$copydir/chrootbuild" + echo '#!/bin/bash' > "$file" + echo '. /etc/profile' >> "$file" + echo 'export HOME=/build' >> "$file" + echo 'cd /build' >> "$file" + echo "sudo -u nobody ${MAKEPKG} $makepkg_args -e" >> "$file" + chmod 755 "$file" + archroot -N "$copydir" -r /chrootbuild +} + +copy_pkgs() { + for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do + mkdir -p "$copydir/repo" + pushd "$copydir/repo" >/dev/null + cp "$pkgfile" . + repo-add repo.db.tar.gz "${pkgfile##*/}" + popd >/dev/null + + chown "$LIBREUSER" "$pkgfile" + mv "$pkgfile" "$PKGDEST" + if [[ $PKGDEST != . ]]; then + ln -s "$PKGDEST/${pkgfile##*/}" . + fi + done +} diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index b576209..992c6e5 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -1,64 +1,65 @@ #!/bin/bash -# LibreMkChroot -# Creates a chroot +# libremkchroot # Copyright 2011, 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/>. -source /etc/libretools.conf - -if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then - source "$XDG_CONFIG_HOME/libretools/libretools.conf" -fi +. /etc/libretools.conf cmd=${0##*/} -function usage { - echo "Usage: $cmd [OPTIONS]" + +usage() { + echo "Usage: $cmd [OPTIONS] [CHROOT]" echo 'This script will create a chroot to build packages in.' echo "Use \`librechroot' to interact with the chroot after it is created." echo '' + echo "The default CHROOT is \`${CHROOT}'." + echo '' echo 'Options:' echo ' -h Show this message' echo '' - echo ' -f Force overwrite of files in the working-dir' - echo '' - echo ' -d <chrootdir> Use this dir instead of "$CHROOTDIR".' - echo " -c <pacmandir> Location of pacman cache. Default: \`/var/cache/pacman/pkg'." echo ' -C <file> Location of pacman config file.' echo ' -M <file> Location of makepkg config file.' } -mkchroot_args=(); -while getopts 'hfd:c:C:M:' arg; do - case "$arg" in - h) usage; exit 0 ;; - f) mkchroot_args+=("-$arg");; - c|C|M) mkchroot_args+=("-$arg" "$OPTARG");; - d) CHROOTDIR=$OPTARG ;; - ?) usage; exit 1 ;; +main() { + archroot_args=(); + while getopts 'hC:M:' arg; do + case "$arg" in + C|M) archroot_args+=("-$arg" "$OPTARG");; + + h) usage; exit 0;; + *) usage; exit 1;; + esac + done + shift $(($OPTIND - 1)) + case $# in + 0) :;; + 1) CHROOT="$1";; + *) usage; exit 1;; esac -done -if (( EUID )); then - error "This script must be run as root" - exit 1 -fi + if (( EUID )); then + error "This script must be run as root" + exit 1 + fi + + mkdir -p "${CHROOTDIR}/${CHROOT}" + archroot "${chroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" -i base base-devel sudo "${CHROOTEXTRAPKG[@]}" +} -mkdir -p "${CHROOTDIR}" -xargs -d'\n' mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/root" < /etc/libretools.d/cleansystem +main "$@" |