#!/bin/bash
OPTIND=1
debug=0
while getopts ":d" opt; do
    case "$opt" in
    d)
        debug=1
        ;;
    esac
done

# When debuggin in QtCreator, don't change the working direcotry
# Needs to be set with -d in projects tab
dir=$( pwd )
if [ $debug -eq 0 ]; then
    dir=$(dirname "$(readlink -f $0)")
    cd "$dir"
fi

export QT_X11_NO_MITSHM=1
cmd="$dir/qt_host_installer"

if [[ $EUID -eq 0 ]]; then
    $cmd
elif command -v gksudo; then
    gksu -k $cmd
elif command -v kdesu; then
    kdesu $cmd
elif command -v xdg-su; then
    xdg-su -c $cmd
else
    sudo $cmd
fi
