#!/bin/sh
#
#  Darryl Miles (G7LED) - 21/07/1994
#
#  
#  1.2 <user>:<host>:<chan>:<stime>:<etime>:<utime>:<opts>:<ptext>
#
#  /etc/conversd.inf (v1.2) -> /etc/convers/conversd.inf (v1.3)
#  1.3 <user>:<host>:<chan>:<stime>:<etime>:<ltime>:<utime>:<opts>:<ptext>
#
#  /etc/convers/conversd.inf (v1.3) -> /etc/convers/conversd.inf (v1.4)
#  1.4 <user>:<host>:<chan>:<stime>:<etime>:<ltime>:<utime>:<num>:<opts>:<ptext>
#

OLD=/etc/conversd.inf
NEW=/etc/convers/conversd.inf

TMP1=/tmp/cvt1.$$
TMP2=/tmp/cvt2.$$
TMP3=/tmp/cvt3.$$

if [ -f $NEW ]
then
   if head -n1 $NEW | grep -s "^G7LED_LNET 1.4$"
   then
      echo "New format v1.4 detected"
      echo "No reformatting needed, its already been done"
      exit 0
   fi
fi

if [ -f $NEW ]
then
   if head -n1 $NEW | grep -s "^G7LED_LNET 1.3$"
   then
      echo "New format v1.3 detected"
      tail +2 $NEW | cut -d':' -f1-7 >$TMP1
      tail +2 $NEW | cut -d':' -f9- >$TMP2
      echo -n >$TMP3
      for I in `cat $TMP1`
      do
         echo "$I:0:LN$" >>$TMP3
      done
      echo "G7LED_LNET 1.4" >$NEW
      paste -d':' $TMP3 $TMP2 >>$NEW
      echo "Formated for version 1.4"
      rm -f $TMP1 $TMP2 $TMP3
      exit 0
   fi
fi

if [ -f $OLD ]
then
   if [ ! -d /etc/convers ]
   then
      mkdir /etc/convers
      echo "Making dir /etc/convers"
   fi

   echo "Old format pre v1.3 detected"
   cut -d':' -f1-5 $OLD >$TMP1
   cut -d':' -f6- $OLD >$TMP2
   echo -n >$TMP3
   for I in `cat $TMP1`
   do
      echo "$I:0" >>$TMP3
   done
   echo "G7LED_LNET 1.3" >$NEW
   paste -d':' $TMP3 $TMP2 >>$NEW
   echo "Reformatted to /etc/convers/conversd.inf, please delete old /etc/conversd.inf"
   rm -f $TMP1 $TMP2 $TMP3
   exit 0
fi

echo "No convertion needed."
