index : devtools32 | |
Archlinux32 fork of devtools | gitolite user |
summaryrefslogtreecommitdiff |
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-10 18:06:29 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-05-10 18:06:29 -0400 |
commit | 33730fc272bec6376a28d8f813e9e35ec4f84175 (patch) | |
tree | 0b85c3687a968fe83baa879952984f18f75f3061 /lib/common.sh | |
parent | 534d2015b45e013b37e1edbb997bd4df27d7b8fd (diff) | |
parent | 905198295dcb4fffcd16edff3fd7052a4cfc5788 (diff) |
-rw-r--r-- | lib/common.sh | 23 |
diff --git a/lib/common.sh b/lib/common.sh index dff9b43..455e841 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -71,12 +71,12 @@ cleanup() { if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then rm -rf "$WORKDIR" fi - [[ -n ${1:-} ]] && exit $1 + exit ${1:-0} } abort() { - msg 'Aborting...' - cleanup 0 + error 'Aborting...' + cleanup 255 } trap_abort() { @@ -91,7 +91,7 @@ trap_exit() { die() { (( $# )) && error "$@" - cleanup 1 + cleanup 255 } ## @@ -117,7 +117,7 @@ get_full_version() { pkgbase=${pkgbase:-${pkgname[0]}} epoch=${epoch:-0} if [[ -z $1 ]]; then - if [[ $epoch ]] && (( ! $epoch )); then + if (( ! epoch )); then echo $pkgver-$pkgrel else echo $epoch:$pkgver-$pkgrel @@ -258,3 +258,16 @@ find_cached_package() { return 1 esac } + +## +# usage : check_root ("$0" "$@") +## +check_root() { + (( EUID == 0 )) && return + if type -P sudo >/dev/null; then + exec sudo -- "$@" + else + exec su root -c "$(printf '%q' "$@")" + fi + die 'This script must be run as root.' +} |