:
# @(#)	Install v1.0		installation script for Magpie/Xenix
#	By Steve Manes, with apologies.
#

PFILE=/etc/passwd
GFILE=/etc/group
TARFILE=magpie.tar

# make certain we're the big cheese here for setuid
if [ "`logname`" != "root" ]
   then	echo "Install must be run as 'root'"
	exit 1
fi

# make sure magpie.tar is here
if [ ! -r "./$TARFILE" ]
   then	echo "\nOops... 'magpie.tar' must be in the current directory."
	echo "I'm lazy.  Please move it here and try again.\n"
	exit 1
fi   

echo "\n\n\n\n
			Magpie Install v1.0


	This script will auto-install MAGPIE/Xenix.

	Please follow these directions carefully to create the required
	directories and install MAGPIE.

	Questions which appear with a [xxx] are the default.  Hit a
	RETURN if you wish to use the default answer.

	
	==> Do you wish to install MAGPIE now (y/n) [no] ? \c"

read YESNO
if [ "$YESNO" != "y" -a "$YESNO" != "yes" ]
   then exit 1
fi

# get destination
echo "\n\n\n\n
	MAGPIE requires its own directory for the MAGPIE executables,
	datafiles and as root for other required subdirectories.  I
	will create this directory for you.  I need to know where you
	want the /magpie directory to reside.

	
	==> Where do you want MAGPIE to reside [/usr] ? \c"

read MAGDIR
if [ "$MAGDIR" = "" ]
   then	MAGDIR=/usr
fi
MAGDIR=${MAGDIR}/magpie

# check for 'bbs' and 'magnet' group
echo "\n\n\n\n
	MAGPIE needs to have access to two /etc/passwd usernames and, for
	file security purposes, one /etc/group group.  The first is the
	Xenix username that people will use at the 'login:' prompt.
	By convention, this name will be 'bbs'.
	
	The second is the mandatory username 'magnet' for UUCP and MagNet.  
	Both of these usernames should be reserved exclusively for use
	by MAGPIE.
	
	Finally, we need a group reserved exclusively by MAGPIE.  This
	may also be 'bbs'.

	I will create these names for you if they don't already exist.
	If you choose to create another login username, make sure it's legal!


	==> What /etc/group name do you wish to use for MAGPIE [bbs] \c"
read GROUP
if [ "$GROUP" = "" ]
   then GROUP=bbs
fi
if [ -n "`egrep \^$GROUP: $GFILE`" ]
   then 
	echo "\n\n
	I see that you already have a '$GROUP' in your $GFILE.
	Providing that no one (other than 'root') has shell access with
	this group name, I'll use it.  If this is NOT the case and people
	may 'newgrp' to '$GROUP' you will have a serious security problem
	with MAGPIE.
	

	==> Should I use '$GROUP' [no] ? \c"
	read YESNO
	if [ "$YESNO" != "y" -a "$YESNO" != "yes" ]
	   then exit 1
	fi
	GROUPNUM="`awk '{ FS = ":" } /'$GROUP'/ { print $3 }' $GFILE`"
	echo "\n\tOkay, using group $GROUPNUM for '$GROUP'\n"
else
	GROUPNUM="0"
fi

echo "	==> Enter login username for MAGPIE users [bbs] \c"
read BBS
if [ "$BBS" = "" ]
   then BBS=bbs
fi

if [ -n "`egrep \^$BBS: $PFILE`" ]
   then	
	echo "\n\n
	Ah, I see you've already got a '$BBS' in your $PFILE.
	I could grab it for myself but there's a chance you may not
	want me to.  So either delete that name or choose another and
	then run me again."
	exit 1
fi	

# get next available group # and create entry
if [ "$GROUPNUM" = "0" ]
   then	echo "\n\n\tChecking $GFILE..."
   	GROUPNUM="`awk 'BEGIN { FS = ":" ; maxnum = 50 }
   		{ if ($3 > maxnum) { maxnum = $3 } }
		END { print maxnum+1 }' $GFILE`"
	echo "\n
	The next available group number is $GROUPNUM.
	
	If you hit ENTER at the prompt, I'll create a new group '$GROUP'
	with group number $GROUPNUM.  Otherwise, enter another group
	number (but check to make sure you don't already have that group
	number defined in $GFILE).
	

	==> New group number for '$GROUP' [${GROUPNUM}] \c"
	read RESPONSE
	if [ "$RESPONSE" != "" -a "$RESPONSE" != "$GROUPNUM" ]
	   then	GROUPNUM=$RESPONSE
	fi
	echo "\n\tCreating new group '$GROUP' for group number $GROUPNUM..."
	chmod 644 $GFILE
	echo "$GROUP::$GROUPNUM:$BBS,magnet" >> $GFILE
	chmod 444 $GFILE
fi

# get next available user number in /etc/passwd for Magpie login
echo "\n\tChecking $PFILE..."
PWDNUM="`awk 'BEGIN { FS = ":" ; maxnum = 200 }
   	{ if ($3 > maxnum) { maxnum = $3 } }
	END { print maxnum+1 }' $PFILE`"
echo "\n
	Next available $PFILE user number is $PWDNUM.

	If you hit ENTER at the prompt, I'll create user '$BBS' with
	user number $PWDNUM.  Otherwise, enter a user number that isn't
	already defined in $PFILE.

	New user number for $BBS [${PWDNUM}] \c"
read RESPONSE
if [ "$RESPONSE" != "" -a "$RESPONSE" != "$PWDNUM" ]
   then	PWDNUM=$RESPONSE
fi

# set /etc/passwd up for writing and add a new entry
chmod 644 $PFILE
echo "$BBS::$PWDNUM:$GROUPNUM:Magpie Login:$MAGDIR:${MAGDIR}/mp" >> $PFILE

# get user number for 'magnet'
if [ -n "`egrep \^magnet: $PFILE`" ]
   then echo "\n\n
	I see that you've already got 'magnet' in your $PFILE so we'll
	leave it alone.  Again, make sure that no one else has access to
	it."

else	PWDNUM="`awk 'BEGIN { FS = ":" ; maxnum = 200 }
   		{ if ($3 > maxnum) { maxnum = $3 } }
		END { print maxnum+1 }' $PFILE`"
	echo "\n\n
		Now we need to create a pseudo-user for MAGPIE UUCP mail
		and for MagNet.  The next available $PFILE user number
		is $PWDNUM.

		If you hit ENTER at the prompt, I'll create user 'magnet' with
		user number $PWDNUM.  Otherwise, enter a user number that isn't
		already defined in $PFILE.

		New user number for 'magnet' [${PWDNUM}] \c"
	read RESPONSE
	if [ "$RESPONSE" != "" -a "$RESPONSE" != "$PWDNUM" ]
	   then	PWDNUM=$RESPONSE
	fi
	echo "magnet:NOLOGIN:$PWDNUM:$GROUPNUM:MagNet Pseudouser:$MAGDIR:/bin/sh"  >> $PFILE

fi
chmod 444 $PFILE

#	Create the subdirectories
#	Unpack Magpie files to target directory
#
echo "\n\n\tCreating MAGPIE subdirectories..."
mkdir $MAGDIR
chown $BBS $MAGDIR
chgrp $GROUP $MAGDIR
mkdir $MAGDIR/files
mkdir $MAGDIR/files/editors
mkdir $MAGDIR/files/msdos
mkdir $MAGDIR/files/text
mkdir $MAGDIR/files/unix
mkdir $MAGDIR/files/comm
mkdir $MAGDIR/files/arcers
mkdir $MAGDIR/uploads
mkdir $MAGDIR/arctemp
mkdir $MAGDIR/mag
mkdir $MAGDIR/utils
mkdir $MAGDIR/doc
mkdir $MAGDIR/magnet
mkdir $MAGDIR/magnet/in
mkdir $MAGDIR/magnet/out
mkdir $MAGDIR/chatfiles

echo "\n\tExtracting files..."
mv $TARFILE $MAGDIR
cd $MAGDIR
tar xvf $TARFILE

# create Paths file
echo "${MAGDIR}/editors\n${MAGDIR}/msdos\n${MAGDIR}/text\n${MAGDIR}/unix\
\n${MAGDIR}/comm\n${MAGDIR}/arcers\n" > ${MAGDIR}/files/Paths

