#!/bin/sh # add_pc_user # add smb and linux user, plus copy login.bat to username.bat in # netlogon directory # where login.bat is the default or template login script # (for example. maps network drive, sets time # login.bat: # net use h: /home # net time \\yourserver /set /yes # # if addpcuser is called with a second parameter, it will be # interpreted as the logon script to copy instead of login.bat # addpcuser xyz staff.bat # will add user named xyz and copy the file staff.bat to xyz.bat # in the netlogon share directory # while # addpcuser xyz will add user xyz and copy login.bat to xyz.bat # # if login.bat does not exist then new user will not have a xyz.bat # login script in netlogon share dir. # # $netlogdir = path to netlogon share directory echo "Add PC user account names and passwords for samba file service" export netlogdir="/home/samba/netlogon" echo "[netlogon] share directory path: $netlogdir" echo -n "Is this correct (y/n): " read yn if [ "$yn" = "n" ] ; then echo -n "Enter the path to the samba netlogon share (e.g. /home/samba/netlogon): " read nlp if [ "$nlp" = "" ] ; then echo "You must enter a value for path to the netlogon share directory." echo "Quitting" exit else export netlogdir="$nlp" fi else echo "" # default netlogdir is correct fi # ask which group for user (student, staff, office) gnum="1" gname="student" echo "Which group is this user in?" echo "1. student" echo "2. staff" echo "3. office" echo -n "Please enter the group number (1,2,3): " read gnum if [ "$gnum" = "1" ] ; then gname="student" fi if [ "$gnum" = "2" ] ; then gname="staff" fi if [ "$gnum" = "3" ] ; then gname ="office" fi #if [ "$gnum" = "1" ] ; then gname="student" fi #if [ "$gnum" = "2" ] ; then gname="staff" #if [ "$gnum" = "3" ]; then gname="office" echo "This user is in group: $gname" # $1 = un = username to be added, the one parameter that this # script must be called with # (if it's blank, error. prompt for it.) if [ "$1" = "" ] ; then echo -n "Enter user name to be added: " read un if [ "$un" = "" ] ; then echo "Error. You must enter a username to add." echo "Quitting." exit fi else export un=$1 fi echo "Creating linux and smb user accounts for $un" useradd $un passwd $un smbpasswd -a $un echo "Creating user login script ($un.bat in netlogon dir) (if any)" echo "Copies .bat into .bat" if [ "$2" = "" ] ; then # A=`ls "$netlogdir" | grep login` A=`ls "$netlogdir" | grep $gname` if [ "$A" = "" ] ; then echo "No group login.bat exists, no $un.bat created for user $un." exit else # cp "$netlogdir/login.bat" "$netlogdir/$un.bat" cp "$netlogdir/$gname.bat" "$netlogdir/$un.bat" fi else A=`ls "$netlogdir" | grep "$2"` if [ "$A" = "" ] ; then echo "No $2 exists, no $un.bat created for user $un." exit else cp "$netlogdir/$2" "$netlogdir/$un.bat" fi fi