#!/bin/sh
# AACA / take so_cl home
# Source: https://github.com/akashrtd/so_cl
# Pinned revision: afc80d796931d5158ce2a22eb6e3509f05133603
# Requirements: Git and Go 1.24+. Linux or macOS; Windows users can use WSL.
# Review this file, then run it on YOUR machine with: sh <this-file>
# Creates a new checkout under ./aaca-workshop, or AACA_WORKSPACE.
# Does not use sudo, change your PATH, or start network services.
set -eu
command -v git >/dev/null 2>&1 || { echo "Git is required." >&2; exit 1; }
command -v go >/dev/null 2>&1 || { echo "go is required. See prerequisites above." >&2; exit 1; }
workshop_dir="${AACA_WORKSPACE:-$PWD/aaca-workshop}"
destination="$workshop_dir/so_cl"
if [ -e "$destination" ] || [ -L "$destination" ]; then
  echo "Refusing to overwrite $destination. Choose a new AACA_WORKSPACE." >&2
  exit 1
fi
mkdir -p "$workshop_dir"
git init "$destination"
cd "$destination"
git remote add origin https://github.com/akashrtd/so_cl.git
git fetch --depth 1 origin afc80d796931d5158ce2a22eb6e3509f05133603
git checkout --detach FETCH_HEAD
actual_revision="$(git rev-parse HEAD)"
[ "$actual_revision" = "afc80d796931d5158ce2a22eb6e3509f05133603" ] || { echo "Revision mismatch." >&2; exit 1; }
go build -o bin/so_cl .
printf '\nBuilt successfully in %s\n' "$destination"
printf 'Next, from that directory:\n  %s\n' 'SO_CL_ENABLE_LAN_DISCOVERY=false ./bin/so_cl'
