YMLib Systems Librarian

一些設定的記錄

我的相片
名稱:
位置: WuGu, Taipei, Taiwan

我是個大光頭,因我的頭型適合這一型。I have a perfect head style.

星期二, 10月 24, 2006

Mac OS 認證系統: NetInfo 手動新增帳號的方法

那麼多niutil的指令,
但要新增帳號,
有現成的script執行:
adduser_OSX.sh

在何處找,基本上是:
http://www.brownnut.com/adduser_OSX.htm
但連不上,所以就直接post上來script,是可work的!

#!/bin/sh
#
# MacOSX user account tool
# version 1.0a
# Written by Dino Amato 06/17/2001
# dino@brownnut.com
# GPL
#################################

## Root check here
if [ "`id -u`" = "0" ]; then
echo ""
else
echo "You need to be root to run this"
exit
fi

#########
# userid
#########

echo "Enter Login Name (userid):"
read userid
if [ "x$userid" = "x" ]; then
echo "Login Name Needed"
exit
fi

######################################
# Lets check if user is already added
######################################

echo ""
echo "Checking if UID is already used ...."
echo ""
ttt=`niutil -list . /users | awk '{print $2}' | egrep ^$userid`
if [ "$userid" = "$ttt" ]; then
echo "##################################################"
echo ""
echo "The UID you entered is already in the database ..."
echo "Use another UID or remove current UID ..."
echo ""
echo "##################################################"
echo ""
exit
fi


# Full Name
############

echo "Full Name:"
read full_name
if [ "x$full_name" = "x" ]; then
echo "Full Name Needed"
exit
fi

######
# UID
######

echo "Enter Unix UID:"
read uid
if [ "x$uid" = "x" ]; then
echo "UID Needed"
exit
fi

######
# GID
######

echo "Enter Unix GID, default is $uid:"
read gid
if [ "x$gid" = "x" ]; then
gid="$uid"
else
gid="$gid"
fi

########
# Shell
########

echo "Shell: (/bin/tcsh default)"
read shell
if [ "x$shell" = "x" ]; then
shell="/bin/tcsh"
else
shell="/bin/$shell"
fi

###########
# Home dir
###########

echo "Home Dir: (default /Users/$userid)"
read home
if [ "x$home" = "x" ]; then
home="/Users/$userid"
else
home="/$home/$userid"
fi

echo ""
echo "###########################"
echo ""
echo "Login Name: $userid"
echo "User ID: $uid"
echo "Group Number: $uid"
echo "Full Name: $full_name"
echo "Login Shell: $shell"
echo "Home Dir: $home"
echo ""
echo "###########################"
echo ""
echo "Is it ok to proceed? (y/n)"
read A
if [ $A = y ]; then

echo ""
echo "Creating Account ...."
echo ""
niutil -create . /users/$userid
niutil -createprop . /users/$userid uid $uid
niutil -createprop . /users/$userid gid $gid
niutil -createprop . /users/$userid shell $shell
niutil -createprop . /users/$userid home $home
niutil -createprop . /users/$userid realname "$full_name"
niutil -createprop . /users/$userid _shadow_passwd
niutil -createprop . /users/$userid sharedDir Public
#niutil -createprop . /users/$userid _writers_passwd
#niutil -createprop . /users/$userid _writers_hint
#
echo "Creating Directories ...."
echo ""
mkdir $home
cp /usr/share/skel/login.std $home/.login
cp /usr/share/skel/tcshrc.std $home/.tcshrc
cp /usr/share/skel/logout.std $home/.logout
# lets add default OSX dirs
cp /usr/share/skel/folder.std.tar $home
cd $home
tar xf $home/folder.std.tar
rm -f $home/folder.std.tar
echo "Setting Perms ...."
echo ""
chown -R $uid.$gid $home
chmod -R 700 $home
chmod 755 $home/Library $home/Movies $home/Music $home/Pictures $home/Public $home
/Sites
#
passwd $userid

else
exit
fi