summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-08-22 17:58:46 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-08-22 17:58:46 (EDT)
commit3086c09b2b3888f4d99a7df3a959a07216953921 (patch)
tree34cdf37f93ea306930759cf721a3f46e35e8ae97
parentc538c3a709552912ebce960922c569d46def35ac (diff)
prokit: Check for superuser privileges
-rw-r--r--locale/en_US.sh3
-rw-r--r--src/prokit.sh20
2 files changed, 23 insertions, 0 deletions
diff --git a/locale/en_US.sh b/locale/en_US.sh
index d39cf1b..efeaea5 100644
--- a/locale/en_US.sh
+++ b/locale/en_US.sh
@@ -21,6 +21,9 @@
msg_prokit_opt_h_summary='print this help message'
msg_prokit_opt_V_summary='print version information'
+# src/prokit.sh
+msg_prokit_uid_0_req='Must be run as the superuser'
+
# lib/fd.sh
msg_prokit_emfile='Too many open files'
msg_prokit_cant_fopen='Cannot open file'
diff --git a/src/prokit.sh b/src/prokit.sh
index b87d1ef..91e76c8 100644
--- a/src/prokit.sh
+++ b/src/prokit.sh
@@ -83,6 +83,7 @@ main()
else
cmd="${1}"
shift
+ check_uid || error 1 "$(get_msg 'uid_0_req')"
fi
run_cmd "${cmd}" "${@}"
@@ -90,4 +91,23 @@ main()
return ${?}
}
+check_uid()
+{
+ local uname_s=
+ local uid=
+
+ uname_s="$( (uname -s) 2>/dev/null)" || uname_s='unknown'
+ uid="$(id -u)"
+
+ case "${uname_s}" in
+ 'Linux')
+ if [ ${uid} -ne 0 ]; then
+ return 1
+ fi
+ ;;
+ esac
+
+ return 0
+}
+
main "${@}"