#! /bin/csh
#
# installation script for Pirate BBS.
#
#
# just in case something goes wrong, make a backup of the passwd file
#

make install
cp /etc/passwd passwd.backup

set bbshome = `./bin/passwdent bbs homedir`

if ( $bbshome == "" ) then
    set bbshome = /a/r/g/v
    echo ERROR: CHECK PASSWD ENTRY, is it bbs\?
    exit -1
endif

# Make all the directories required
echo making directories
mkdir ~bbs
mkdir ~bbs/bin
mkdir ~bbs/lib
mkdir ~bbs/ftp
mkdir ~bbs/ftp/files
mkdir ~bbs/ftp/files/source
mkdir ~bbs/etc
mkdir ~bbs/boards
mkdir ~bbs/dev
mkdir ~bbs/mail
mkdir ~bbs/tmp
mkdir ~bbs/usr
mkdir ~bbs/usr/lib

# Copy Welcome and copyright notices to home directory
echo Copying Welcome message and copyright notices
cd install.files
cp COPYING Welcome Version.Info BoardName ~bbs

cd ..
# Make zero device in dev
if (-e /dev/zero ) then
	echo Making device zero
	mknod ~bbs/dev/zero c 3 12
endif

# Set Up etc directory
echo setting up etc directory
cp /etc/termcap ~bbs/etc
cp /etc/group ~bbs/etc
cp /etc/hosts ~bbs/etc
echo "root:*:0:1:Operator:/:/bin/csh" > ~bbs/etc/passwd
echo -n "bbs:*:" >> ~bbs/etc/passwd
echo -n `./bin/passwdent bbs uid`: >> ~bbs/etc/passwd
echo -n `./bin/passwdent bbs gid`: >> ~bbs/etc/passwd
echo -n "Bulletin Board Software:/:/bin/bbs" >> ~bbs/etc/passwd
chmod a-w ~bbs/etc/passwd
chmod a-w ~bbs/etc/group
chmod a-w ~bbs/etc/termcap

# set up usr directory
# this includes timezone stuff and shared library stuff
echo setting up usr directory
if ( -e /usr/share/lib/zoneinfo ) then
 echo Copying zoneinfo stuff
 mkdir ~bbs/usr/share
 mkdir ~bbs/usr/share/lib
 (cd  /usr/share/lib;tar cf - zoneinfo) | (cd ~bbs/usr/share/lib; tar xf -)
endif
# The following lines are supposed to copy the necessary files for shared
# libraries on Sun Systems
if ( -f /usr/lib/ld.so ) then
	echo installing shared libraries
	cp /usr/lib/ld.so ~bbs/usr/lib
	cp /usr/lib/libc.so.* ~bbs/usr/lib
	if( -f /usr/lib/libdl.so.1.0 ) then
		cp /usr/lib/libdl.so.1.0 ~bbs/usr/lib
	endif
endif

# set up the bin directory
echo setting up binaries
cp bin/* ~bbs/bin
# The chroot app runs setuid.
chmod 4755 ~bbs/bin/bbsrf
chown root ~bbs/bin/bbsrf
cp /bin/sh ~bbs/bin
cp /bin/csh ~bbs/bin
cp /bin/mv ~bbs/bin
cp /bin/ls ~bbs/bin
cp /bin/rm ~bbs/bin
cp /bin/stty ~bbs/bin
cp /bin/mkdir ~bbs/bin
cp /bin/cp ~bbs/bin
cp /usr/ucb/vi ~bbs/bin
cp /usr/ucb/reset ~bbs/bin

# set up home directory and ownerships
echo Setting ownerships and permissions
echo -n > ~bbs/.hushlogin
cp install.files/dotcshrc ~bbs/.cshrc
cp install.files/dotlogin ~bbs/.login
cp install.files/more.help ~bbs/usr/lib/more.help
chown bbs ~bbs
chown bbs ~bbs/.hushlogin
chown bbs ~bbs/.cshrc
chown bbs ~bbs/boards
chown bbs ~bbs/mail
chown bbs ~bbs/Welcome
chown -R bbs ~bbs/ftp
chown bbs ~bbs/tmp
chmod 770 ~bbs



