#!/bin/sh
set -e

BIN=mautrix-mail
INSTALL_DIR=/usr/bin
CONFIG_DIR=/etc/mautrix-mail
PORT=29334

cd "$(dirname "$0")/.."
./build.sh

install -Dm755 "$BIN" "$INSTALL_DIR/$BIN"
install -d -m755 "$CONFIG_DIR"

if [ ! -f "$CONFIG_DIR/config.yaml" ]; then
    "$INSTALL_DIR/$BIN" --generate-example-config > "$CONFIG_DIR/config.yaml.example"
    echo "Generated example config at $CONFIG_DIR/config.yaml.example"
    echo "Copy it to $CONFIG_DIR/config.yaml and edit before use."
fi

echo "mautrix-mail installed to $INSTALL_DIR/$BIN"
echo "Config dir: $CONFIG_DIR"
echo "Appservice port: $PORT"
