diff options
author | Andrew Fyfe <andrew@neptune-one.net> | 2007-06-03 01:59:54 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-06-03 22:19:52 -0400 |
commit | b69edc1c3532816576198995675dd6ad53df74df (patch) | |
tree | c54d9f60160629fe6eb9c0f88a9746fd4bc30a8f | |
parent | 76fd85450e2c6efca8e423f63d4740552e33544e (diff) |
scripts/makepkg.in: Improve error handling and clean up on exit.
* makepkg now runs with errexit (exit on syntax error) enabled
for the whole script.
* Removed unneeded setting of errexit around build().
* Added bash traps to catch TERM HUP INT signals.
* Added trap to catch unhandled/unknown errors.
* Added trap to call clean_up() when the script exits.
* Moved call to remove_deps() into clean_up().
* Moved -c/--clean code into clean_up().
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | scripts/makepkg.in | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 9c6470d2..106501db 100644 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # # makepkg - make packages compatable for use with pacman # @configure_input@ @@ -103,6 +103,55 @@ error() { fi } + +## +# Special exit call for traps, Don't print any error messages when inside, +# the fakeroot call, the error message will be printed by the main call. +## +trap_exit() { + if [ "$INFAKEROOT" = "0" ]; then + echo + error "$@" + fi + exit 1 +} + + +## +# Clean up function. Called automatically when the script exits. +## +clean_up() { + local EXIT_CODE=$? + + if [ "$INFAKEROOT" = "1" ]; then + # Don't clean up when leaving fakeroot, we're not done yet. + return + fi + + if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then + # If it's a clean exit and -c/--clean has been passed... + msg "$(gettext "Cleaning up...")" + cd "$startdir" + rm -rf pkg src + if [ "$pkgname" != "" ]; then + # Can't do this unless the BUILDSCRIPT has been sourced. + rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*" + fi + fi + + remove_deps +} + + +## +# Signal Traps +## +trap 'clean_up' 0 +trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT +trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT +trap 'trap_exit "$(gettext "An unknown error has occured. Exiting...")"' ERR + + strip_url() { echo "$1" | sed 's|^.*://.*/||g' } @@ -594,9 +643,6 @@ run_build() { # ensure all necessary build variables are exported export CFLAGS CXXFLAGS MAKEFLAGS - # check for "exit on syntax error" shell option - echo $SHELLOPTS | grep errexit 2>&1 >/dev/null; set_e=$? - local ret=0 if [ "$LOGGING" = "1" ]; then BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" @@ -612,15 +658,9 @@ run_build() { mv "$BUILDLOG" "$BUILDLOG.$i" fi - # use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} - [ $set_e -eq 1 ] && set +e else - # use 'errexit' to bail on syntax error - [ $set_e -eq 1 ] && set -e build 2>&1 || ret=$? - [ $set_e -eq 1 ] && set +e fi if [ $ret -gt 0 ]; then @@ -1296,15 +1336,6 @@ else create_xdelta "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" fi -cd "$startdir" -if [ "$CLEANUP" = "1" ]; then - msg "$(gettext "Cleaning up...")" - rm -rf src pkg - rm -rf ${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log* -fi - -remove_deps - msg "$(gettext "Finished making: %s")" "$pkgname ($(date))" install_package |