#!/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

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