
cls

echo "\nChecking existence of system files................\c"

for file in `cat filelist`
  do
    if [ ! -f $file ]
      then
        echo "ERROR\n  $file missing."
        exit 1
    fi
  done

echo "OK"

check

if [ $? != 0 ]
  then
    exit 1
fi

echo "\nPlease enter the MultiView central directory that you wish to use:"
echo "  (default: /usr/mvw)"
getdir
central=`cat central`

chkexist

if [ $? != 0 ]
  then
    echo "\nMultiView is already installed on this machine."
    echo "\nIf you continue from this point, all information except that"
    echo "contained in the MultiView data directory will be removed."
    echo "\nIf this is also an update to a later version, your MultiView"
    echo "system files (wmgr.rc, mvw_termcap, etc.) may become invalid."
    echo "\nDo you wish to continue (y/n)?\n"

    chkyn

    if [ $? != 0 ]
      then
        echo "\nExiting at user request."
        exit 1
    fi

    deinstall save

    if [ $? != 0 ]
      then
        exit 2
    fi

    cls
fi

echo "\nCreating MultiView directory structure............\c"

mkdir $central >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't make $central."
    exit 3
fi

mkdir $central/bin >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't make $central/bin."
    exit 3
fi

mkdir $central/data >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't make $central/data."
    exit 3
fi

chmod 777 $central/data >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't change permissions on $central/data."
    exit 3
fi

mkdir $central/help >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't make $central/help."
    exit 3
fi

echo "OK"

if [ -d data ]
  then
    echo "Moving saved data into position...................\c"

    mv data/* $central/data >> errorlog 2>&1

    if [ $? != 0 ]
      then
        echo "ERROR\n  Can't move files to $central/data."
        exit 3
    fi

    rm -rf data >> errorlog 2>&1

    if [ $? != 0 ]
      then
        echo "ERROR\n  Can't remove work data files."
        exit 3
    fi

    echo "OK"
fi

echo "Moving MultiView binary files into position.......\c"

mv tmp/usr/mvw/bin/* $central/bin >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't move files to $central/bin."
    exit 3
fi

ln $central/bin/mvw_Scratchpad $central/bin/mvw_Clipboard >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't link Scratchpad to Clipboard."
    exit 3
fi

ln $central/bin/mvw_paddress $central/bin/mvw_coaddress >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't link Address Book."
    exit 3
fi

ln $central/bin/mvw_pfiling $central/bin/mvw_cofiling >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't link Filer."
    exit 3
fi

ln $central/bin/mvw_ptel $central/bin/mvw_cotel >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't link Telephone Book."
    exit 3
fi

echo "OK"

echo "Moving MultiView help files into position.........\c"

mv tmp/usr/mvw/help/* $central/help >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't move help files to $central/help."
    exit 3
fi

echo "OK"

rm -rf tmp/usr/mvw/bin tmp/usr/mvw/help >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR: Unable to remove MultiView directories from work area."
    exit 3
fi

echo "Moving MultiView system files into position.......\c"

mv tmp/usr/mvw/* $central >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't move .rc files to $central."
    exit 3
fi

echo "OK"

echo "Moving MultiView user-level files into position...\c"

mv tmp/usr/bin/* /usr/bin >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't move mview to /usr/bin."
    exit 3
fi

echo "OK"

edits

if [ $? != 0 ]
  then
    exit 3
fi

mk_krn

if [ $? != 0 ]
  then
    exit 3
fi

echo "Creating MultiView device node....................\c"

mvwc=`cat device`

/etc/mknod /dev/mvwdev c $mvwc 255 >> errorlog 2>&1

if [ $? != 0 ]
  then
    echo "ERROR\n  Can't mknod /dev/mvwdev."
    exit 3
fi

echo "OK"

deinstall only

rm -f errorlog central device filelist

echo -n "Do you have WordPerfect installed on this system? <y|n> "
read ans
if [ $ans != "y" ]
then
 	rm $central/wpterm.???
else
	echo " A copy of WordPerfect termcaps is left for you in $central"
fi
sleep 2

exit 0
