#!/bin/sh

set -eu

CONFIG_DIR="${CONFIG_DIR:-/etc/geordi}"

. /usr/share/geordi/_functions
. /etc/geordi/scripts-config

trap 'cd "$(pwd)"' EXIT

RT=${RT:-"/var/lib/geordi/rt"}
AUTO_RECONNECT="${AUTO_RECONNECT:-0}"
ALWAYS_REFRESH_CHROOT="${ALWAYS_REFRESH_CHROOT:-1}"
DEBUG=${DEBUG:-0}
INFO=${INFO:-1}

cd "${CONFIG_DIR}"

Cond_refresh_chroot

if [ ! -d "${RT}" ]
then
	Echo_error "${RT} does not exist - run /usr/sbin/geordi-refresh-chroot"
	exit 1
fi

Echo_debug "Starting geordi-local"

if [ -x /usr/bin/rlwrap ]
then
	exec /usr/bin/rlwrap /usr/lib/geordi/geordi-local
else
	exec /usr/lib/geordi/geordi-local
fi
