#!/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 .
source /etc/libretools.conf
source /etc/makepkg.conf
function usage {
echo 'cd to a dir containing a PKGBUILD and run:'
echo '$0 [options] [makepkg args]'
echo 'This script will build your package on a chroot.'
echo
echo 'OPTIONS:'
echo
echo ' -h show this message.'
echo ' -c cleans the chroot before building.'
echo ' -u updates the chroot before building.'
echo ' -n use this dir instead of "${CHCOPY}".'
echo ' -I install this package, use it as many times needed.'
echo ' -M <--arg> passes long args to makepkg, use it as many times as needed.'
echo
}
function buildenv {
msg "Building env"
for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
msg2 "binding /$mp"
mkdir -p "${CHROOTDIR}/${CHCOPY}${mp}"
mount -o bind ${mp} "${CHROOTDIR}/${CHCOPY}${mp}" || exit 1
done
for config in etc/makepkg.conf etc/pacman.conf etc/mtab; do
msg2 "copying config /$etc"
cp --remove-destination /$etc $CHROOTDIR/$CHCOPY/$etc || exit 1
done
}
# End inmediately but print a useful message
trap_exit() {
for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
umount "${CHROOTDIR}/${CHCOPY}${mp}"
done
error "$@"
exit 1
}
## Trap signals
# From makepkg
set -E
trap 'trap_exit "TERM signal caught. Exiting..."' TERM HUP QUIT
trap 'trap_exit "Aborted by user! Exiting..."' INT
trap 'trap_exit "An unknown error has occurred. Exiting..."' ERR
CLEAN_FIRST="n"
CLEAN_CACHE=""
UPDATE_FIRST="n"
USE_LOG='n'
CHROOTNAME=${CHCOPY}
PKGINSTALL=""
MAKEPKG_ARGS=""
#libremakepkg own args
libremakepkgargs='hcun:I:M:'
#now makepkg args
libremakepkgargs+='ACdefiLmop:rRs'
while getopts ${libremakepkgargs} arg ; do
case "${arg}" in
h) usage; exit 0 ;;
c) CLEAN_FIRST="y" ;;
u) update_first="y" ;;
n) chrootname="$OPTARG"; echo $chrootname ;;
I) PKGINSTALL+="-I $OPTARG " ;;
M) MAKEPKG_ARGS+=" $OPTARG" ;;
L) MAKEPKG_ARGS+=" -$arg $OPTARG"
use_log='y';;
*) MAKEPKG_ARGS+=" -$arg $OPTARG" ;;
esac
done
if [ ${UID} -ne 0 ]; then
error "This script must be run as root"
exit 1
fi
msg "Checking PKGBUILD for non-free issues"
pkgbuild-check-nonfree ||{
if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree
error "PKGBUILD contains non-free issues"
exit 15
fi
}
if [ "${UPDATE_FIRST}" = y ]; then
msg "Updating the chroot in use"
# -c option in mkarchroot indicates cache
mkarchroot -c ${CACHEDIR} -u "${CHROOTDIR}/${CHROOTNAME}"
elif [ "${CLEAN_FIRST}" = y ]; then
msg "Cleaning ..."
cp "/etc/libretools.d/cleansystem" "${CHROOTDIR}/${CHROOTNAME}/root"
(cat < "${CHROOTDIR}/${CHROOTNAME}/clean"
mkarchroot -r "/clean" "${CHROOTDIR}/${CHROOTNAME}"
elif [ -n ${PKGINSTALL} ]; then
msg "Installing packages"
makechrootpkg -r ${PKGINSTALL}
fi
buildenv
msg "Creating the package"
makechrootpkg -r ${CHROOTDIR} -l "${chrootname}" -- ${MAKEPKG_ARGS}
ev=$? # exit value
[ "${USE_LOG}" == 'y' -a -e ${CHROOTDIR}/${chrootname}/build/*.log ] && {
cp ${CHROOTDIR}/${chrootname}/build/*.log ./
}
exit $ev