#!/bin/sh
# CreateAdminUser.sh
#
# Created by David Kittell on 12/8/17.
#
clear
userFullName=$1
userName=$2
userPassword=$3
echo "Checking If User Exists"
# List Local Users
# dscl . list /Users | grep -v '_'
if [[ $(dscl . list /Users) =~ "$userName" ]]; then
echo "User Exists"
else
echo "User Does Not Exist"
maxid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
#echo $maxid
newid=$((maxid+1))
#echo $newid
sudo dscl . -create /Users/$userName
sudo dscl . -create /Users/$userName UserShell /bin/bash
sudo dscl . -create /Users/$userName RealName "$userFullName"
sudo dscl . -create /Users/$userName PrimaryGroupID 1000
sudo dscl . -create /Users/$userName UniqueID $newid
sudo dscl . -append /Groups/admin GroupMembership $userName
sudo dscl . -create /Users/$userName NFSHomeDirectory /Local/Users/$userName
sudo dscl . -passwd /Users/$userName "$userPassword"
fi
sudo sh CreateAdminUser.sh "Test User" "lUser" "SomethingSecret"
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.
Related