diff options
Diffstat (limited to 'src/chroot-tools/libremakepkg')
-rwxr-xr-x | src/chroot-tools/libremakepkg | 253 |
1 files changed, 161 insertions, 92 deletions
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 "$@" |