Listing 3: The createdev shell script
#!/bin/sh
#
# Create a development area
#
# Parameters :
# areaname : users can setdev to areaname
# arearoot : directory under which area will be created
#
# Preconditions :
# user ${areaname}own must exist
# group ${areaname}grp must exist
# $arearoot must exist
#
# Postconditions :
# root should add areaname:arearoot and users to the /etc/setdevd file
# after running this program.
#
# Author :
# Arthur Donkers
# Le Reseau netwerksystemen BV
# Burg. F. v. Ankenweg 5
# NL-9991 AM Middelstum
#
# Disclaimer :
#
# Use at your own will and risk
# Check arguments
if [ $# -ne 2 ]; then
echo "Usage : $0 <areaname> <arearoot>"
exit 1
fi
areaname=$1
arearoot=$2
# Check if arearoot exists
if [ ! -d $arearoot ]; then
echo "Area root $arearoot does not exist, please create and rerun this program"
exit 1
fi
# We're halfway there, check user and group
userpw="`egrep ${areaname}own /etc/passwd 2>/dev/null`"
if [ "x$userpw" = "x" ]; then
echo "User ${areaname}own does not exist, please create and rerun this program"
exit 1
fi
grppw="`egrep ${areaname}grp /etc/group 2>/dev/null`"
if [ "x$grppw" = "x" ]; then
echo "Group ${areaname}grp does not exist, please create and rerun this program"
exit 1
fi
# We can start creating our development tree
cd $arearoot
if [ -d $areaname ]; then
echo "Area $areaname already there, exit"
exit 0
else
mkdir $areaname
fi
cd $areaname
mkdir src include lib doc work
cd ..
# And set ownerships and protection
chown -R ${areaname}own $areaname
chgrp -R ${areaname}grp $areaname
chmod -R o-rwx $areaname
chmod -R g+rws $areaname
# Done
# End of File
|