Skip to content
Snippets Groups Projects
Commit 60dadfc9 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Start of check_user functions

parent 0a897b13
Branches
No related merge requests found
...@@ -27,4 +27,14 @@ Various references used in project. ...@@ -27,4 +27,14 @@ Various references used in project.
## References ## References
None so far. ### Including other Script Files
<https://stackoverflow.com/a/10823650>
### Check Number of Passed Args
<https://stackoverflow.com/a/6482403>
### Get User's name
<https://stackoverflow.com/a/19306837>
### String Manipulation
<https://stackoverflow.com/a/14703709>
utils.sh 100644 → 100755
#!/usr/bin/env bash #!/usr/bin/env bash
###
# A helper/utility script to be imported by other scripts.
#
# Intended to hold very common functionality (that's surprisingly not built into bash) such as string upper/lower,
# and checking current user value, and prompts of yes/no user input.
##
###
# Function to check if current username matches passed value.
# In particular, is used to check if user is sudo/root user.
##
function check_is_user () {
# Check number of passed function args. Continue.
if [[ $# == 1 ]]
then
local username=$USER
local check_user=$1
echo "user is ${username}."
echo "check_user is ${check_user}"
# Handle for too many args.
elif [[ $# > 1 ]]
then
echo "Too many args passed. Expected one arg of username to check against."
exit 1
# Handle for too few args.
else
echo "Too few args passed. Expected one arg of username to check against."
exit 1
fi
}
###
# Function to check if current username does not match passed value.
# In particular, is used to check if user is sudo/root user.
##
function check_is_not_user () {
# Check number of passed function args.
if [[ $# == 1 ]]
then
# Got the expected number of function args. Continue.
local username=$USER
local check_user=$1
echo "user is ${username}."
echo "check_user is ${check_user}"
# Handle for too many args.
elif [[ $# > 1 ]]
then
echo "Too many args passed. Expected one arg of username to check against."
exit 1
# Handle for too few args.
else
echo "Too few args passed. Expected one arg of username to check against."
exit 1
fi
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment