#!/bin/sh
set -eu

PREFIX=${PREFIX:-/usr/local}
PACKAGE_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)

install -d "$PREFIX/bin" "$PREFIX/etc/nrt-cli" "$PREFIX/share/doc/nrt-cli"
install -m 0555 "$PACKAGE_DIR/bin/nrt-cli" "$PREFIX/bin/nrt-cli"
install -m 0555 "$PACKAGE_DIR/bin/nrt-menu" "$PREFIX/bin/nrt-menu"
install -m 0444 "$PACKAGE_DIR/etc/nrt-cli/config.example.ini" \
    "$PREFIX/etc/nrt-cli/config.example.ini"
install -m 0444 "$PACKAGE_DIR/README-DEPLOY.md" \
    "$PREFIX/share/doc/nrt-cli/README-DEPLOY.md"

if [ ! -e "$PREFIX/etc/nrt-cli/config.ini" ]; then
    install -m 0600 "$PACKAGE_DIR/etc/nrt-cli/config.example.ini" \
        "$PREFIX/etc/nrt-cli/config.ini"
    echo "Konfiguration angelegt: $PREFIX/etc/nrt-cli/config.ini"
else
    echo "Vorhandene Konfiguration beibehalten: $PREFIX/etc/nrt-cli/config.ini"
fi

echo "nrt-cli wurde unter $PREFIX installiert."
echo "Als Nächstes: $PREFIX/etc/nrt-cli/config.ini bearbeiten"
