summaryrefslogtreecommitdiff
path: root/libremakepkg
diff options
context:
space:
mode:
authorNicolás Reynolds <apoyosis@correo.inta.gob.ar>2011-06-30 18:14:15 -0300
committerNicolás Reynolds <apoyosis@correo.inta.gob.ar>2011-06-30 18:14:15 -0300
commit8a385be009f51b1af2cd8fd82c08b6b7c2c7f8b0 (patch)
tree72e58e38d91827b9a2d116406a26bd894122d91f /libremakepkg
parent8dff8b1deac0bd4a832e1dee0173e79c55ab4301 (diff)
parent207a930a564e8157e24c3e7f5fbe987494b73d7b (diff)
Merge branch 'master' of ssh://vparabola/srv/git/projects/libretools
Diffstat (limited to 'libremakepkg')
-rwxr-xr-xlibremakepkg106
1 files changed, 64 insertions, 42 deletions
diff --git a/libremakepkg b/libremakepkg
index b2f8aa8..13e7617 100755
--- a/libremakepkg
+++ b/libremakepkg
@@ -22,7 +22,8 @@
source /etc/libretools.conf
source /etc/makepkg.conf
-function usage {
+function usage { # Display message and exit
+
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.'
@@ -32,30 +33,25 @@ function usage {
echo ' -h show this message.'
echo ' -c cleans the chroot before building.'
echo ' -u updates the chroot before building.'
- echo ' -U copy pacman, makepkg, and mtag config files to the chroot'
echo ' -n use this dir instead of "${CHCOPY}".'
echo ' -M <--arg> passes long args to makepkg, use it as many times as needed.'
echo
+ exit 1
}
-function buildenv {
+function buildenv { # Mounts *DEST from makepkg.conf
+
msg "Building env"
- for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
+ for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST}; do
msg2 "binding ${mp} to ${CHROOTDIR}/${CHCOPY}${mp}"
mkdir -p "${CHROOTDIR}/${CHCOPY}${mp}"
mount -o bind ${mp} "${CHROOTDIR}/${CHCOPY}${mp}" || exit 1
done
- if [ "$update_config" = 'y' ] ; then
- for config in etc/makepkg.conf etc/pacman.conf etc/mtab; do
- msg2 "copying config /$config to ${CHROOTDIR}/${CHCOPY}/${config}"
- cp --remove-destination /${config} ${CHROOTDIR}/${CHCOPY}/${config} || exit 1
- done
- fi
}
-# Clean packages with pacman
-function clean_chroot {
+function clean_chroot { # Clean packages with pacman
+
plain "making list of packages in ${CHROOTDIR}/${CHROOTNAME}/root/"
cp "/etc/libretools.d/cleansystem" "${CHROOTDIR}/${CHROOTNAME}/root/cleansystem"
(cat <<EOF
@@ -79,22 +75,33 @@ EOF
) > "${CHROOTDIR}/${CHROOTNAME}/clean"
chmod +x "${CHROOTDIR}/${CHROOTNAME}/clean"
mkarchroot -r "/clean" "${CHROOTDIR}/${CHROOTNAME}"
+
+}
+
+function copy_log { # copy logs if they exist
+
+ if [ "${USE_LOG}" == 'y' ]; then
+ find ${CHROOTDIR}/${CHROOTNAME}/build/ -name "*\.log" -exec cp {} ./ \;
+ fi
+
}
-# End inmediately but print a useful message
-trap_exit() {
+function trap_exit { # End inmediately but print a useful message
+
+# args are treated as part of the message
- for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST} ${WORKDIR}; do
+ for mp in ${SRCDEST} ${PKGDEST} ${SRCPKGDEST}; do
umount "${CHROOTDIR}/${CHCOPY}${mp}"
done
+ copy_log
+
error "$@"
exit 1
}
-## Trap signals
-# From makepkg
+# 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
@@ -106,19 +113,15 @@ UPDATE_FIRST="n"
USE_LOG='n'
CHROOTNAME=${CHCOPY}
MAKEPKG_ARGS=""
-update_config='n'
-#libremakepkg own args
-libremakepkgargs='hcuUn:I:M:'
-#now makepkg args
-libremakepkgargs+='ACdefiLmop:rRs'
+libremakepkgargs='hcuUn:I:M:' # libremakepkg own args
+libremakepkgargs+='ACdefiLmop:rRs' # makepkg args
while getopts ${libremakepkgargs} arg ; do
case "${arg}" in
- h) usage; exit 0 ;;
+ h) usage ;;
c) CLEAN_FIRST="y" ;;
u) UPDATE_FIRST="y" ;;
- U) update_config='y' ;;
n) CHROOTNAME="$OPTARG" ;;
M) MAKEPKG_ARGS+=" $OPTARG" ;;
L) MAKEPKG_ARGS+=" -$arg $OPTARG"
@@ -132,35 +135,54 @@ if [ ${UID} -ne 0 ]; then
exit 1
fi
+if [ ! -r 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"
-pkgbuild-check-nonfree ||{
- if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree
+if ! pkgbuild-check-nonfree; then
+
+ if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree
error "PKGBUILD contains non-free issues"
exit 15
else
true
fi
-}
-
-buildenv
-if [ "${UPDATE_FIRST}" = 'y' ]; then
- msg "Updating the chroot in use..."
-# -c option in mkarchroot indicates cache
- mkarchroot -c ${CACHEDIR} -u "${CHROOTDIR}/${CHROOTNAME}"
fi
-if [ "${CLEAN_FIRST}" = 'y' ]; then
- msg "Cleaning"
- clean_chroot
-fi
+buildenv
msg "Creating the package"
-makechrootpkg -r "${CHROOTDIR}" -l "${CHROOTNAME}" -- "${MAKEPKG_ARGS}"
-ev=$? # exit value
+if [ -d "${CHROOTDIR}/${CHROOTNAME}" ]; then # use chroot
-if [ "${USE_LOG}" == 'y' ]; then
- find ${CHROOTDIR}/${CHROOTNAME}/build/ -name "*\.log" -exec cp {} ./ \;
-}
+ if [ "${UPDATE_FIRST}" = 'y' ]; then
+ msg "Updating the chroot in use..."
+ mkarchroot -c ${CACHEDIR} -u "${CHROOTDIR}/${CHROOTNAME}" # -c option is for cache
+ fi
+
+ if [ "${CLEAN_FIRST}" = 'y' ]; then
+ msg "Cleaning"
+ clean_chroot
+ fi
+
+ makechrootpkg -r "${CHROOTDIR}" -l "${CHROOTNAME}" -- "${MAKEPKG_ARGS}"
+ ev=$? # exit value
+
+else # build new chroot before using
+
+ if [ "${UPDATE_FIRST}" = 'y' ]; then # update CHROOT
+ msg "Updating the chroot in use..."
+ mkarchroot -c ${CACHEDIR} -u "${CHROOTDIR}/${CHROOT}" # -c option is for cache
+ fi
+
+ makechrootpkg -c -r "${CHROOTDIR}" -l "${CHROOTNAME}" -- "${MAKEPKG_ARGS}"
+ ev=$? # exit value
+
+fi
+
+copy_log
exit $ev