#!/bin/bash #################################################### ## Adduser script hack for Mac OS X ## Usage: adduser [-u UID] [-c COMM] [-d HOME] [-g GID] [-G GRP[,GRP...]] ## [-s SHELL] USER ## Copyright 2007 by Adam Katz for ICS , LGPL #################################################### # See also http://lists.apple.com/archives/Darwinos-users/2002/Sep/msg00064.html invalid() { echo "${0##*/}: $* Try '${0##*/} --help'" >&2 exit 1 } while [ -n "$1" ]; do case "$1" in -u ) uid="$2" ;; -[Cc] ) full="$2" ;; -d ) dir="$2" ;; -g ) gid="$2" ;; # I think this has to be a number -G ) grps="$2" ;; -s ) shell="$2";; -h|--help ) sed -e '/^## /!d' -e 's///' "`which $0 || echo $0`"; exit 0 ;; -* ) invalid "unknown option '$1' (maybe you need to space the args?)" ;; esac name="$1" shift; shift # uh, "shift 2" is unsupported! done if [ -z "$name" ]; then invalid "no name specified."; fi if [ -z "$uid" ]; then uid=`ls -ln /Users |awk '{printf $3"\n"}' |sort |uniq |tail -n1` uid=`expr 1 + $uid 2>/dev/null` if [ -z "$uid" ]; then echo "Unable to guess UID. Please enter one with the -u flag." >&2 exit 1 fi fi fail() { echo "${0##*/}: Previous command FAILED, we're stopping here." break } do_it() { $runtest niutil -create / /users/$name || fail $runtest niutil -createprop / /users/$name shell ${shell:=/bin/bash} || fail if [ -n "$full" ]; then $runtest niutil -createprop / /users/$name realname "$full" || fail fi $runtest niutil -createprop / /users/$name uid $uid || fail if [ -z "$gid" ]; then $runtest niutil -create / /groups/$name || fail $runtest niutil -createprop / /groups/$name gid $uid || fail fi $runtest niutil -createprop / /users/$name gid ${gid:-$uid} || fail for group in ${grps//,/ }; do $runtest niutil -appendprop / /groups/$group users $name || fail done $runtest niutil -createprop / /users/$name home ${dir:=/Users/$name} || fail $runtest niutil -createprop / /users/$name _shadow_passwd || fail $runtest passwd $name || fail } echo "REMINDER: This is not an Apple (or Fink) script." echo "I am about to run this:" runtest=echo do_it |sed 's/^/ /' if [ "`uname -s`" != Darwin ]; then echo "This script is only supposed to be run on Mac OS ('Darwin'). Quitting." exit 1 fi echo "Is this okay to run [yN]? " read yn if [ "${yn#[Yy]}" = "${yn}" ] then echo "Didn't do anything. Please try again and/or fix me."; exit 0 fi echo "Here it goes!" for i in 1; do do_it; done # for loop enables "break" command from failure echo "Here's the output of finger and id:" finger $name id $name