Return to BSD News archive
Newsgroups: comp.os.386bsd.questions Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bruce.cs.monash.edu.au!maurice From: maurice@bruce.cs.monash.edu.au Subject: Re: Adduser script Message-ID: <1994Oct30.224035.2470@bruce.cs.monash.edu.au> Organization: Computer Science, Monash University, Australia Date: Sun, 30 Oct 1994 22:40:35 GMT Lines: 183 Paul Quinn (p_quinn@ECE.Concordia.CA) wrote: : I am looking for the adduser script. : Thanks in advance, : ________ : Paul Quinn Here is a version of an adduser script that I use for my FreeBSD 1.1R systems. It has been adapted from others work and consists of two files to simplify the process. ----------------------------- cut here --------------------------------- # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # addentry # adduser # echo x - addentry sed 's/^X//' >addentry << 'END-of-addentry' X#!/bin/sh Xsleep 1 Xcat /tmp/passwdentree >> $1 END-of-addentry echo x - adduser sed 's/^X//' >adduser << 'END-of-adduser' X#!/bin/sh X# X# add user script for use with 386bsd X# arguments: uname uid gid fullname homedir shell X# X# bmyers@rucs2.sunlab.cs.runet.edu X# X# Modified by M. Castro X# X# to execute type: X# sh add_user [uname] [uid] [gid] ["full name"] [homedir] [shell] X Xmyname=`basename $0` XPasswd=/etc/passwd XPATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin Xexport PATH X# check for root Xif [ "`whoami`x" != "root"x ]; then X echo "You must be root to do $myname!" X exit 1 Xfi X X# check for number of args X# Change to 5 if the directories are going to be in the same place X# ie. no homedir option given to the program X Xif [ $# -ne 6 ]; then X echo "${myname}: invalid number of arguments" X echo " usage: ${myname} uname uid gid \"fullname\" homedir shell" X exit 1 Xfi X X# put args into named variables Xuname=$1 Xuid=$2 Xgid=$3 Xfullname=$4 Xhomedir=$5 # If all directories are going to be in the same place Xshell=$6 # Then change homedir=$5 to homedir=/DIR/../$1 ie: /DIR/../UNAME X # homedir will be assumed on each call X X# checks for validity of arguments X# check uid Xif test $uid -lt 10 ; then X echo "uid: uid must be greater than 10 and less than 60000" X exit 1 Xelif test $uid -gt 60000 ; then X echo "uid: uid must be greater than 10 and less than 60000" X exit 1 Xfi X X# check gid Xif test $gid -lt 10 ; then X echo "gid: gid must be greater than 10 and less than 60000" X exit 1 Xelif test $gid -gt 60000 ; then X echo "gid: gid must be greater than 10 and less than 60000" X exit 1 Xfi X X X# check shell Xif test ! -x $shell ; then X echo "$shell: the program does not exist or is not executable" X exit 1 Xfi X X# check homedir X# check if homedir already exists Xif [ -f ${homedir} ]; then X echo "${myname}: WARNING: a file named \"${homedir}\" already exists" X echo "and is NOT a directory, NOT setting up user account" X exit 1 Xfi Xif [ -d ${homedir} ]; then X echo "${myname}: WARNING: home directory \"${homedir}\" already exists" X echo " no files copied, NOT setting up user account" X exit 1 Xfi X# check if all but last path of homedir exits X#dir=`shdirname $homedir` X#if test ! -d $dir ; then X# echo "$dir: does not exist or is not a directory" X# exit 1 X#fi X# check if $homedir is local Xdfout=`df $dir | ( read aline; read aline; echo $aline )` Xcase $dfout in X /dev*) ;; # $dir is on local machine X *) echo "$dir: is not on local machine" X exit 1;; Xesac X X# create a null /etc/passwd entry X# first check if one already exists Xif grep -s "^${uname}:" ${Passwd} ; then X echo "${myname}: ERROR: ${uname} aleady in ${Passwd}"; X exit 1; Xfi X# check if uid already exists Xif grep -s ".*:.*:${uid}:" ${Passwd} ; then X echo "uid: ERROR: ${uid} already in ${Passwd}"; X exit 1; Xfi Xpwent="${uname}::${uid}:${gid}::0:0:${fullname}:${homedir}:${shell}" X# XXX sould we use tmp file and rename it? X XEDITOR=/usr/sbin/addentry Xexport EDITOR X( echo "${pwent}"; ) > /tmp/passwdentree Xvipw ${Passwd} X X# Verify that the entree was saved. Xif grep -s "^${uname}:" ${Passwd} ; then X : Xelse X echo "${myname}: ERROR: password entry didn't go to ${Passwd}"; X exit 1; X rm -f /tmp/passwdentree # remove old file Xfi Xrm -f /tmp/passwdentree # remove old file X X# Set a temporary password so that passwd will work Xpasswd ${uname} X# make the home directory X/bin/mkdir ${homedir} X/usr/sbin/chown ${uname} ${homedir} X/usr/bin/chgrp ${gid} ${homedir} X X# add default user startup files Xfor i in /usr/share/skel/dot.* Xdo cp $i ${homedir}/`basename $i | sed s/dot//` Xdone X/usr/sbin/chown -R ${uname} ${homedir} X/usr/bin/chgrp -R ${gid} ${homedir} X X# is ok, exit 0 Xexit 0 END-of-adduser exit ----------------------------- cut here --------------------------------- -- Maurice Castro | "In hardware engineering, Ohm's maurice@bruce.cs.monash.edu.au | law and Maxwell's equations pale | in importance and influence next | to Murphy's Law" Gordon Bell -- Maurice Castro | "In hardware engineering, Ohm's maurice@bruce.cs.monash.edu.au | law and Maxwell's equations pale | in importance and influence next | to Murphy's Law" Gordon Bell