#!/bin/sh

SHAREDIR=/usr/share/rmap

if test "$1" = "-sharedir" ; then
   SHAREDIR=$2
   echo "Share directory is $SHAREDIR"
fi

DUMP=`xrmap -rcfile none -dump stat`

if test "$DUMP" = "ABORT" ; then
  echo "The X display could not be open. Aborting."
  exit
fi

if test "$DUMP" = "JPD=31961 ARC=0" ; then
  echo "The vector map data file CIA_WDB2.jpd has already been upgraded."
  echo "Aborting the upgrade process."
  exit
fi

if test "$HOME" = "/root" ; then

mv -f $SHAREDIR/CIA_WDB2.jpd $SHAREDIR/CIA_WDB2_pre1990.jpd
xrmap -rcfile none +memory -mapfile $SHAREDIR/CIA_WDB2_pre1990.jpd \
-arc "read|WDB2_newlines" -dump "write|CIA_WDB2.jpd"
mv -f CIA_WDB2.jpd $SHAREDIR/CIA_WDB2.jpd
chmod a+r $SHAREDIR/CIA_WDB2.jpd

echo "New 'CIA_WDB2.jpd' file created and installed."
echo "(A copy of the old data has been kept under name 'CIA_WDB2_pre1990.jpd')."
exit

fi

xrmap -rcfile none +memory -mapfile \
-arc "read|WDB2_newlines" -dump "write|CIA_WDB2.jpd"

echo "A new 'CIA_WDB2.jpd' file has been created."
echo "Copy it to $SHAREDIR/CIA_WDB2.jpd, preferably after saving the old file."
