From c000286dabf780061b46cfdadd2121869cd9e02a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 4 Jan 2015 15:59:26 -0500 Subject: Generate the duplicated code in chcleanup --- src/chroot-tools/.gitignore | 3 ++ src/chroot-tools/Makefile | 12 +++++ src/chroot-tools/chcleanup | 115 ------------------------------------------ src/chroot-tools/chcleanup.in | 94 ++++++++++++++++++++++++++++++++++ src/chroot-tools/librechroot | 2 + 5 files changed, 111 insertions(+), 115 deletions(-) delete mode 100755 src/chroot-tools/chcleanup create mode 100644 src/chroot-tools/chcleanup.in (limited to 'src') diff --git a/src/chroot-tools/.gitignore b/src/chroot-tools/.gitignore index 3f46ed2..f0969c7 100644 --- a/src/chroot-tools/.gitignore +++ b/src/chroot-tools/.gitignore @@ -2,3 +2,6 @@ makechrootpkg.sh* arch-nspawn* mkarchroot* !*.patch + +chcleanup +chcleanup.lib diff --git a/src/chroot-tools/Makefile b/src/chroot-tools/Makefile index c041cc8..db18ea4 100644 --- a/src/chroot-tools/Makefile +++ b/src/chroot-tools/Makefile @@ -1,3 +1,5 @@ +progs = chcleanup +clean_files = chcleanup.lib # These files are coming from devtools copy_files = makechrootpkg.sh.in mkarchroot.in arch-nspawn.in # These are programs that we will use internally, but shouldn't be in PATH @@ -13,4 +15,14 @@ include ../../common.mk makechrootpkg.sh.in: %.sh.in: $(devtoolsdir)/%.in cp $< $@ +chcleanup: chcleanup.in chcleanup.lib + m4 -P $< | $(edit) > $@ + chmod 755 $@ +chcleanup.lib: ../lib/common.sh.top ../lib/common.sh Makefile + { cat $<; bash -c '. ../lib/common.sh; declare -f plain msg msg2 error'; } > $@ + distcc-tool.pot: LIBREXGETTEXT_FLAGS+=--simple=errusage + +# This is so gross. I hate recursive Make. Why did I implement it this way? +../lib/common.sh: $(devtoolsdir)/lib/common.sh ../lib/common.sh.top ../lib/Makefile + $(MAKE) -C ../lib common.sh diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup deleted file mode 100755 index 4a11176..0000000 --- a/src/chroot-tools/chcleanup +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2011-2012 Nicolás Reynolds -# Copyright (C) 2012-2013 Luke Shumaker -# -# The plain, msg, msg2, and error functions are Copyright (C) their -# authors in devtools, and are assumed to be GPLv2+. -# -# License: GNU GPLv3+ -# -# 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, either version 3 of the License, or -# (at your option) any later version. -# -# 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# Performs chroot cleanup smartly, it only removes the unneeded packages or -# leaves you with a cleansystem -# -# See: HOOKPREBUILD - -set -eE - -DRYRUN=${DRYRUN:-false} - -################################################################################ -# Define these here to avoid having dependencies on outside files - -if type gettext &>/dev/null; then - _() { gettext "$@"; } -else - _() { echo "$@"; } -fi - -plain() { - local mesg="$(_ "$1")"; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg() { - local mesg="$(_ "$1")"; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg2() { - local mesg="$(_ "$1")"; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg="$(_ "$1")"; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -################################################################################ - -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 - export CARCH="$(. /etc/makepkg.conf; printf '%s' "$CARCH")" - source ./PKGBUILD - CHROOTEXTRAPKG+=("${depends[@]}" - "${makedepends[@]}" - "${checkdepends[@]}") -fi - -msg "Cleaning chroot..." - -# Sync the local repo with pacman -cp /repo/repo.db /var/lib/pacman/sync/repo.db - -# Setup the temporary directory -TEMPDIR="$(mktemp --tmpdir -d ${0##*/}.XXXXXXXXXX)" -trap "rm -rf -- $(printf '%q' "$TEMPDIR")" EXIT - -cp -a /var/lib/pacman/sync "${TEMPDIR}/" -pkglist="${TEMPDIR}"/pkglist.txt - -# Get the full list of packages needed by dependencies, including the base system -msg2 "Creating a full list of packages..." -pacman -b "${TEMPDIR}" \ - -Sp --print-format "%n" base-devel "${CHROOTEXTRAPKG[@]}" >"$pkglist" || { - ret=$? - error "Could not create a full list of packages, exiting." - plain "This is likely caused by a dependency that could not be found." - exit $ret -} - -# Diff installed packages against a clean chroot then remove leftovers -packages=($(comm -23 <(pacman -Qq | sort -u) \ - <(sort -u "${pkglist}"))) - -if [[ ${#packages[@]} = 0 ]]; then - msg2 "No packages to remove" -else - msg2 "Removing %d packages" ${#packages[@]} - - if ${DRYRUN}; then - echo "${packages[*]}" - else - # Only remove leftovers, -Rcs removes too much - pacman --noconfirm -Rn "${packages[@]}" - fi -fi diff --git a/src/chroot-tools/chcleanup.in b/src/chroot-tools/chcleanup.in new file mode 100644 index 0000000..d76989d --- /dev/null +++ b/src/chroot-tools/chcleanup.in @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# Copyright (C) 2011-2012 Nicolás Reynolds +# Copyright (C) 2012-2013 Luke Shumaker +# +# If you don't see m4_include(...) below, but see function definitions +# for msg() et al., then this is a generated file, and contains some +# code from librelib. The the source distribution for full copyright +# information. +# +# License: GNU GPLv3+ +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Performs chroot cleanup smartly, it only removes the unneeded packages or +# leaves you with a cleansystem +# +# See: HOOKPREBUILD + +set -eE + +DRYRUN=${DRYRUN:-false} + +# Statically include various library routines to avoid having +# dependencies on outside files. +# Begin chcleanup.lib ########################################################## +m4_include(chcleanup.lib) +# End chcleanup.lib ############################################################ + +if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then + error "(chcleanup): Must be run inside of a chroot" + exit 1 +fi + +# Note: the in-chroot pkgconfdir is non-configurable, this is +# intentionally hard-coded. +source /etc/libretools.d/chroot.conf +# If we're running makepkg +if [[ -f PKGBUILD ]]; then + export CARCH="$(. /etc/makepkg.conf; printf '%s' "$CARCH")" + source ./PKGBUILD + CHROOTEXTRAPKG+=("${depends[@]}" + "${makedepends[@]}" + "${checkdepends[@]}") +fi + +msg "Cleaning chroot..." + +# Sync the local repo with pacman +cp /repo/repo.db /var/lib/pacman/sync/repo.db + +# Setup the temporary directory +TEMPDIR="$(mktemp --tmpdir -d ${0##*/}.XXXXXXXXXX)" +trap "rm -rf -- $(printf '%q' "$TEMPDIR")" EXIT + +cp -a /var/lib/pacman/sync "${TEMPDIR}/" +pkglist="${TEMPDIR}"/pkglist.txt + +# Get the full list of packages needed by dependencies, including the base system +msg2 "Creating a full list of packages..." +pacman -b "${TEMPDIR}" \ + -Sp --print-format "%n" base-devel "${CHROOTEXTRAPKG[@]}" >"$pkglist" || { + ret=$? + error "Could not create a full list of packages, exiting." + plain "This is likely caused by a dependency that could not be found." + exit $ret +} + +# Diff installed packages against a clean chroot then remove leftovers +packages=($(comm -23 <(pacman -Qq | sort -u) \ + <(sort -u "${pkglist}"))) + +if [[ ${#packages[@]} = 0 ]]; then + msg2 "No packages to remove" +else + msg2 "Removing %d packages" ${#packages[@]} + + if ${DRYRUN}; then + echo "${packages[*]}" + else + # Only remove leftovers, -Rcs removes too much + pacman --noconfirm -Rn "${packages[@]}" + fi +fi diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 0fbb8f7..616d868 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -327,6 +327,8 @@ main() { _makechrootpkg sync_chroot "$CHROOTDIR/$CHROOT" "$COPY" fi + # Note: the in-chroot pkgconfdir is non-configurable, this is + # intentionally hard-coded. mkdir -p "$copydir/etc/libretools.d" { if [[ ${#CHROOTEXTRAPKG[*]} -eq 0 ]]; then -- cgit v1.2.2