diff options
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-x | src/chroot-tools/buildenv | 28 | ||||
-rwxr-xr-x | src/chroot-tools/chcleanup | 57 | ||||
-rwxr-xr-x | src/chroot-tools/librechroot | 113 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg | 126 | ||||
-rwxr-xr-x | src/chroot-tools/libremkchroot | 64 |
5 files changed, 388 insertions, 0 deletions
diff --git a/src/chroot-tools/buildenv b/src/chroot-tools/buildenv new file mode 100755 index 0000000..84a1fc2 --- /dev/null +++ b/src/chroot-tools/buildenv @@ -0,0 +1,28 @@ +#!/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/chcleanup b/src/chroot-tools/chcleanup new file mode 100755 index 0000000..17c1f02 --- /dev/null +++ b/src/chroot-tools/chcleanup @@ -0,0 +1,57 @@ +#!/bin/bash +# (c) Nicolás Reynolds <fauno@parabola.nu> +# Released under GPLv3 +# +# Performs chroot cleanup smartly, it only removes the unneeded packages or +# leaves you with a cleansystem +# +# See: HOOKPREBUILD + +set -e +DRYRUN=${DRYRUN:-false} + +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 we're running makepkg +if [ -f PKGBUILD ]; then + source PKGBUILD || true + + check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]}) + +fi + +# 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} + +# 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[@]} + +# Cleanup +${DRYRUN} || rm -fr ${TMPDIR} + +exit $? diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot new file mode 100755 index 0000000..158828b --- /dev/null +++ b/src/chroot-tools/librechroot @@ -0,0 +1,113 @@ +#!/bin/bash +# LibreChRoot +# Enters a chroot + +# Copyright 2010 Nicolás Reynolds +# Copyright 2011 Joshua Haase + +# ---------- 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/>. + +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 "" + +} + +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}" +} + +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" +} +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 diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg new file mode 100755 index 0000000..f7924f6 --- /dev/null +++ b/src/chroot-tools/libremakepkg @@ -0,0 +1,126 @@ +#!/bin/bash +# Copyright 2010 - 2011 Nicolás Reynolds +# Copyright 2011 Joshua Ismael Haase Hernández + +# ---------- 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/>. + + +# set -x # uncomment for debug + +function copy_log { # copy logs if they exist + + find "${CHROOTDIR}/${CHROOT}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \; + +} + + +function trap_exit { # End inmediately but print a useful message + + copy_log + error "$@" + exit 1 + +} + +# 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 + +source /etc/libretools.conf + +CLEANFIRST="false" +UPDATEFIRST="false" +CHECKNONFREE="true" +LIBRECHROOT_ARGS="" +MAKEPKG_ARGS="" + +function usage { + + echo '' + 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 '' + echo 'OPTIONS:' + 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 '' + exit 1 + +} + +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 diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot new file mode 100755 index 0000000..b576209 --- /dev/null +++ b/src/chroot-tools/libremkchroot @@ -0,0 +1,64 @@ +#!/bin/bash +# LibreMkChroot +# Creates a chroot + +# 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 + +cmd=${0##*/} +function usage { + echo "Usage: $cmd [OPTIONS]" + 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 '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 ;; + esac +done + +if (( EUID )); then + error "This script must be run as root" + exit 1 +fi + +mkdir -p "${CHROOTDIR}" +xargs -d'\n' mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/root" < /etc/libretools.d/cleansystem |