Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Adduser script for Mac OS X:
- # Usage: adduser [-u UID] [-c COMM] [-d HOME] [-g GID] [-G GRP[,GRP...]]
- # [-s SHELL] USER
- #
- # Small hack for adding users via command line
- #
- # COPYRIGHT 2009 CYNAMICS Johan E. < [email protected] >
- #
- 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, Cyn Engine STOPS 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: NOT AN APPLE SCRIPT. A Cyn Engine: Cynamics Script."
- echo "About to execute:"
- 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 is."
- for i in 1; do do_it; done
- echo "The output of finger and id:"
- finger $name
- id $name
Advertisement
Add Comment
Please, Sign In to add comment