diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-05-02 15:06:04 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-05-02 15:06:04 -0400 |
commit | 962250da23024224fc9e0be782b16ae08df46671 (patch) | |
tree | 2cc17939d6fc064b65eb3ce20e43ba49565d925c /src/chroot-tools | |
parent | bf2e3833c4158c8ec94e6af621f7d50d11353957 (diff) |
Update for the new devtools-par (major)
* `src/devtools`: Redo to get devtools from another location, and patch it
* `src/chroot-tools/{chcleanup,chroot.conf}`: Only install 'base-devel' by
default
* libremkchroot: deprecate in favor of `librechroot make`
* librechroot:
- redo option parsing to be a "sub-command" (git-like) interface,
instead of having esoteric flags (pacman-like).
- add more documentation.
- allow COPY to be an absolute path
- generally clean up and use updated functions from `makechrootpkg.sh`
* libremakepkg:
- allow COPY to be an absolute path
- update to work with the new `makechrootpkg.sh`:
- `makechrootpkg.sh:chroot_exec()` -> `libremakepkg:run()`
- `makechrootpkg.sh:chroot_init()` -> `libremakepkg:chroot_init()`
- All functions from `makechrootpkg.sh` are wrapped, because they
don't work with `set -euE`.
- Other small changes
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-x | src/chroot-tools/chcleanup | 2 | ||||
-rw-r--r-- | src/chroot-tools/chroot.conf | 2 | ||||
-rwxr-xr-x | src/chroot-tools/librechroot | 208 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg | 181 | ||||
-rwxr-xr-x | src/chroot-tools/libremkchroot | 68 |
5 files changed, 288 insertions, 173 deletions
diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup index 821c572..40db3c0 100755 --- a/src/chroot-tools/chcleanup +++ b/src/chroot-tools/chcleanup @@ -33,7 +33,7 @@ cleanup_log="${TEMPDIR}"/libretools-cleanup.log # Get the full list of packages needed by dependencies, including the base system pacman -b "${TEMPDIR}" \ -Sp --print-format "%n" \ - base base-devel sudo "${CHROOTEXTRAPKG[@]}" \ + base-devel "${CHROOTEXTRAPKG[@]}" \ >"${cleanup_log}" # Diff installed packages against a clean chroot then remove leftovers diff --git a/src/chroot-tools/chroot.conf b/src/chroot-tools/chroot.conf index d84e8b4..a161a61 100644 --- a/src/chroot-tools/chroot.conf +++ b/src/chroot-tools/chroot.conf @@ -9,5 +9,5 @@ CHROOTDIR=/var/lib/archbuild CHROOT=default # Extra packages to have installed on the chroot. -# This is in addition to CHROOTPKG=(base base-devel sudo) +# This is in addition to CHROOTPKG=(base-devel) CHROOTEXTRAPKG=(distcc ccache tsocks libretools) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 7f113f5..368ecc1 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -3,7 +3,7 @@ # Copyright 2010 Nicolás Reynolds # Copyright 2011 Joshua Haase -# Copyright 2012 Luke Shumaker +# Copyright 2012-2013 Luke Shumaker # # This file is part of Parabola. # @@ -23,20 +23,41 @@ . /usr/share/libretools/conf.sh load_conf_libretools_chroot -. "$(which libremessages)" +. libremessages . /usr/share/devtools/makechrootpkg.sh -cleanup=(':'); -cleanup() { - for cmd in "${cleanup[@]}"; do - $cmd - done -} +# Because the makechrootpkg.sh library functions don't work with -euE +normshell() ( + set +euE + "$@" +) cmd=${0##*/} usage() { - echo "Usage: $cmd [OPTIONS] " - echo 'Interacts with a chroot.' + echo "Usage: $cmd [OPTIONS] COMMAND [ARGS...]" + echo 'Interacts with an archroot (arch chroot).' + echo '' + echo 'There may be multiple chroots; they are stored in $CHROOTDIR.' + echo '' + echo 'Each chroot is named; the default is configured with $CHROOT.' + echo '' + echo "Each named chroot has a master clean copy (named 'root'), and any" + echo 'number of other named copies; the copy used by default is the' + echo "current username (or \$SUDO_USER, or 'copy' if root)." + echo '' + echo 'The full path to the chroot copy is "$CHROOTDIR/$CHROOT/$COPY",' + echo 'Unless the copy name is manually specified as an absolute path,' + echo 'in which case, that path is used.' + echo '' + echo 'The current settings for the above varibles are:' + echo " CHROOTDIR : $CHROOTDIR" + echo " CHROOT : $CHROOT" + echo " COPY : $COPY" + echo " root path : $rootdir" + echo " copy path : $copydir" + echo '' + echo 'If the chroot, or copy does not exist, it will be created' + echo 'automatically.' echo '' echo 'This command will make the following configuration changes in' echo 'the chroot:' @@ -44,81 +65,104 @@ usage() { echo " - overwrite \`/etc/pacman.d/mirrorlist'" echo " - set \`CacheDir' in \`/etc/pacman.conf'" echo '' + echo 'Creating a copy, deleting a copy, or syncing a copy can be fairly' + echo 'slow; but are very fast if $CHROOTDIR is on a btrfs partition.' + echo '' echo 'Options:' - echo ' Settings:' - echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'" - echo " -l <COPY> Use this chroot copy instead \`$CHROOTCOPY'" + echo ' -n <CHROOT> Name of the chroot to use' + echo ' -l <COPY> Name of, or absolute path to, the copy to use' echo ' -N Disable networking in the chroot' + echo ' -C <file> Location of pacman config file' + echo ' -M <file> Location of makepkg config file' 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 Show this message' + echo 'Commands:' + echo ' Create/copy/delete:' + echo ' noop|make Do not do anything, but still creates the' + echo ' chroot copy if it does not exist' + echo " sync Sync the copy with the clean ('root') copy" + echo " delete delete the chroot copy" + echo ' Dealing with packages:' + echo ' install-file FILES... Like `pacman -U FILES...`' + echo ' install-name NAMES... Like `pacman -S NAMES...`' + echo ' update Like `pacman -Syu`' + echo ' clean-pkgs Remove all "exta" packages from the chroot copy' + echo ' Other:' + echo ' run CMD... Run CMD in the chroot copy' + echo ' enter Enter an interactive shell in the chroot copy' + echo ' clean-repo Clean /repo in the chroot copy' + echo ' help Show this message' # usage } +# Globals: $CHROOTDIR, $CHROOT, $COPY, $rootdir and $copydir main() { - CHROOTCOPY=$LIBREUSER - [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + COPY=$LIBREUSER + [[ $COPY != root ]] || COPY=copy + + # defaults + rootdir="${CHROOTDIR}/${CHROOT}/root" + copydir="${CHROOTDIR}/${CHROOT}/${COPY}" local mode=enter - local archroot_args=(-f) - local ARG='' - while getopts 'n:l:NCcI:i:mr:suh' arg; do + local archroot_args=() # not local + while getopts 'n:l:NC:M:' arg; do case $arg in n) CHROOT=$OPTARG;; - 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;; - m) mode=noop;; - r) mode=run; ARG=$OPTARG;; - s) mode=sync;; - u) mode=update;; - - h) usage; exit 0;; - *) usage; exit 1;; + l) COPY=$OPTARG;; + N) + # We do this so that it carries through to + # chroot_* functions + archroot() { + $(which archroot) -N "$@" + } + ;; + C|M) archroot_args+=(-$arg "$OPTARG");; + *) usage; return 1;; esac done shift $(($OPTIND - 1)) - if [[ $# > 0 ]]; then + if [[ $# < 1 ]]; then + error "Must specify a command" usage - exit 1 + return 1 fi + mode=$1 + shift - # not local rootdir="${CHROOTDIR}/${CHROOT}/root" - copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + if [[ ${COPY:0:1} = / ]]; then + copydir=$COPY + else + copydir="${CHROOTDIR}/${CHROOT}/${COPY}" + fi ######################################################################## + if [[ $mode == help ]]; then + usage + return 0 + fi + if (( EUID )); then - error "This script must be run as root." - exit 1 + error "This program must be run as root." + return 1 fi + umask 0022 + # 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" \ "Waiting for existing lock on \`$copydir' to be released" if [[ ! -d $rootdir ]]; then - libremkchroot "$CHROOT" + archroot "${archroot_args[@]}" -m "$rootdir" fi - if [[ ! -d $copydir ]] && [[ $mode != sync ]]; then - chroot_sync + if [[ ! -d $copydir ]] || [[ $mode == sync ]]; then + normshell chroot_sync "$CHROOTDIR/$CHROOT" "$COPY" fi - mkdir -p $copydir/etc/libretools.d + mkdir -p "$copydir/etc/libretools.d" { if [[ -n ${CHROOTEXTRAPKG[@]:-} ]]; then printf 'CHROOTEXTRAPKG=(' @@ -127,37 +171,53 @@ main() { else printf 'CHROOTEXTRAPKG=()\n' fi - } > $copydir/etc/libretools.d/chroot.conf + } > "$copydir"/etc/libretools.d/chroot.conf + + if [[ $mode != delete ]]; then + # "touch" the chroot first + # this will + # - overwrite \`/etc/pacman.d/mirrorlist'" + # - set \`CacheDir' in \`/etc/pacman.conf'" + # - apply -C or -M flags + archroot "${archroot_args[@]}" -r "$copydir" true + fi ######################################################################## - trap cleanup EXIT case "$mode" in - clean_repo) + # Creat/copy/delete + noop|make|sync) :;; + delete) + if [[ -d $copydir ]]; then + normshell chroot_delete "$copydir" + fi + ;; + + # Dealing with packages + install-file) normshell chroot_install_pkgs "$copydir" "$@";; + install-name) archroot -r "$copydir" pacman -Sy "$@";; + clean-pkgs) + trap "rm -f '$copydir'/clean '$copydir'/chrootexec" EXIT + cp -a "$(which chcleanup)" "$copydir/clean" + echo '#!/bin/bash' > "$copydir/chrootexec" + echo 'mkdir /build' >> "$copydir/chrootexec" + echo 'cd /build; /clean' >> "$copydir/chrootexec" + chmod 755 "$copydir/chrootexec" + archroot -r "$copydir" /chrootexec + ;; + + # Other + run) archroot -r "$copydir" "$@";; + enter) archroot -r "$copydir" bash;; + clean-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) - cleanup+=("rm -f $copydir/clean $copydir/chrootexec") - cp -a "$(which chcleanup)" "${copydir}/clean" - 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) - cleanup+=("rm $copydir/${ARG##*/}") - cp "$ARG" "$copydir/${ARG##*/}" - archroot "${archroot_args[@]}" "${copydir}" -r "pacman -U /${ARG##*/} --noconfirm" + *) + error "Unrecognized command: \`$mode'" + return 1 ;; - install_pkg) archroot "${archroot_args[@]}" "${copydir}" -i $ARG ;; - noop) :;; - run) archroot "${archroot_args[@]}" "${copydir}" -r "$ARG" ;; - sync) chroot_sync;; - update) archroot "${archroot_args[@]}" "${copydir}" -u ;; - enter) archroot "${archroot_args[@]}" "${copydir}" -r bash ;; esac } diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index a9e1fb7..25f23c6 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -3,7 +3,7 @@ # Copyright 2010 - 2011 Nicolás Reynolds # Copyright 2011 Joshua Ismael Haase Hernández -# Copyright 2012 Luke Shumaker +# Copyright 2012-2013 Luke Shumaker # # This file is part of Parabola. # @@ -23,22 +23,131 @@ . /usr/share/libretools/conf.sh load_conf_libretools_chroot -. "$(which libremessages)" -. /usr/share/devtools/makechrootpkg.sh +. libremessages shopt -s nullglob +umask 0022 -# Boring functions ############################################################# +# Boring/mundane functions ##################################################### -## # End inmediately but print a useful message -## trap_exit() { - copy_logs error "$*" + set +euE + . /usr/share/devtools/makechrootpkg.sh + chroot_copy_out_logs "$@" exit 1 } +# Usage run [-N] $copydir "$cmd" +# Runs cmd properly, whether in a chroot already or not. +# +# Note that $cmd is a quoted string, not a list of arguments. +# $copydir=/ if INCHROOT=true +# +# Environment +# - $INCHROOT is set +run() { + local HASNET=true + [[ $1 == -N ]] && { HASNET=false; shift; } + local cmd="$*" + + cat >"$copydir/chrootexec" <<EOF +#!/bin/bash +. /etc/profile +${INCHROOT} || export HOME=/build +${INCHROOT} || cd /build + +${cmd} +EOF + chmod 755 "$copydir/chrootexec" + + local flags='' + if $INCHROOT; then + $HASNET || flags='-n' + unshare $flags -- /chrootexec + else + $HASNET || flags='-N' + librechroot $flags -l "$copydir" run /chrootexec + fi +} + +# Usage: add_to_local_repo $copydir +add_to_local_repo() ( + set +euE + . /usr/share/devtools/makechrootpkg.sh + chroot_add_to_local_repo "$@" +) + +# Usage: chroot_copy_in $copydir +# Environment: +# - In the dirctory of a PKGBUILD +# - $SRCDEST is set +chroot_copy_in() ( + set +euE + . /usr/share/devtools/makechrootpkg.sh + chroot_copy_in "$@" +) + +# Usage: chroot_copy_out $copydir $owner +# Environment: +# - $SRCDEST is set +# - $PKGDEST is set +chroot_copy_out() ( + set +euE + . /usr/share/devtools/makechrootpkg.sh + chroot_copy_out_pkgs "$@" + chroot_copy_out_logs "$@" + chroot_copy_out_srcs "$@" +) + +# Usage: chroot_let_nobody_use_pacman $copydir +chroot_let_nobody_use_pacman() ( + set +euE + . /usr/share/devtools/makechrootpkg.real.sh + chroot_let_nobody_use_pacman "$@" +} + +# Usage: chroot_init $copydir $repack +# Environment +# - $LIBREHOME is set +chroot_init() { + local $copydir=$1 + local $repack=$2 + + librechroot -l "$copydir" make # make sure the chroot exists + mkdir -p "$copydir"/{build,pkgdest,srcdest} + + # Remove anything in there UNLESS -R (repack) was passed + $repack || rm -rf "$copydir"/build/* + + if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then + install -D "$LIBREHOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg" + fi + rm -f "$copydir/build/.makepkg.conf" + + MAKEPKG_CONF="$copydir/etc/makepkg.conf" set_conf_makepkg PKGDEST /pkgdest + MAKEPKG_CONF="$copydir/etc/makepkg.conf" set_conf_makepkg SRCDEST /srcdest + + if grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then + cat >> "$copydir/etc/makepkg.conf" <<EOF +[repo] +SigLevel = Optional TrustAll +Server = file:///repo +EOF + fi + + chroot_let_nobody_use_pacman +} + +# Core functions ############################################################### + +# Usage: extract +# Extracts the sources (`makepkg -o`) +# Environment: +# - $INCHROOT is set +# - $copydir is set +# - $LIBREUSER is set extract() { local user=$LIBREUSER $INCHROOT || user=nobody @@ -51,14 +160,21 @@ extract() { clean=/clean fi - chroot_exec "${clean} && sudo -u ${user} ${MAKEPKG} ${makepkg_args} -o" + run "$copydir" "${clean} && sudo -u ${user} makepkg ${makepkg_args} -o" + rm -f "$copydir"/clean } +# Usage: build +# Builds the package (`makepkg -e`) +# Environment: +# - $INCHROOT is set +# - $copydir is set +# - $LIBREUSER is set build() { local user=$LIBREUSER $INCHROOT || user=nobody - chroot_exec -N "sudo -u ${user} ${MAKEPKG} ${makepkg_args} -e" + run -N "$copydir" "sudo -u ${user} makepkg ${makepkg_args} -e" } # Functions that check for issues with the build ############################### @@ -99,34 +215,39 @@ usage() { echo "SRCDEST in the chroot's \`/etc/makepkg.conf', as well as making" echo "whataver alterations to the chroot \`librechroot' makes." echo '' + echo "The \`-n' and \`-l' options behave identically to librechroot," + echo 'see the documentation there.' + echo '' echo 'Options:' - echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'" - echo " -l <COPY> Use this chroot copy instead \`$CHROOTCOPY'" - echo " -m <MAKEPKG> Use the command MAKEPKG instead of \'makepkg'" + echo ' -n <CHROOT> Name of the chroot to use' + echo ' -l <COPY> Name of, or absolute path to, the copy to use' + echo ' -R Repackage contents of the package without rebuilding' echo ' -h Show this message' } +# Globals: $CHROOTDIR, $CHROOT, $COPY and $copydir +# Globals: $makepkg_args, $INCHROOT main() { # Parse command line ################################################### - CHROOTCOPY=$LIBREUSER - [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + COPY=$LIBREUSER + [[ $COPY != root ]] || COPY=copy makepkg_args='-s --noconfirm -L ' - MAKEPKG=makepkg + local repack=false INCHROOT=false if [[ -f /.arch-chroot ]]; then INCHROOT=true fi - while getopts 'n:l:m:Rh' arg ; do + while getopts 'n:l:Rh' arg ; do case "${arg}" in n) CHROOT=$OPTARG;; - l) CHROOTCOPY=$OPTARG;; - m) MAKEPKG=$OPTARG;; - h) usage; exit 0;; - *) usage; exit 1;; + l) COPY=$OPTARG;; + R) repack=true; makepkg_args+=" -R";; + h) usage; return 0;; + *) usage; return 1;; esac done shift $(($OPTIND - 1)) @@ -134,9 +255,11 @@ main() { makepkg_args+=" $*" if $INCHROOT; then - copydir='' + copydir='/' + elif [[ ${COPY:0:1} = / ]]; then + copydir=$COPY else - copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + copydir="${CHROOTDIR}/${CHROOT}/${COPY}" fi # Init ################################################################# @@ -148,14 +271,14 @@ main() { if [[ ! -f PKGBUILD ]]; then # This is the message used by makepkg - error "PKGBUILD does not exist" + error "PKGBUILD does not exist." 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 + trap 'trap_exit "(libremakepkg): An error has occurred. Exiting..."' ERR SRCDEST="$(get_conf_makepkg SRCDEST .)" PKGDEST="$(get_conf_makepkg PKGDEST .)" @@ -163,7 +286,7 @@ main() { # OK, we're starting now ############################################### lock_open_write 9 "$copydir" \ - "Waiting for existing lock on \`$copydir' to be released" + "Waiting for existing lock on chroot copy to be released: [$COPY]" # Set target CARCH as it might be used within the PKGBUILD to select # correct sources @@ -171,17 +294,17 @@ main() { export CARCH="$(get_conf_makepkg CARCH)" unset MAKEPKG_CONF - $INCHROOT || chroot_init + $INCHROOT || chroot_init "$copydir" "$repack" check_pkgbuild - $INCHROOT || chroot_copy_in + $INCHROOT || chroot_copy_in "$copydir" extract check_src build check_pkg - add_to_local_repo - $INCHROOT || chroot_copy_out + add_to_local_repo "$copydir" + $INCHROOT || chroot_copy_out "$copydir" "$LIBREUSER" } main "$@" diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot deleted file mode 100755 index 6a13792..0000000 --- a/src/chroot-tools/libremkchroot +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -euE -# libremkchroot - -# Copyright 2011, 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/>. - -. /usr/share/libretools/conf.sh -load_conf_libretools_chroot - -. "$(which libremessages)" - -cmd=${0##*/} - -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 ' -C <file> Location of pacman config file.' - echo ' -M <file> Location of makepkg config file.' -} - -main() { - archroot_args=(-f); - 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 - - if (( EUID )); then - error "This script must be run as root" - exit 1 - fi - - mkdir -p "${CHROOTDIR}/${CHROOT}" - archroot "${archroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" -i base base-devel sudo "${CHROOTEXTRAPKG[@]}" -} - -main "$@" |