From 4ee45fe6d4e5b317700ca0ac20a800af0b3cef69 Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Sun, 16 Feb 2014 09:55:58 +0100 Subject: abort and die are serious errors so throw 255 out Signed-off-by: BlackEagle Signed-off-by: Pierre Schmitz --- lib/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index cb9db76..04a282b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -69,8 +69,8 @@ cleanup() { } abort() { - msg 'Aborting...' - cleanup 0 + error 'Aborting...' + cleanup 255 } trap_abort() { @@ -85,7 +85,7 @@ trap_exit() { die() { (( $# )) && error "$@" - cleanup 1 + cleanup 255 } trap 'trap_abort' INT QUIT TERM HUP -- cgit v1.2.3 From 6db31cc16a8044272170204975378ece8eb94e2a Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Sun, 16 Feb 2014 09:55:59 +0100 Subject: when cleanup is called without code exit with 0 Signed-off-by: BlackEagle Signed-off-by: Pierre Schmitz --- lib/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 04a282b..1009e90 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -65,7 +65,7 @@ setup_workdir() { cleanup() { [[ -n $WORKDIR ]] && rm -rf "$WORKDIR" - [[ $1 ]] && exit $1 + exit ${1:-0} } abort() { -- cgit v1.2.3 From 7aac293d76e4bdf6ceee1cfe5d888060c24f1822 Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Sun, 16 Feb 2014 09:56:00 +0100 Subject: get_full_version :: remove duplicated epoch check Signed-off-by: BlackEagle Signed-off-by: Pierre Schmitz --- lib/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index 1009e90..c9ff1b8 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -114,7 +114,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 -- cgit v1.2.3 From 03611dc63e3e44d0504f0d05c3129fbc0b2d1510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Wed, 8 Jan 2014 01:15:37 +0100 Subject: Switch to root when started as regular user In collaborative builder machine, these scripts are often allowed to become root via sudo. This patch avoid to prefix them by sudo each time or call su. Signed-off-by: Pierre Schmitz --- lib/common.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index c9ff1b8..b885080 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -228,3 +228,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.' +} -- cgit v1.2.3