#!/bin/bash # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # /var/db/dslocal/nodes/Default/users/jdoe.plist # dscl . list /Users # dscl . -read /Users/jdoe # dscl . list /Groups GroupMembership # dscl . search /Users name jdoe # dscl . read /Groups # Tiger created groupname = loginname # Leopard creates groupname = 'staff', e.g. '20' # useradd 899112222 password USERNAME="$1" PASSWORD="$2" if [[ $UID -ne 0 ]]; then echo " sorry, must be root to run this script" exit 1 fi RESULT=$(dscl . list /Users | grep "^$USERNAME\$") if [ -n "$RESULT" ]; then echo " user account: \"$USERNAME\" already exists" exit 1 fi MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1) USERID=$((MAXID+1)) # gleaned from Workgroup Manager MCXSETTINGS=$(cat< mcx_application_data com.apple.finder Forced mcx_preference_settings ProhibitBurn ProhibitConnectTo ProhibitEject ProhibitGoToFolder ProhibitGoToiDisk com.apple.loginwindow Forced mcx_preference_settings RestartDisabledWhileLoggedIn ShutDownDisabledWhileLoggedIn EOF) DESKTOP=$(cat< /dev/null cd /Users /usr/sbin/createhomedir -l -c > /dev/null /usr/bin/defaults write /Users/$USERNAME/Library/Preferences/com.apple.desktop "$DESKTOP" /usr/sbin/chown $USERNAME:20 /Users/$USERNAME/Library/Preferences/com.apple.desktop.plist # show new account dscl . read /Users/$USERNAME | grep "user account"