From f56d7904f6fab99a0e2774828ba1858d77af042f Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Sat, 6 Aug 2016 11:07:47 +0800 Subject: functions.sh: add as-root function --- functions.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'functions.sh') diff --git a/functions.sh b/functions.sh index 3c05320..1ee9590 100644 --- a/functions.sh +++ b/functions.sh @@ -48,3 +48,13 @@ umount_iso() { getuuid() { lsblk -n -o UUID "$1" } + +as-root() { + if [ "$UID" == 0 ]; then + "$@" + elif type -p sudo > /dev/null; then + sudo "$@" + elif type -p su > /dev/null; then + su -c "$*" + fi +} -- cgit v1.2.3