summaryrefslogtreecommitdiffstats
path: root/lib/common.sh
diff options
context:
space:
mode:
authorSébastien Luttringer <seblu@seblu.net>2014-01-08 01:15:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-05-10 08:05:08 +0200
commit03611dc63e3e44d0504f0d05c3129fbc0b2d1510 (patch)
tree770ca5cea407be8a4c9ad0cd9ec8b5de30e429f4 /lib/common.sh
parent7aac293d76e4bdf6ceee1cfe5d888060c24f1822 (diff)
downloaddevtools-03611dc63e3e44d0504f0d05c3129fbc0b2d1510.tar.gz
devtools-03611dc63e3e44d0504f0d05c3129fbc0b2d1510.tar.xz
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 <pierre@archlinux.de>
Diffstat (limited to 'lib/common.sh')
-rw-r--r--lib/common.sh13
1 files changed, 13 insertions, 0 deletions
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.'
+}