summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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.'
+}