:
#
# aodinst (Online Diagnostics)
#

# check for superuser id

if [ `logname` != "root" ]
then
	echo "Must be super-user to execute online diagnostics installation"
	exit 2
fi

echo "\n################################################################################"
echo "   		    Online Diagnostics Installation Procedure"

################################################################################

#
# UUCP initialization section
#
echo "\n################################################################################"
echo "\nInitializing \"UUCP\" files for Remote System notification"
# change directory to uucp commands directory
cd /usr/lib/uucp
# check for existence of required files
# change directory to commands default
cd /usr/bin
for file in uucp uulog uuname uupick uustat uuto uux
do
	if [ ! -x $file ]
	then
		echo "\nWARNING: $file missing from, or not executable in, /usr/lib/uucp directory"
		echo "	check to be certain that UUCP has been installed on this system"
	fi
done
# change directory to uucp commands directory
cd /usr/lib/uucp
for file in uucheck uucico uuclean uugetty uusched uuxqt uutry
do
	if [ ! -x $file ]
	then
		echo "\nWARNING: $file missing from, or not executable in, /usr/lib/uucp directory;"
		echo "	check to be certain that UUCP has been installed on this system"
	fi
done
for file in Devices Permissions Systems
do
	if [ ! -f $file ]
	then
		echo "\nWARNING: $file missing from /usr/lib/uucp directory"
		echo "	check to be certain that UUCP has been installed on this system"
	fi
done
# set up temporary file aliases
TEMP="$$.edtmp"
# set clean-up action upon abort or premature exit
TRAPMSG="Aborting On-Line Diagnostics Installation"
trap 'rm -f $TEMP > /dev/null;echo "\n$TRAPMSG\n";trap 0 2 3 15;exit' 0 2 3 15

# set up aliases for uu command execution
# Systems file

if [ ! -f /usr/lib/aod.remsys ]
then
	echo "\nRemote System configuration file missing (aod.remsys) ...creating default"
	cat > /usr/lib/aod.remsys << ?
AltosOnline|9=xxx-xxxx|Any|1200|"" \d\d\d login: nuucp
?
fi

# Devices file

if [ ! -f /usr/lib/aod.remdev ]
then
	echo "\nRemote System configuration file missing (aod.remdev) ...creating default"
	cat > /usr/lib/aod.remdev << ?
ACU|tty1A|-|1200|/usr/lib/uucp/dialHA12
?
fi

# Permissions file

if [ ! -f /usr/lib/aod.remperm ]
then
	echo "\nRemote System configuration file missing (aod.remperm) ...creating default"
	cat > /usr/lib/aod.remperm << ?
REMSYSTEM|nuucp|rmail:rnews:uucp|/usr/spool/uucppublic:/usr/tmp:/tmp|/usr/spool/uucppublic:/usr/tmp:/tmp|yes|yes
?
fi

# aod.remsys file
REMSYSTEM=`awk 'BEGIN{FS="|"}{print $1}' /usr/lib/aod.remsys`
REMNUMBER=`awk 'BEGIN{FS="|"}{print $2}' /usr/lib/aod.remsys`
REMHOURS=`awk 'BEGIN{FS="|"}{print $3}' /usr/lib/aod.remsys`
REMSPEED=`awk 'BEGIN{FS="|"}{print $4}' /usr/lib/aod.remsys`
REMEXSEND=`awk 'BEGIN{FS="|"}{print $5}' /usr/lib/aod.remsys`
THISSYSTEM=`uuname -l`

# aod.remdev file
DEVICETYPE=`awk 'BEGIN{FS="|"}{print $1}' /usr/lib/aod.remdev`
TTYLINE=`awk 'BEGIN{FS="|"}{print $2}' /usr/lib/aod.remdev`
DIALERLINE=`awk 'BEGIN{FS="|"}{print $3}' /usr/lib/aod.remdev`
SPEED=`awk 'BEGIN{FS="|"}{print $4}' /usr/lib/aod.remdev`
DIALER=`awk 'BEGIN{FS="|"}{print $5}' /usr/lib/aod.remdev`
TOKEN=`awk 'BEGIN{FS="|"}{print $6}' /usr/lib/aod.remdev`

# aod.remperm
MACHINE=`awk 'BEGIN{FS="|"}{print $1}' /usr/lib/aod.remperm`
LOGNAME=`awk 'BEGIN{FS="|"}{print $2}' /usr/lib/aod.remperm`
COMMANDS=`awk 'BEGIN{FS="|"}{print $3}' /usr/lib/aod.remperm`
READ=`awk 'BEGIN{FS="|"}{print $4}' /usr/lib/aod.remperm`
WRITE=`awk 'BEGIN{FS="|"}{print $5}' /usr/lib/aod.remperm`
SEND=`awk 'BEGIN{FS="|"}{print $6}' /usr/lib/aod.remperm`
REQ=`awk 'BEGIN{FS="|"}{print $7}' /usr/lib/aod.remperm`

