Created
November 26, 2017 00:10
-
-
Save pamtrak06/fc2426ff49928fe0d2e95bfc059caedc to your computer and use it in GitHub Desktop.
bash script for mac osx user creation commmands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findCurrentOSType() | |
{ | |
osType=$(uname) | |
case "$osType" in | |
"Darwin") | |
echo "OS: MacOSX detected" | |
;; | |
"Linux") | |
echo "OS: Linux detected" | |
;; | |
*) | |
{ | |
echo "Unsupported OS, exiting" | |
exit | |
} ;; | |
esac | |
} | |
function check-user-exist-on-host { | |
user=$1 | |
findCurrentOSType | |
# create user jenkins and sonar on host machine | |
if id "$user" >/dev/null 2>&1; then | |
echo "INFO: user $user exists" | |
else | |
echo -e "ERROR: user user does not exist, please add it" | |
case "$osType" in | |
"Darwin") | |
{ | |
echo -e "\tsudo dscl . -create /Users/$user" | |
echo -e "\tsudo dscl . -create /Users/$user UserShell /bin/bash" | |
echo -e "\tsudo dscl . -create /Users/$user RealName \"$user\"" | |
NEXTUID=$(dscl . -list /Users UniqueID | awk 'BEGIN{i=0}{if($2>i)i=$2}END{print i+1}') | |
echo -e "\tsudo dscl . -create /Users/$user UniqueID $NEXTUID" | |
NEXTGID=$(dscl . -list /Groups PrimaryGroupID | awk 'BEGIN{i=0}{if($2>i)i=$2}END{print i+1}') | |
echo -e "\tsudo dscl . -create /Users/$user PrimaryGroupID $NEXTGID" | |
echo -e "\tsudo dscl . -create /Users/luser NFSHomeDirectory /Users/$user" | |
echo -e "\tsudo dscl . -passwd /Users/$user" | |
} ;; | |
"Linux") | |
{ | |
echo -e "\tsudo useradd -u $user -g $user -d /home/$user $user" | |
echo -e "\tsudo usermod -aG docker $user" | |
} ;; | |
esac | |
exit | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment