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-70-g09d2 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-70-g09d2 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-70-g09d2 From 03611dc63e3e44d0504f0d05c3129fbc0b2d1510 Mon Sep 17 00:00:00 2001 From: Sébastien Luttringer 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 --- arch-nspawn.in | 2 +- archbuild.in | 4 +--- lib/common.sh | 13 +++++++++++++ makechrootpkg.in | 2 +- mkarchroot.in | 3 ++- 5 files changed, 18 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/arch-nspawn.in b/arch-nspawn.in index 6900382..4436a0e 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -37,8 +37,8 @@ while getopts 'hC:M:c:' arg; do done shift $(($OPTIND - 1)) -(( $EUID != 0 )) && die 'This script must be run as root.' (( $# < 1 )) && die 'You must specify a directory.' +check_root "$0" "$@" working_dir=$(readlink -f "$1") shift 1 diff --git a/archbuild.in b/archbuild.in index b1c96f9..ae2f511 100644 --- a/archbuild.in +++ b/archbuild.in @@ -40,9 +40,7 @@ done # Pass all arguments after -- right to makepkg makechrootpkg_args+=("${@:$OPTIND}") -if (( EUID )); then - die 'This script must be run as root.' -fi +check_root "$0" "$@" if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then msg "Creating chroot for [${repo}] (${arch})..." 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.' +} diff --git a/makechrootpkg.in b/makechrootpkg.in index 47c6ac9..97c7780 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -81,7 +81,7 @@ while getopts 'hcur:I:l:nTD:d:' arg; do esac done -(( EUID != 0 )) && die 'This script must be run as root.' +check_root "$0" "$@" [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' diff --git a/mkarchroot.in b/mkarchroot.in index 7cdb274..fb472bc 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -35,9 +35,10 @@ while getopts 'hC:M:c:' arg; do done shift $(($OPTIND - 1)) -(( $EUID != 0 )) && die 'This script must be run as root.' (( $# < 2 )) && die 'You must specify a directory and one or more packages.' +check_root "$0" "$@" + working_dir="$(readlink -f $1)" shift 1 -- cgit v1.2.3-70-g09d2