echo "\nConsult your Altos UNIX System V/386 System Administrator's Reference\nfor information on UUCP."

ACU=`grep ACU /usr/lib/uucp/Devices | awk '{if($1=="ACU")printf("%s\n",$0);}'`
if [ ! "$ACU" ]
then
        echo "$DEVICETYPE $TTYLINE $DIALERLINE $SPEED $DIALER $TOKEN" >> /usr/lib/uucp/Devices
fi

awk "{if(\$1!=\""$REMSYSTEM"\")print \$0}" /usr/lib/uucp/Systems > $TEMP

echo "$REMSYSTEM $REMHOURS ACU $REMSPEED $REMNUMBER $REMEXSEND" | \
cat $TEMP - > /usr/lib/uucp/Systems
rm $TEMP


SYSNAME=`grep -c $MACHINE /usr/lib/uucp/Permissions`

# write permission info to /usr/lib/uucp/Permissions
if [ "$SYSNAME" -eq 0 ]
then
	echo "MACHINE=REMSYSTEM LOGNAME=nuucp COMMANDS=rmail:rnews:uucp READ=/usr/spool/uucppublic:/usr/tmp:/tmp WRITE=/usr/spool/uucppublic:/usr/tmp:/tmp SENDFILES=yes REQUEST=yes" >> /usr/lib/uucp/Permissions
fi


################################################################################

#
# Threshold Settings initialization section
#
echo "\n################################################################################"
echo "\nInitializing and/or Modifying Threshold Detection Settings\n"
#define file equates to shorten shell script lines
xfile=/usr/lib/err.xref
tfile=/usr/lib/err.thresh

# make default cross-reference file
/usr/lib/aodmkxref -h
RETVAL=$?
if [ $RETVAL -ne 0 ]
then
	echo "aodinst: error creating online diagnostic cross-reference file"
	exit `expr $RETVAL + 8`
fi

# turn on flag for progress messages
HEADINGS="on"

# read cross-reference data
.   /usr/lib/aodrdset

# thresholds settings file does not exist; create default
# via script file executed within this shell process
.   /usr/lib/aodsetdef

# now write these defaults to the threshold file
echo "Saving error detection thresholds file...\c"

for device in hd fd tp mdc sio krn mis
do
	eval fieldlist=$"$device""fields"
	for fieldtype in $fieldlist
	do
		eval fieldname=$""$device"val"$fieldtype""
		eval echo "$device""$fieldname" $""$device""$fieldname"" $""$device""$fieldname"ACT" >> /usr/lib/err.thresh
	done
done
echo "done"
echo "\nThe Online Diagnostics error threshold settings have been preset to"
echo "default levels by this installation.  You may modify these thresholds"
echo "or the action to be taken when threshold level error activity occurs"
echo "(i.e. whether to notify Altos' Remote Diagnostics Center) by running the"
echo "Online Diagnostics Threshold Setting Routine \`setthresh'."

################################################################################

#
# Cron Table initialization section
#
echo "\n################################################################################"
echo "\nInitializing and/or Modifying Online Monitor Cron Scheduling Settings"
# in case of premature exit, remove temporary files
trap 'rm -f $$.cron* > /dev/null;echo "\n$TRAPMSG\n";trap 0 2 3 15;exit' 0 2 3 15

# let user know there will be a short delay
echo "\nExtracting cron table information; please be patient...\c"

# extract non-aodmon portion of crontab table into separate files
# (ignore any existing aodmon references; strip them out with `grep -v')
su root -c "crontab -l > $$.cronlist"
grep -v "aodmon" $$.cronlist > $$.cronrem

# let user know that we're done getting the info now
echo "done"

cronline="59 23 * * * /usr/lib/aodmon 2>&1 > /dev/null"

# make changes to cron table
echo "# aodmon cron editor entry `date`" >> $$.cronrem
# add cron table entry
echo "$cronline" >> $$.cronrem

# replace pre-existing cron table with this one
echo "\nnew cron table :"
echo;cat $$.cronrem;echo
su root -c "crontab $$.cronrem"
echo "cron table updated";echo
echo "The Online Diagnostics Monitor Routine \`aodmon' is currently scheduled"
echo "to be run every day at 11:59 P.M.  To modify this schedule, you may either"
echo "extract the cron table entry, edit it directly, and reschedule it via the"
echo "crontab and editor functions, or you may run the Online Diagnostics Cron"
echo "Table Editor Routine \`aodcron' for a menu-driven schedule modifier."

# prepare to exit; clean-up temp files
rm -f $$.cron*

echo "\nOnline Diagnostics Installation Procedure Completed\n"
trap 0 2 3 15
# done, so get out of here
exit 0
