#!/bin/sh
set -e
SCRIPT_PATH="$0"
case "$SCRIPT_PATH" in
  /*) : ;;
  *) SCRIPT_PATH="$(pwd)/$SCRIPT_PATH" ;;
esac
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
cd "$SCRIPT_DIR"

if uname -m | grep -E -q 'aarch64|arm64'; then
  TOOLDIR=aarch64
else
  TOOLDIR=x86_64
fi

if [ "$(id -u)" -eq 0 ]; then
  exec ./tool/$TOOLDIR/Hiperiso2Disk.gtk3 "$@"
fi
if command -v pkexec >/dev/null 2>&1; then
  exec pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "$SCRIPT_DIR/tool/$TOOLDIR/Hiperiso2Disk.gtk3" "$@"
fi
if command -v sudo >/dev/null 2>&1; then
  exec sudo env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "$SCRIPT_DIR/tool/$TOOLDIR/Hiperiso2Disk.gtk3" "$@"
fi
printf '%s\n' 'Need pkexec or sudo to start the GTK GUI with root privileges.' >&2
exit 1
