#!/bin/sh
#--
# Create symbolic links from some /etc files to the Windows equivalents
#--

FILES="hosts protocols services networks"

OSNAME="`/bin/uname -s`"
WINHOME="`/bin/cygpath -W`"

case "$OSNAME" in
  CYGWIN_NT*) WINETC="$WINHOME/system32/drivers/etc" ;;
  CYGWIN_9*|CYGWIN_ME*) WINETC="$WINHOME" ;;
  *) 
    echo "Unknown system type $OSNAME; exiting" >&2
    exit 0
  ;;
esac

WINETC="$(/bin/cygpath -u "$(/bin/cygpath -w -l "$WINETC")")"
if [ ! -d "$WINETC" ]
then
  echo "Directory $WINETC does not exist; exiting" >&2
  echo "If directory name is garbage, update cygpath to 1.22 or later" >&2
  exit 0
fi

for FILE in $FILES
do
  if [ ! -e "/etc/$FILE" -a ! -L "/etc/$FILE" ]
  then
    # Windows only uses the first 8 characters
    WFILE="$WINETC/`expr substr "$FILE" 1 8`"
    WFILE="$(/bin/cygpath -u "$(/bin/cygpath -w -l "$WFILE")")"
    /bin/ln -s -v "$WFILE" "/etc/$FILE"
  fi
done



