Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions stdlib-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/sh

set -eu

throwError() {
echo "\033[91m✗\033[0m $1." >&2
exit 1
}

logHappy() {
echo "\033[32m✔\033[0m $1"
}

# Pick the Agda executable to analyse
# unless the caller has specified one
if [ -z ${AGDA_EXEC-} ]; then
read -p "What's the name of your Agda executable (default: agda)? " AGDA_EXEC
if [ -z "$AGDA_EXEC" ]; then
AGDA_EXEC=agda
fi
fi

# Double check that the command exists
if ! [ -x "$(command -v $AGDA_EXEC)" ]; then
throwError "'$AGDA_EXEC' is not a valid executable"
Copy link
Member Author

@gallais gallais Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if e.g. $HOME/.cabal/bin/$AGDA_EXEC exists and suggest that the user should be adding $HOME/.cabal/bin/ to their PATH?

Copy link
Member

@Taneb Taneb Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get cabal's default install path from cabal with cabal path --installdir

fi

logHappy "Agda executable: $AGDA_EXEC"

# Ask the executable for its version number
# unless the caller has specified one
if [ -z ${AGDA_VERSION-} ]; then
AGDA_VERSION=$($AGDA_EXEC --version | head -n 1 | sed "s/^[a-zA-Z ]*\(2[0-9.]*\)\(-.*\)*$/\1/")
fi

# Double check that the version number is correct
if ! echo "$AGDA_VERSION" | grep -Eq "^2(\.[0-9]+)+$"; then
throwError "'$AGDA_VERSION' is not a valid version number"
fi

logHappy "Agda version number: $AGDA_VERSION"

# Pick the install directory
# unless the caller has specified one
if [ -z ${AGDA_DIR-} ]; then
AGDA_DIR=$($AGDA_EXEC --print-agda-app-dir | head -n 1 || true)
if echo "$AGDA_DIR" | grep -Eq "^Error.*$"; then
AGDA_DIR="$HOME/.agda"
fi
read -p "Where do you want to install the library (default: $AGDA_DIR)? " AGDA_DIR_OVERWRITE
if ! [ -z "$AGDA_DIR_OVERWRITE" ]; then
AGDA_DIR="$AGDA_DIR_OVERWRITE"
fi
fi

logHappy "Agda directory: $AGDA_DIR"

if [ -z ${STDLIB_VERSION-} ]; then
case "$AGDA_VERSION" in
"2.8.0")
STDLIB_VERSION=2.3
;;
"2.7.0.1")
STDLIB_VERSION=2.3
;;
"2.7.0")
STDLIB_VERSION=2.2
;;
"2.6.4.3")
STDLIB_VERSION=2.1
;;
"2.6.4.2")
STDLIB_VERSION=2.0
;;
"2.6.4.2")
STDLIB_VERSION=2.0
;;
"2.6.4.1")
STDLIB_VERSION=2.0
;;
"2.6.4")
STDLIB_VERSION=2.0
;;
"2.6.3")
STDLIB_VERSION=1.7.3
;;
"2.6.2.2")
STDLIB_VERSION=1.7.1
;;
"2.6.2.1")
STDLIB_VERSION=1.7.1
;;
"2.6.1")
STDLIB_VERSION=1.7.1
;;
*)
STDLIB_VERSION=experimental
;;
esac
fi

logHappy "Standard library version: $STDLIB_VERSION"

case "$STDLIB_VERSION" in
"master")
STDLIB_TAG="refs/heads/master"
;;
"experimental")
STDLIB_TAG="refs/heads/experimental"
;;
*)
STDLIB_TAG="v$STDLIB_VERSION"
;;
esac

# Setting up the Agda install directory
mkdir -p "$AGDA_DIR"
cd "$AGDA_DIR"
mkdir -p logs

# Downloading and extracting the standard library
STDLIB_TARBALL_NAME="/tmp/agda-stdlib-$STDLIB_VERSION.tar.gz"
STDLIB_TARBALL_URL="https://github.com/agda/agda-stdlib/archive/$STDLIB_TAG.tar.gz"
wget -O "$STDLIB_TARBALL_NAME" "$STDLIB_TARBALL_URL" -o logs/wget
tar -zxvf "$STDLIB_TARBALL_NAME" > logs/tar

logHappy "Successfully downloaded the standard library"

# Adding the standard library to the list of installed and default libraries
STDLIB_PATH="$AGDA_DIR/agda-stdlib-$STDLIB_VERSION/standard-library.agda-lib"
AGDA_LIBRARIES_FILE="libraries-$AGDA_VERSION"

if ! grep -Eq "$STDLIB_PATH" "$AGDA_LIBRARIES_FILE"; then
echo "$STDLIB_PATH" >> "$AGDA_LIBRARIES_FILE"
fi

if ! grep -Eq "^standard-library$" "defaults-$AGDA_VERSION"; then
echo "standard-library" >> "defaults-$AGDA_VERSION"
fi

logHappy "Successfully installed the standard library"