From 9ee05e6933dae1ea3d896a0f18b0da8101eb3790 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Wed, 19 Mar 2014 19:55:14 -0300 Subject: [PATCH] Add kickstart.user.root? --- docs/index.md | 1 + docs/kickstart/user/root?.md | 13 +++++++++++++ kickstart/recipes/kickstart/user.sh | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 docs/kickstart/user/root?.md diff --git a/docs/index.md b/docs/index.md index a7398ca..05c071a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -43,3 +43,4 @@ * [kickstart.user.exec](kickstart/user/exec) * [kickstart.user.is_on_group](kickstart/user/is_on_group) * [kickstart.user.remove_group](kickstart/user/remove_group) +* [kickstart.user.root?](kickstart/user/root?) diff --git a/docs/kickstart/user/root?.md b/docs/kickstart/user/root?.md new file mode 100644 index 0000000..a16e657 --- /dev/null +++ b/docs/kickstart/user/root?.md @@ -0,0 +1,13 @@ +# kickstart.user.root? + +Return 0 if the user running is root and 1 if not. + + +### Example + +```bash +$ whoami +root +$ kickstart.user.root? && echo yup +yup +``` diff --git a/kickstart/recipes/kickstart/user.sh b/kickstart/recipes/kickstart/user.sh index bcf3239..7c51e8b 100644 --- a/kickstart/recipes/kickstart/user.sh +++ b/kickstart/recipes/kickstart/user.sh @@ -47,3 +47,7 @@ kickstart.user.exec() { kickstart.info Running \'"$@"\' as $user su $user - bash -c "$command" } + +kickstart.user.root?() { + [ `whoami` == root ] +}