# change permissions
mv *.mag $MAGDIR/mag
mv *.Doc $MAGDIR/doc
touch $MAGDIR/files/Download.DB
chown $BBS $MAGDIR/*
chgrp $GROUP $MAGDIR/*
chmod 775 $MAGDIR/*
chown $BBS $MAGDIR/files/*
chgrp $GROUP $MAGDIR/files/*
chmod 775 $MAGDIR/files/*
chown $BBS $MAGDIR/magnet/*
chgrp $GROUP $MAGDIR/magnet/*
chmod 775 $MAGDIR/magnet/*
chown $BBS $MAGDIR/mag/*
chgrp $GROUP $MAGDIR/mag/*
chmod 660 *.DB *.LKP Exec Boards 
chmod 6711 mp pack usedit cfedit packuser
ln $MAGDIR/xfer $MAGDIR/send
ln $MAGDIR/xfer $MAGDIR/recv

echo "\n\nMaking protected vi subdirectories (ignore any link warnings)...\n"
chmod 755 rvi_install
./rvi_install

echo "\n\n
	Now, a few questions about your local setup.  What will be the
	MAGPIE username of the system's SYSOP (maximum 20 characters)?
	
	==> System SYSOP: \c"
read SYSOP

echo "\n\n
	Most sysops like to give their BBSes a name, i.e. \"The MIDI Inn\"
 	or \"The Bird's Nest\".  What name would you like to give your
 	BBS?
 	
 	==> BBS name: \c"
read BBSNAME

${MAGDIR}/cfedit -s"$SYSOP" -n"$BBSNAME" -h$MAGDIR -u${MAGDIR}/uploads \
-a${MAGDIR}/arctemp -w

echo "\n\nWelcome to $BBSNAME!" > ${MAGDIR}/mag/signon.mag
echo "\n\nThanks for calling $BBSNAME!" > ${MAGDIR}/mag/logoff.mag

echo "\n\n\n\n
	All done!

	You will probably want to set up your gettydefs so that the
	the string \"For BBS, type $BBS\" appears at the 'login:' prompt.
	
	In addition, you should modify the script files 'umail' and
	'getumail' to fit your local system environment.

	It's recommended that you also get copies of Rahul Dhesi's 'zoo'
	and a S.E.A.-compatible 'arc' and place both in $MAGDIR.  Both
	may be downloaded from Magpie-HQ, the MAGPIE support board, at
	(212)420-0527.

	You may login now by cd'ing to $MAGDIR and typing 'mp'.  Login
	as \"SYSOP\" with the password \" local\" (note the leading space
	in the password).
	
	You may create your own username by logging into Magpie, creating
	a new name and modifying its permissions with 'usedit'.
	

	Hit any key to continue... \c"
read YESNO

echo "\n\n\n\n\n
	Please read the MAGPIE manual carefully!  You cannot run
	this software effectively without it.  If you are new to
	MAGPIE as a user, by all means, study the on-line TUTORIAL.

	Finally \"The Pitch\": Magpie is USER-SUPPORTED SOFTWARE.
	Aside from being the most sophisticated BBS available for
	Unix and Xenix you also now have two very convenient stand-alone
	utilities -- the 'chat' Multichat program and 'recv/send',
	an Xmodem/Ymodem/Batch file transfer program.
	
	Three years of hard effort have gone into the development of
	MAGPIE and the development continues.  If you find MAGPIE
	worthwhile and decide to use it, a contribution of $75 would
	be humbley appreciated.  This will also register your software
	for technical assistance on the Magpie-HQ SYSOP SUPPORT BOARD
	as well as allow your board to participate in the upcoming
	MagNet BBS network.

	Commercial users and those sysops charging users fees in excess
	of $25/year are required to purchase a site license for $350.
	Sorry... Magpie deserves to share the wealth if there's wealth
	to be shared.
	
	Hit any key to continue... \c"
read YESNO

echo "\n\n\n\n\n
	Please mail contributions and comments to:
	
		Steve Manes
		Roxy Recorders, Inc.
		648 Broadway, 3rd floor
		New York, New York 10012


	Good luck with MAGPIE and happy BBSing!
	

	Steve Manes	3/3/88

	UUCP: {backbones}!{cmcl2|cucard|rutgers}!hombre!magpie!manes
	SmartMail: manes@magpie.MASA.COM
	Magpie-HQ: (212)420-0527
"
# end of script
