Softice-user-add
From SOFTICE
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Developed by:
Contents |
Synopsis
This script creates and populates the specified user account on the SOFTICE cluster. It is located at /home/sys/bin/softice-user-add.
Usage
softice-user-add should be run either as the root user, or by using the sudo command.
Course numbering
Specifying the following course numbers trigger additional setup scripts to install course-specific files:
- cop4610 calls the softice-osc-setup script for Operating Systems Concepts
- eel4782 calls the softice-net-setup script for IT Computer Networks
Creating accounts one-at-a-time
To create accounts one-at-a-time, use the following syntax:
/home/sys/bin/softice-user-add course username password
For example, the following command will create an account named "bjones" with a password of "foobar" for course "eel4782".
/home/sys/bin/softice-user-add eel4782 bjones foobar
Creating accounts in batch
To create accounts in batch from a file, first create a file using the following syntax, with one line per student, and space separating each field:
Firstname Lastname username email password
For example:
Brad Jones bjones bjones@somedomain.com foobar
Then run softice-user-add on the accounts file using the following syntax:
/home/sys/bin/softice-user-add course-number /path/to/accounts-file
For example:
/home/sys/bin/softice-user-add eel4782 students.txt
File
#!/bin/bash
# copyleft Alessio Gaspar, SOFTICE project, 2006/07/17
# modified by Matt Rideout, SOFTICE project, 2007/07/31, 2007/08/30, 2007/09/13
# modified by Alessio Gaspar, SOFTICE project, 2008/01/09
# modified by Matt Rideout, SOFTICE project, 2008/08/27
# file: $SOFTICE_ROOT/bin/softice-user-add
# chmod: only executable by root
# credits: used parts of add_user script available at http://www.hccfl.edu/pollock/AUnix2/addUsers.htm
# Written 2002 by Wayne Pollock, Tampa FL USA.
# Create and then populate user account with all the data necessary for the student
# to work on the softice osc labs
#_____________________________________________________________________________
function usage {
#_____________________________________________________________________________
echo "softice-user-add Course StudentName Password"
echo " examples:"
echo " softice-user-add course StudentName Password"
echo " softice-user-add course FileName"
echo " filename needs to be an existing filename containing"
echo " students accounts information"
echo " Courses cop4610 and eel4782 also set up the environment for students"
echo " by calling respectively softice-osc-setup or softice-net-setup"
exit -1
}
#_____________________________________________________________________________
function add_from_file {
#_____________________________________________________________________________
# parameters
# $1 groupname
# $2 filename
groupname="students"
course=$1
filename=$2
if [[ ! -e $filename ]]
then
echo "Error: File $filename doesn't exist"
exit -1
fi
exec 3< $filename
until [ $done ]
do
# this one stores the line in a variable
read <&3 myline
# this one parses it according to $1 $2 $3...
set -- $myline
# The "--" prevents nasty surprises if $planet is null or
#+ begins with a dash.
# May need to save original positional parameters,
#+ since they get overwritten.
# One way of doing this is to use an array,
# original_params=("$@")
# cf. adv bash scripting guide
if [ $? != 0 ]
then
done=1
continue
fi
if [[ $# != 5 ]]
then
echo "Data file $filename not properly formatted"
echo "Last Name <tab> First Name <tab> Login Name <tab> Email Address <tab> Password"
echo "read $# words: $*"
exit -1
fi
StudentName="$1 $2"
StudentLogin=$3
StudentEmail=$4
StudentPassword=$5
echo " ADDING $StudentName to group $groupname with login $StudentLogin"
# the line below skips questions about where to store the default ssh key file and passphrase
# ok the ssh-keygen call below has been removed for now
add_one_student $course $StudentLogin $StudentPassword
mail -s "USF Linux account for $groupname" $StudentEmail <<EOF
The following account has been opened for you to use exclusively for work related to one of your USF course.
Please refer to the syllabus for information about legal and proper usage of the University computing resources.
Hostname: penguin.lakeland.usf.edu
Login: $StudentLogin
Password: $StudentPassword
Course: $course
EOF
done
exit 0;
}
#_____________________________________________________________________________
function add_one_student {
#_____________________________________________________________________________
course=$1
student=$2
password=$3
echo "Building environment for user $student course $course password $password"
echo " softice root = $SOFTICE_ROOT"
echo " TAG = $TAG"
for TARGET in /home/students /home/students/$course
do
if [[ ! -d $TARGET ]]
then
mkdir $TARGET
chown root:students $TARGET
chmod u=rwx,og=rx $TARGET
fi
done
#useradd -m -g students -d /home/students/$course/$student -c "$course" -e $closing -p '' $student -s /bin/bash
useradd -m -g students -d /home/students/$course/$student -p '' $student -s /bin/bash
echo $student:$password | chpasswd
# set the student as the owner of all files in their home directory, and deny access to all other users
chown -R $student:students /home/students/$course/$student
chmod -R og-rwx /home/students/$course/$student/
# create a Samba account
sambaPassword=`dd if=/dev/random count=10 bs=1 | hexdump | cut -d \ -f 2-| head -n 1 | tr -d " "`
$SOFTICE_ROOT/bin/smb-user-add $student $sambaPassword
# create .credentials file for SMB mounts
echo "username=$student" > /home/students/$course/$student/.credentials
echo "password=$sambaPassword" >> /home/students/$course/$student/.credentials
chown $student:students /home/students/$course/$student/.credentials
chmod 600 /home/students/$course/$student/.credentials
# add local users to nodes
cat /etc/shadow | grep ^$student: >> /vnfs/default/etc/shadow
wwnodes --sync
# TODO: verify pam settings for group students
# TODO: what about disk quotas
if [[ $TAG = "osc" ]]
then
su - $student -c $SOFTICE_ROOT/$TAG/bin/softice-osc-setup
fi
if [[ $TAG = "net" ]]
then
su - $student -c $SOFTICE_ROOT/$TAG/bin/softice-net-setup
fi
cd $WHEREWECOMEFROM
return
}
#_____________________________________________________________________________
# script starts here
#_____________________________________________________________________________
if [[ $# != 2 && $# != 3 ]]
then
usage
fi
# configuration of our softice installation
SOFTICE_ROOT="/home/sys"
WHEREWECOMEFROM="`pwd`"
course=$1
#let's first figure out if we're running for osc or elsa labs
if [[ $course = "cop4610" ]]
then
TAG="osc"
fi
if [[ $course = "eel4782" ]]
then
TAG="net"
fi
if [[ $# == 2 ]]
then
add_from_file $*
fi
if [[ $# == 3 ]]
then
add_one_student $*
fi
exit 0

