summaryrefslogtreecommitdiffstats
path: root/rooty 2.sh
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2012-05-26 00:22:05 -0500
committerKamil Kaminski <kyle@kkaminsk.com>2012-05-26 00:22:05 -0500
commit5c961dc755954d1a2f90248c81aff725cf38466c (patch)
tree73aebdd6101d798355149d6499186ef9a2ef866b /rooty 2.sh
downloadscripts-5c961dc755954d1a2f90248c81aff725cf38466c.tar.gz
scripts-5c961dc755954d1a2f90248c81aff725cf38466c.tar.bz2
scripts-5c961dc755954d1a2f90248c81aff725cf38466c.zip
initial commit
Diffstat (limited to 'rooty 2.sh')
-rwxr-xr-xrooty 2.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/rooty 2.sh b/rooty 2.sh
new file mode 100755
index 0000000..2b4dad9
--- /dev/null
+++ b/rooty 2.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# $0 is visible globally, in functions too
+
+# apparently su -c accepts a command and 1 argument, hence we export
+CMDL_ARGS=$@
+export CMDL_ARGS
+
+chk_root()
+{
+ if [[ ! $(id -u) -eq 0 ]]; then
+ echo "root user required";
+ # exec works similar to fork()
+ exec su -c "\"$0\" $CMDL_ARGS"
+ exit $?
+ fi
+}
+
+chk_root $@
+if [[ $(id -u) -eq 0 ]]; then
+ echo "you're root"
+fi
+