
if [ $# -eq 1 ]
  then
    type=$1
  else
    type=all
fi

if [ ! -f central ]
   then
      central=/usr/mvw
   else
      central=`cat central`
fi

echo "\nAbout to de-install MultiView \c"

if [ $type = all ] || [ $type = save ]
  then
    echo "from the system\c"

    if [ $type = save ]
      then
        echo " (saving data files)\c"
    fi

    echo "."
fi

if [ $type = only ]
  then
    echo "installation work files."
fi

echo "  (Press RETURN)\c"
read wait

echo "========== De-Installation Starts ====================" >> errorlog
cls

if [ $type = save ]
  then
    echo "\nSaving MultiView data files.......................\c"

    if [ -f $central/data/* ]
      then
        mkdir data >> errorlog 2>&1

        if [ $? != 0 ]
          then
            echo "ERROR\n  Can't make data work directory."
            exit 1
        fi

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

        if [ $? != 0 ]
          then
            echo "ERROR\n  Can't copy data files to work directory."
            exit 1
        fi

    fi

    echo "OK"
fi

if [ $type != only ]
  then
    if [ -d $central ]
      then
        echo "\nRemoving MultiView central directory..............\c"
        rm -rf $central >> errorlog 2>&1

        if [ $? != 0 ]
          then
            echo "ERROR\n  Can't remove directories."
            exit 1
        fi

        echo "OK"
    fi

    if [ -f /usr/bin/mview ]
      then
        echo "Removing MultiView user level binaries............\c"
        rm -f /usr/bin/mview >> errorlog 2>&1

        if [ $? != 0 ]
          then
            echo "ERROR\n  Can't remove mview file."
            exit 1
        fi

        if [ -f /usr/bin/mvw_ixsrv ]
          then
            rm -f /usr/bin/mvw_ixsrv >> errorlog 2>&1

            if [ $? != 0 ]
              then
                echo "ERROR\n  Can't remove mvw_ixsrv file."
                exit 1
            fi

        fi

        echo "OK"

    fi

    echo

    de_edits

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

    echo

    de_mk_krn $type

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

    echo "Removing MultiView device nodes...................\c"

    if [ -c /dev/mvwdev ]
      then
        rm -f /dev/mvwdev >> errorlog 2>&1
      else
        rm -f /dev/mvw????? >> errorlog 2>&1
    fi

    echo "OK"
fi

if [ $type = only ] || [ $type = all ]
  then
    echo "\nRemoving MultiView installation work files........\c"

    if [ `pwd` = "/" ]
      then
        rm -rf tmp/*
      else
        rm -rf tmp
    fi

    if [ $? != 0 ]
      then
        echo "ERROR\n  Unable to remove tmp work directory."
        exit 1
    fi

    rm -f INSTALL DEINSTALL filelist central

    if [ $? != 0 ]
      then
        echo "ERROR\n  Unable to remove INSTALL file."
        exit 1
    fi

    echo "OK"
fi

echo "========== De-Installation Finished ====================" >> errorlog

exit 0
