#!/bin/bash
# One-time setup on PACE ICE. Run this once from the login node.
#
#   bash setup.sh
#
# Model files are several GB each. Your home directory holds 30 GB and your
# scratch directory holds 300 GB, so this points every model cache at scratch.

set -e

mkdir -p ~/scratch/.cache ~/scratch/.ollama

link_to_scratch() {
    local link=$1 target=$2
    if [ -L "$link" ]; then
        echo "ok        $link is already a link"
    elif [ -d "$link" ]; then
        echo "moving    $link into scratch"
        mv "$link"/* "$target"/ 2>/dev/null || true
        rmdir "$link" 2>/dev/null || { echo "WARNING   $link is not empty, move it by hand"; return; }
        ln -s "$target" "$link"
        echo "ok        $link now points at $target"
    else
        ln -s "$target" "$link"
        echo "ok        $link now points at $target"
    fi
}

link_to_scratch ~/.cache  ~/scratch/.cache
link_to_scratch ~/.ollama ~/scratch/.ollama

echo
echo "Storage in use:"
pace-quota 2>/dev/null | grep -E "^(Home|Scratch)" || true
echo
echo "Setup done. Next run: sbatch serve.sbatch"
