#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
basedir_win="$basedir"

case `uname -a` in
  *CYGWIN*|*MINGW*|*MSYS*)
    if command -v cygpath > /dev/null 2>&1; then
      basedir_win=`cygpath -w "$basedir"`
    fi
  ;;
  *WSL2*)
    if command -v wslpath > /dev/null 2>&1; then
      basedir_win="$(wslpath -w "$basedir" 2> /dev/null)"
      if [ $? -ne 0 ] || [ -z "$basedir_win" ]; then
        echo "Error: wslpath failed to convert path. WSL environment may be misconfigured." >&2
        exit 1
      fi
    fi
  ;;
esac

PROG_EXE="$basedir/node.exe"
if ! [ -x "$PROG_EXE" ]; then
  PROG_EXE="$basedir/node"
  if ! [ -x "$PROG_EXE" ]; then
    PROG_EXE=node
    if ! [ -x "$PROG_EXE" ]; then
      PROG_EXE=node.exe
    fi
  fi
fi

exec "$PROG_EXE"  "$basedir_win/../sshpk/bin/sshpk-conv" "$@"
