#!/bin/sh
set -eu

student_id="${1:-${STUDENT_ID:-}}"
if [ "${#student_id}" -ne 8 ]; then
  printf '%s\n' "Usage: $0 STUDENT_ID (8 digits)" >&2
  exit 2
fi

case "$student_id" in
  *[!0-9]*)
    printf '%s\n' "Student ID must contain 8 digits." >&2
    exit 2
    ;;
esac

if [ -z "${TIER_ID:-}" ]; then
  printf '%s\n' "TIER_ID is not set." >&2
  exit 2
fi

curl -sS \
  -H "content-type: application/json" \
  --data "{\"tier_id\":\"$TIER_ID\",\"student_id\":\"$student_id\"}" \
  https://sl.0g.rip/beacon
