#!/usr/bin/env sh
# shellcheck disable=SC1073

command_exists() {
  command -v "$@" > /dev/null 2>&1
}

###############################################################
# Utility functions that will be called only once, script wide
###############################################################
get_sh() {
  user="$(id -un 2>/dev/null || true)"
  sh_c='sh -c'
  if [ "$user" != 'root' ]; then
    if command_exists sudo; then
      sh_c='sudo -E sh -c'
    elif command_exists su; then
      sh_c='su -c'
    else
cat >&2 <<EOF
Error: this installer needs the ability to run commands as root.
Neither the 'sudo' nor 'su' command was found on the host, interrupting.
EOF
exit 1
    fi
  fi
}
# Global shell variable used by all functions
get_sh #1>/dev/null

$sh_c "/opt/onedata/onedatify/onedatify.sh $*"
