# Guider Launcher
#
# Copyright (c) 2016-2022 Peace Lee <iipeace5@gmail.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.

# export CMDLINE for Guider #
CMDLINE=$0
export CMDLINE

# check PYTHON variable #
if [ $PYTHON ]; then
    $PYTHON -m guider "$@"
    exit 0
fi

# check python binaries #
for cmd in python3 python python2
do
    # check a python binary #
    RES=$(which $cmd 2> /dev/null)
    if [ $? -ne "0" ]; then
        continue;
    fi

    # launch Guider #
    PYTHON=$cmd
    $cmd -m guider "$@"

    # check result #
    if [ $? -eq "0" ]; then
        exit 0
    fi
done

# print error message #
if [ ! $PYTHON ]; then
    echo "[Error] failed to find python"
else
    echo "[Error] failed to find Guider module"
fi
exit 1
