#!/bin/sh
# Retain the established setup shortcuts and delegate management commands.
case "$1" in
    connect|reconfigure)
        if [ "$#" != 1 ]; then
            echo 'Usage: turnkey connect|reconfigure' >&2
            exit 2
        fi
        if [ "$(id -u)" != 0 ]; then
            echo "Run: sudo turnkey $1" >&2
            exit 1
        fi
        case "$1" in
            connect) exec /usr/lib/inithooks/bin/hubservices.py --relink ;;
            reconfigure) exec /usr/lib/inithooks/bin/turnkey-reconfigure ;;
        esac
        ;;
    *)
        if [ -x /usr/lib/confconsole/turnkey.py ]; then
            exec /usr/lib/confconsole/turnkey.py "$@"
        fi
        echo 'TurnKey management console is unavailable. Install or update the confconsole package.' >&2
        exit 1
        ;;
esac
