summaryrefslogtreecommitdiff
path: root/libremakepkg
diff options
context:
space:
mode:
Diffstat (limited to 'libremakepkg')
-rwxr-xr-xlibremakepkg85
1 files changed, 55 insertions, 30 deletions
diff --git a/libremakepkg b/libremakepkg
index 0baaed2..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.'
@@ -35,19 +36,22 @@ function usage {
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}; do
msg2 "binding ${mp} to ${CHROOTDIR}/${CHCOPY}${mp}"
mkdir -p "${CHROOTDIR}/${CHCOPY}${mp}"
mount -o bind ${mp} "${CHROOTDIR}/${CHCOPY}${mp}" || exit 1
done
+
}
-# 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
@@ -71,19 +75,22 @@ EOF
) > "${CHROOTDIR}/${CHROOTNAME}/clean"
chmod +x "${CHROOTDIR}/${CHROOTNAME}/clean"
mkarchroot -r "/clean" "${CHROOTDIR}/${CHROOTNAME}"
+
}
-copy_log() {
+function copy_log { # copy logs if they exist
+
if [ "${USE_LOG}" == 'y' ]; then
find ${CHROOTDIR}/${CHROOTNAME}/build/ -name "*\.log" -exec cp {} ./ \;
fi
+
}
+function trap_exit { # End inmediately but print a useful message
-# End inmediately but print a useful message
-trap_exit() {
+# 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
@@ -94,8 +101,7 @@ trap_exit() {
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
@@ -108,14 +114,12 @@ USE_LOG='n'
CHROOTNAME=${CHCOPY}
MAKEPKG_ARGS=""
-#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" ;;
n) CHROOTNAME="$OPTARG" ;;
@@ -131,32 +135,53 @@ 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 [ "${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