#!/bin/sh
set -eux

TLD="$(cat aux/tld.txt)"

PACKAGE="$(basename "$PWD")"
__ENABLE_CI__ LOGS_DIR="/opt/ci/$PACKAGE/logs"
REMOTE_GIT_DIR="/srv/git/$PACKAGE.git"

DESCRIPTION="$(mktemp)"
if [ -f description ]
then
	cp description "$DESCRIPTION"
else
	git config euandreh.description > "$DESCRIPTION"
fi

scp "$DESCRIPTION" "$TLD:$REMOTE_GIT_DIR/description"
__ENABLE_CI__ ssh "$TLD" mkdir -p "$LOGS_DIR"
__ENABLE_CI__ scp aux/ci/ci-build.sh         "$TLD:$(dirname "$LOGS_DIR")/ci-build.sh"
__ENABLE_CI__ scp aux/ci/git-post-receive.sh "$TLD:$REMOTE_GIT_DIR/hooks/post-receive"
