diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 3 | ||||
-rw-r--r-- | src/abslibre-tools/Makefile | 3 | ||||
-rw-r--r-- | src/chroot-tools/Makefile | 3 | ||||
-rwxr-xr-x | src/chroot-tools/chcleanup | 72 | ||||
-rw-r--r-- | src/chroot-tools/chroot.conf | 13 | ||||
-rwxr-xr-x | src/chroot-tools/librechroot | 101 | ||||
-rwxr-xr-x[-rw-r--r--] | src/chroot-tools/librechroot.gpl2 | 7 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg | 123 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg.gpl2 | 60 | ||||
-rwxr-xr-x | src/chroot-tools/libremkchroot | 5 | ||||
-rw-r--r-- | src/fullpkg/Makefile | 3 | ||||
-rw-r--r-- | src/lib/Makefile | 2 | ||||
-rw-r--r-- | src/lib/conf.sh | 110 | ||||
-rw-r--r-- | src/libretools.conf | 23 | ||||
-rw-r--r-- | src/mips64el-tools/Makefile | 3 | ||||
-rw-r--r-- | src/toru/Makefile | 3 |
16 files changed, 350 insertions, 184 deletions
diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..ff8d399 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(bindir) +libre_datadir=$(sysconfdir) +include ../common.mk diff --git a/src/abslibre-tools/Makefile b/src/abslibre-tools/Makefile new file mode 100644 index 0000000..f2cec54 --- /dev/null +++ b/src/abslibre-tools/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(bindir) +libre_datadir=$(sysconfdir)/libretools.d +include ../../common.mk diff --git a/src/chroot-tools/Makefile b/src/chroot-tools/Makefile new file mode 100644 index 0000000..3ae95ea --- /dev/null +++ b/src/chroot-tools/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(sbindir) +libre_datadir=$(sysconfdir)/libretools.d +include ../../common.mk diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup index 17c1f02..821c572 100755 --- a/src/chroot-tools/chcleanup +++ b/src/chroot-tools/chcleanup @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -eE # (c) Nicolás Reynolds <fauno@parabola.nu> # Released under GPLv3 # @@ -7,51 +7,51 @@ # # See: HOOKPREBUILD -set -e DRYRUN=${DRYRUN:-false} +source "$(which libremessages)" -source /etc/makepkg.conf -source /etc/libretools.conf -source ${HOME}/.makepkg.conf 2>/dev/null|| true - -msg "Cleaning chroot..." - -TMPDIR="$(mktemp -d /tmp/$(basename $0)-XXXXX)" -cleanup_log="${TMPDIR}"/libretools-cleanup.log - -cp -a /var/lib/pacman/sync "${TMPDIR}/" -touch ${cleanup_log} +if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then + error "(chcleanup): Must be run inside of a chroot" + exit 1 +fi +source /etc/libretools.d/chroot.conf # If we're running makepkg if [ -f PKGBUILD ]; then - source PKGBUILD || true + source PKGBUILD + CHROOTEXTRAPKG+=("${depends[@]}" + "${makedepends[@]}" + "${checkdepends[@]}") +fi - check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]}) +msg "Cleaning chroot..." -fi +TEMPDIR="$(mktemp --tmpdir -d $(basename $0).XXXXX)" +cp -a /var/lib/pacman/sync "${TEMPDIR}/" +cleanup_log="${TEMPDIR}"/libretools-cleanup.log # Get the full list of packages needed by dependencies, including the base system -sudo pacman -b "${TMPDIR}" \ - -Sp \ - --print-format "%n" \ - base base-devel sudo \ - ${CHROOTEXTRAPKG[@]} \ - ${check[@]} \ - >${cleanup_log} +pacman -b "${TEMPDIR}" \ + -Sp --print-format "%n" \ + base base-devel sudo "${CHROOTEXTRAPKG[@]}" \ + >"${cleanup_log}" # Diff installed packages against a clean chroot then remove leftovers -packages=($(comm -23 <(pacman -Qq | sort) \ - <(sort -u ${cleanup_log}))) - -[ ${#packages[@]} -eq 0 ] && exit 0 - -msg2 "Removing %d packages" ${#packages[@]} - -# Only remove leftovers, -Rcs removes too much -${DRYRUN} || sudo pacman --noconfirm -Rn ${packages[@]} -${DRYRUN} && echo ${packages[@]} - +packages=($(comm -23 <(pacman -Qq | sort -u) \ + <(sort -u "${cleanup_log}"))) + +RET=0 +if [[ ${#packages[@]} != 0 ]]; then + msg2 "Removing %d packages" ${#packages[@]} + + if ${DRYRUN}; then + echo "${packages[@]}" + else + # Only remove leftovers, -Rcs removes too much + pacman --noconfirm -Rn "${packages[@]}" || RET=$? + fi +fi # Cleanup -${DRYRUN} || rm -fr ${TMPDIR} +rm -rf "${TEMPDIR}" -exit $? +exit $RET diff --git a/src/chroot-tools/chroot.conf b/src/chroot-tools/chroot.conf new file mode 100644 index 0000000..d84e8b4 --- /dev/null +++ b/src/chroot-tools/chroot.conf @@ -0,0 +1,13 @@ +# The full path to the chroot is +# $CHROOTDIR/$CHROOT/$CHROOTCOPY +# where $CHROOTCOPY is set at runtime, either +# - based on the username +# - set with the `-l COPY` flag +# The purpose of having a $CHROOT setting is that multiple clones of the same +# base $CHROOT can quickly and easily be created. +CHROOTDIR=/var/lib/archbuild +CHROOT=default + +# Extra packages to have installed on the chroot. +# This is in addition to CHROOTPKG=(base base-devel sudo) +CHROOTEXTRAPKG=(distcc ccache tsocks libretools) 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 } diff --git a/src/chroot-tools/librechroot.gpl2 b/src/chroot-tools/librechroot.gpl2 index 6ba361f..1b5d90a 100644..100755 --- a/src/chroot-tools/librechroot.gpl2 +++ b/src/chroot-tools/librechroot.gpl2 @@ -19,20 +19,21 @@ sync() { exit 1 fi - lock_open_read 8 "$rootdir" "Locking clean chroot" + lock_open_read 8 "$rootdir" \ + "Waiting for existing lock on \`$rootdir' to be released" 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 + btrfs subvolume snapshot "$rootdir" "$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" + rsync -a --delete -q -W -x "$rootdir/" "$copydir" fi stat_done diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index 4e810d1..2901b0d 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -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)" shopt -s nullglob @@ -29,9 +32,10 @@ shopt -s nullglob . "$(dirname "$0")/libremakepkg.gpl2" # This gives us the functions: # - chroot_init -# - chroot_extract -# - chroot_build -# - copy_pkgs +# - chroot_exec +# - chroot_copy_in +# - chroot_copy_out +# - add_to_local_repo # Boring functions ############################################################# @@ -54,37 +58,31 @@ trap_exit() { 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'" +extract() { + local user=$LIBREUSER + $INCHROOT || user=nobody + + local clean + if $INCHROOT; then + clean=chcleanup + else + cp -a "$(which chcleanup)" "${copydir}/clean" + clean=/clean fi -} -chroot_makepkg_conf_get() { - local setting=$1 - eval $(grep "^$setting=" "$copydir/etc/makepkg.conf") + chroot_exec "${clean} && sudo -u ${user} ${MAKEPKG} ${makepkg_args} -o" } -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" +build() { + local user=$LIBREUSER + $INCHROOT || user=nobody + + chroot_exec -N "sudo -u ${user} ${MAKEPKG} ${makepkg_args} -e" } # Functions that check for issues with the build ############################### -libre_check_pkgbuild() { +check_pkgbuild() { msg "Checking PKGBUILD for issues" # TODO if ! pkgbuild-check-nonfree -f; then @@ -98,12 +96,12 @@ libre_check_pkgbuild() { fi } -libre_check_src() { +check_src() { msg "Checking src directory for issues" # TODO } -libre_check_pkg() { +check_pkg() { msg "Checking final package for issues" # TODO } @@ -113,17 +111,18 @@ libre_check_pkg() { cmd=${0##*/} usage() { - echo "Usage: $cmd [options] [-- makepkg args]" - echo 'This program will build your package.' - 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 " -m <MAKEPKG> Use the command MAKEPKG instead of 'makepkg'" - echo '' - echo ' -h Show this message' + echo "Usage: $cmd [options] [-- makepkg args]" + echo 'This program will build your package.' + echo '' + echo 'If run from outside of a chroot, this will set PKGDEST and' + echo "SRCDEST in the chroot's \`/etc/makepkg.conf', as well as making" + echo "whataver alterations to the chroot \`librechroot' makes." + 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 ' -h Show this message' } main() { @@ -135,6 +134,11 @@ main() { makepkg_args='-s --noconfirm -L ' MAKEPKG=makepkg + INCHROOT=false + if [[ -f /.arch-chroot ]]; then + INCHROOT=true + fi + while getopts 'n:l:m:Rh' arg ; do case "${arg}" in n) CHROOT=$OPTARG;; @@ -148,8 +152,11 @@ main() { # Pass all arguments after -- right to makepkg makepkg_args+=" $*" - rootdir="${CHROOTDIR}/${CHROOT}/root" - copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + if $INCHROOT; then + copydir='' + else + copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + fi # Init ################################################################# @@ -169,27 +176,31 @@ main() { 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 . + SRCDEST="$(get_conf_makepkg SRCDEST .)" + PKGDEST="$(get_conf_makepkg PKGDEST .)" # OK, we're starting now ############################################### - lock_open_write 9 "$copydir" "Locking chroot '$CHROOTCOPY'" + lock_open_write 9 "$copydir" \ + "Waiting for existing lock on \`$copydir' to be released" - # Set target CARCH as it might be used within the PKGBUILD to select correct sources - chroot_makepkg_conf_get CARCH - export CARCH + # Set target CARCH as it might be used within the PKGBUILD to select + # correct sources + MAKEPKG_CONF=$copydir/etc/makepkg.conf + export CARCH="$(get_conf_makepkg CARCH)" + unset MAKEPKG_CONF - chroot_init + $INCHROOT || chroot_init - libre_check_pkgbuild - chroot_extract - libre_check_src - chroot_build - libre_check_pkg + check_pkgbuild + $INCHROOT || chroot_copy_in + extract + check_src + build + check_pkg - copy_pkgs - copy_logs + add_to_local_repo + $INCHROOT || chroot_copy_out } main "$@" diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2 index 1077b66..8770bee 100755 --- a/src/chroot-tools/libremakepkg.gpl2 +++ b/src/chroot-tools/libremakepkg.gpl2 @@ -20,11 +20,13 @@ chroot_init() { if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then install -D "$HOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg" fi + rm -f "$copydir/build/.makepkg.conf" mkdir -p "$copydir/pkgdest" mkdir -p "$copydir/srcdest" - chroot_makepkg_conf_set PKGDEST /pkgdest - chroot_makepkg_conf_set SRCDEST /srcdest + + MAKEPKG_CONF=$copydir/etc/makepkg.conf set_conf_makepkg PKGDEST /pkgdest + MAKEPKG_CONF=$copydir/etc/makepkg.conf set_conf_makepkg SRCDEST /srcdest cat > "$copydir/etc/sudoers.d/nobody-pacman" <<EOF Defaults env_keep += "HOME" @@ -33,7 +35,8 @@ EOF chmod 440 "$copydir/etc/sudoers.d/nobody-pacman" } -chroot_extract() { + +chroot_copy_in() { rm -rf "$copydir"/build/* cp PKGBUILD "$copydir/build/" ( @@ -64,42 +67,49 @@ chroot_extract() { ) chown -R nobody "$copydir"/{build,pkgdest,srcdest} - - cp -a "$(which chcleanup)" "${copydir}/clean" - local file="$copydir/chrootextract" - echo '#!/bin/bash' > "$file" - echo '. /etc/profile' >> "$file" - echo 'export HOME=/build' >> "$file" - echo 'cd /build' >> "$file" - echo '/clean' >> "$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 +chroot_exec() { + 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 -n "$CHROOT" -l "$CHROOTCOPY" -r /chrootexec + fi } -copy_pkgs() { +add_to_local_repo() { 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 - + done +} +chroot_copy_out() { + for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do chown "$LIBREUSER" "$pkgfile" mv "$pkgfile" "$PKGDEST" if [[ $PKGDEST != . ]]; then ln -s "$PKGDEST/${pkgfile##*/}" . fi done + copy_logs } diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index d3652a5..6a13792 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -18,7 +18,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)" cmd=${0##*/} diff --git a/src/fullpkg/Makefile b/src/fullpkg/Makefile new file mode 100644 index 0000000..f2cec54 --- /dev/null +++ b/src/fullpkg/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(bindir) +libre_datadir=$(sysconfdir)/libretools.d +include ../../common.mk diff --git a/src/lib/Makefile b/src/lib/Makefile new file mode 100644 index 0000000..0c69ba3 --- /dev/null +++ b/src/lib/Makefile @@ -0,0 +1,2 @@ +libre_datadir=$(datadir)/libretools +include ../../common.mk diff --git a/src/lib/conf.sh b/src/lib/conf.sh new file mode 100644 index 0000000..c5c5056 --- /dev/null +++ b/src/lib/conf.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +INCLUDE_CONF_SH=conf.sh + +LIBREUSER="${SUDO_USER:-$USER}" +LIBREHOME="$(eval echo ~$LIBREUSER)" +if [[ -z ${XDG_CONFIG_HOME:-} ]]; then + export XDG_CONFIG_HOME="${LIBREHOME}/.config" +fi + +# Generic functions ############################################################ + +get_files() { + local slug=$1 + case $slug in + makepkg.conf) + if [[ $MAKEPKG_CONF != /etc/$slug && -r $MAKEPKG_CONF ]]; then + echo "$MAKEPKG_CONF" + else + echo /etc/$slug + echo "$LIBREHOME/.$slug" + fi + ;; + libretools.conf) + echo /etc/$slug + echo "$XDG_CONFIG_HOME/libretools/$slug" + ;; + *.conf) + echo /etc/libretools.d/$slug + echo "$XDG_CONFIG_HOME/libretools/$slug" + ;; + esac +} + +load_files() { + for file in $(get_files $1.conf); do + if [[ -r $file ]]; then + . "$file" + fi + done +} + +check_vars() { + local slug=$1 + shift + local ret=0 + for VAR in "$@"; do + if [[ -z ${!VAR} ]]; then + if [[ $(get_files $slug|wc -l) > 1 ]]; then + echo "Configure '$VAR' in one of:" + get_files $slug | sed 's/./ -> &/' + else + echo "Configure '$VAR' in $(get_files $slug)" + fi + ret=1 + fi >>/dev/stderr + done + if [[ $ret != 0 ]]; then + return 1 + fi +} + +# makepkg configuration ######################################################## + +[[ -n ${MAKEPKG_CONF:-} ]] || MAKEPKG_CONF=/etc/makepkg.conf + +load_conf_makepkg() { + load_files makepkg +} + +get_conf_makepkg() ( + set +euE + local setting=$1 + local default=$2 + load_conf_makepkg + printf '%s\n' "${!setting:-${default}}" +) + +set_conf_makepkg() { + local key=$1 + local val=$2 + for file in `get_files makepkg.conf|tac`; do + if [[ -w $file ]]; then + sed -i "/^\s*$key=/d" "$file" + echo "$key='$val'" >> "$file" + return 0 + fi + done + return 1 +} + + +# libretools configuration ##################################################### + +load_conf_libretools() { + load_files libretools + # TODO: checks +} + +load_conf_libretools_chroot() { + load_files chroot + # Exclude CHROOTEXTRAPKG from the checks because an empty value is valid + if [[ -f /.arch-chroot ]]; then + # check_vars chroot CHROOTEXTRAPKG + : + else + # check_vars chroot CHROOTDIR CHROOT CHROOTEXTRAPKG + check_vars chroot CHROOTDIR CHROOT + fi +} diff --git a/src/libretools.conf b/src/libretools.conf index 5e45350..9e17871 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -25,18 +25,6 @@ REPOS=('core' 'libre' 'extra' 'community' 'libre-testing' 'social' 'sugar' 'pcr' ARCHES=('i686' 'x86_64' 'mips64el' 'any') ################################################################################ -# chroot # -################################################################################ - -## The directory where the chroots are stored -CHROOTDIR=/var/lib/archbuild -## Extra packages to have installed on the chroot (besides base base-devel and sudo) -CHROOTEXTRAPKG=(distcc ccache tsocks) -## The meaning of this changes based on the version of libretools+devtools -## do NOT set it to 'root' -CHROOT=default - -################################################################################ # abslibre # ################################################################################ @@ -106,6 +94,8 @@ TORUPATH=/var/lib/libretools/toru # This probably shouldn't be in a .conf file... # ################################################################################ +if [[ -n ${INCLUDE_CONF_SH:-} ]]; then + LIBREUSER="${SUDO_USER:-$USER}" LIBREHOME="$(eval echo ~$LIBREUSER)" if [[ -z ${XDG_CONFIG_HOME:-} ]]; then @@ -116,22 +106,19 @@ if [[ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]]; then fi ret=0 -for VAR in CHROOTDIR CHROOT PARABOLAHOST LIBREDESTDIR \ +for VAR in PARABOLAHOST LIBREDESTDIR \ BLACKLIST WORKDIR REPOS ARCHES ABSLIBREGIT \ COMMITCMD DIFFTOOL FULLBUILDCMD SIGEXT SIGID; do - if [[ -z ${!VAR} ]]; then echo "Configure $VAR var in /etc/libretools.conf" ret=1 fi done -if [[ $CHROOT == root ]]; then - echo "Configured var CHROOT cannot equal 'root'" - ret=1 -fi if [[ $ret != 0 ]]; then exit 1 fi unset ret . /usr/bin/libremessages + +fi diff --git a/src/mips64el-tools/Makefile b/src/mips64el-tools/Makefile new file mode 100644 index 0000000..f2cec54 --- /dev/null +++ b/src/mips64el-tools/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(bindir) +libre_datadir=$(sysconfdir)/libretools.d +include ../../common.mk diff --git a/src/toru/Makefile b/src/toru/Makefile new file mode 100644 index 0000000..f2cec54 --- /dev/null +++ b/src/toru/Makefile @@ -0,0 +1,3 @@ +libre_execdir=$(bindir) +libre_datadir=$(sysconfdir)/libretools.d +include ../../common.mk |