#!/bin/bash

# Permissions: root:root 755

_PYTHON=$(which python3)
python3 -c "import migasfree_client" 2&> /dev/null
if [ $? -ne 0 ]
then
    _PYTHON=$(which python2)
fi

_CMD=$(cat << EOF
import os
import webbrowser

from migasfree_client.utils import get_config, get_hardware_uuid, get_mfc_computer_name
from migasfree_client import settings

if __name__ == '__main__':
    config = get_config(settings.CONF_FILE, 'client')
    protocol = 'https' if os.path.isfile(settings.CERT_FILE) else 'http'

    webbrowser.open(
        '{0}://{1}/computer/{2}/label/?name={3}'.format(
            protocol,
            config.get('server', 'localhost'),
            get_hardware_uuid(),
            get_mfc_computer_name()
        )
    )
EOF
)

$_PYTHON -c "$_CMD" "$@"
