Files
py-media-grader/deploy.sh

78 lines
2.3 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Always run from this script's directory
cd "$(dirname "$0")"
# Build a fresh wheel and install it as a uv tool to avoid stale caches
uv tool uninstall grader >/dev/null 2>&1 || true
uv build --wheel --out-dir dist
WHEEL=$(ls -1 dist/grader-*.whl | tail -n 1)
uv tool install "$WHEEL"
# Build and install croppa
cd croppa
uv tool uninstall croppa >/dev/null 2>&1 || true
uv build --wheel --out-dir dist
CROPPA_WHEEL=$(ls -1 dist/croppa-*.whl | tail -n 1)
uv tool install "$CROPPA_WHEEL"
cd ..
# Resolve uv tool install location (Linux/macOS and Windows Git Bash)
SRC=""
CROPPA_SRC=""
APPDATA_U=""
if [ -n "${APPDATA:-}" ]; then
if command -v cygpath >/dev/null 2>&1; then
APPDATA_U="$(cygpath -u "$APPDATA")"
else
APPDATA_U="$APPDATA"
fi
fi
if [ -d "$HOME/.local/share/uv/tools/grader/bin" ]; then
SRC="$HOME/.local/share/uv/tools/grader/bin"
elif [ -n "$APPDATA_U" ] && [ -d "$APPDATA_U/uv/tools/grader/Scripts" ]; then
SRC="$APPDATA_U/uv/tools/grader/Scripts"
elif [ -d "$HOME/AppData/Roaming/uv/tools/grader/Scripts" ]; then
SRC="$HOME/AppData/Roaming/uv/tools/grader/Scripts"
fi
if [ -d "$HOME/.local/share/uv/tools/croppa/bin" ]; then
CROPPA_SRC="$HOME/.local/share/uv/tools/croppa/bin"
elif [ -n "$APPDATA_U" ] && [ -d "$APPDATA_U/uv/tools/croppa/Scripts" ]; then
CROPPA_SRC="$APPDATA_U/uv/tools/croppa/Scripts"
elif [ -d "$HOME/AppData/Roaming/uv/tools/croppa/Scripts" ]; then
CROPPA_SRC="$HOME/AppData/Roaming/uv/tools/croppa/Scripts"
fi
mkdir -p "$HOME/.local/bin"
if [ -n "$SRC" ]; then
if [ -f "$SRC/grader.exe" ]; then
cp -f "$SRC/grader.exe" "$HOME/.local/bin/grader.exe"
elif [ -f "$SRC/grader" ]; then
cp -f "$SRC/grader" "$HOME/.local/bin/grader"
chmod +x "$HOME/.local/bin/grader"
fi
fi
if [ -n "$CROPPA_SRC" ]; then
if [ -f "$CROPPA_SRC/croppa.exe" ]; then
cp -f "$CROPPA_SRC/croppa.exe" "$HOME/.local/bin/croppa.exe"
elif [ -f "$CROPPA_SRC/croppa" ]; then
cp -f "$CROPPA_SRC/croppa" "$HOME/.local/bin/croppa"
chmod +x "$HOME/.local/bin/croppa"
fi
fi
case ":${PATH}:" in
*":$HOME/.local/bin:"*) ;;
*) export PATH="$HOME/.local/bin:$PATH" ;;
esac
# Refresh shell command cache and print resolution
hash -r || true
which grader || true
which croppa || true
echo "grader and croppa installed to $HOME/.local/bin"