#!/usr/bin/env sh

EXECUTABLE="./docs.brut.systems"

echo "Fetching latest version"
git pull origin master

if command -v go &> /dev/null; then
    echo "Recompiling..."

    go build -o "$EXECUTABLE" .

    if [ $? -ne 0 ]; then
        echo "Compilation failed!"
        exit 1
    fi
    echo "Compilation successful."
fi

if [ -x "$EXECUTABLE" ]; then
    echo "Starting $EXECUTABLE..."
    "$EXECUTABLE" "$@"
else
    echo "Error: Executable not found and Go is not installed to compile it."
    exit 1
fi
