Skip to content

Commit 273d05a

Browse files
committed
[ new ] install script for the standard library
1 parent efda8e2 commit 273d05a

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

stdlib-install.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
throwError() {
6+
echo "\033[91m✗\033[0m $1." >&2
7+
exit 1
8+
}
9+
10+
logHappy() {
11+
echo "\033[32m✔\033[0m $1"
12+
}
13+
14+
# Pick the Agda executable to analyse
15+
# unless the caller has specified one
16+
if [ -z ${AGDA_EXEC-} ]; then
17+
read -p "What's the name of your Agda executable (default: agda)? " AGDA_EXEC
18+
if [ -z "$AGDA_EXEC" ]; then
19+
AGDA_EXEC=agda
20+
fi
21+
fi
22+
23+
# Double check that the command exists
24+
if ! [ -x "$(command -v $AGDA_EXEC)" ]; then
25+
throwError "'$AGDA_EXEC' is not a valid executable"
26+
fi
27+
28+
logHappy "Agda executable: $AGDA_EXEC"
29+
30+
# Ask the executable for its version number
31+
# unless the caller has specified one
32+
if [ -z ${AGDA_VERSION-} ]; then
33+
AGDA_VERSION=$($AGDA_EXEC --version | head -n 1 | sed "s/^[a-zA-Z ]*\(2[0-9.]*\)\(-.*\)*$/\1/")
34+
fi
35+
36+
# Double check that the version number is correct
37+
if ! echo "$AGDA_VERSION" | grep -Eq "^2(\.[0-9]+)+$"; then
38+
throwError "'$AGDA_VERSION' is not a valid version number"
39+
fi
40+
41+
logHappy "Agda version number: $AGDA_VERSION"
42+
43+
# Pick the install directory
44+
# unless the caller has specified one
45+
if [ -z ${AGDA_DIR-} ]; then
46+
AGDA_DIR=$($AGDA_EXEC --print-agda-app-dir | head -n 1 || true)
47+
if echo "$AGDA_DIR" | grep -Eq "^Error.*$"; then
48+
AGDA_DIR="$HOME/.agda"
49+
fi
50+
read -p "Where do you want to install the library (default: $AGDA_DIR)? " AGDA_DIR_OVERWRITE
51+
if ! [ -z "$AGDA_DIR_OVERWRITE" ]; then
52+
AGDA_DIR="$AGDA_DIR_OVERWRITE"
53+
fi
54+
fi
55+
56+
logHappy "Agda directory: $AGDA_DIR"
57+
58+
if [ -z ${STDLIB_VERSION-} ]; then
59+
case "$AGDA_VERSION" in
60+
"2.8.0")
61+
STDLIB_VERSION=2.3
62+
;;
63+
"2.7.0.1")
64+
STDLIB_VERSION=2.3
65+
;;
66+
"2.7.0")
67+
STDLIB_VERSION=2.2
68+
;;
69+
"2.6.4.3")
70+
STDLIB_VERSION=2.1
71+
;;
72+
"2.6.4.2")
73+
STDLIB_VERSION=2.0
74+
;;
75+
"2.6.4.2")
76+
STDLIB_VERSION=2.0
77+
;;
78+
"2.6.4.1")
79+
STDLIB_VERSION=2.0
80+
;;
81+
"2.6.4")
82+
STDLIB_VERSION=2.0
83+
;;
84+
"2.6.3")
85+
STDLIB_VERSION=1.7.3
86+
;;
87+
"2.6.2.2")
88+
STDLIB_VERSION=1.7.1
89+
;;
90+
"2.6.2.1")
91+
STDLIB_VERSION=1.7.1
92+
;;
93+
"2.6.1")
94+
STDLIB_VERSION=1.7.1
95+
;;
96+
*)
97+
STDLIB_VERSION=experimental
98+
;;
99+
esac
100+
fi
101+
102+
logHappy "Standard library version: $STDLIB_VERSION"
103+
104+
case "$STDLIB_VERSION" in
105+
"master")
106+
STDLIB_TAG="refs/heads/master"
107+
;;
108+
"experimental")
109+
STDLIB_TAG="refs/heads/experimental"
110+
;;
111+
*)
112+
STDLIB_TAG="v$STDLIB_VERSION"
113+
;;
114+
esac
115+
116+
# Setting up the Agda install directory
117+
mkdir -p "$AGDA_DIR"
118+
cd "$AGDA_DIR"
119+
mkdir -p logs
120+
121+
# Downloading and extracting the standard library
122+
STDLIB_TARBALL_NAME="/tmp/agda-stdlib-$STDLIB_VERSION.tar.gz"
123+
STDLIB_TARBALL_URL="https://github.com/agda/agda-stdlib/archive/$STDLIB_TAG.tar.gz"
124+
wget -O "$STDLIB_TARBALL_NAME" "$STDLIB_TARBALL_URL" -o logs/wget
125+
tar -zxvf "$STDLIB_TARBALL_NAME" > logs/tar
126+
127+
logHappy "Successfully downloaded the standard library"
128+
129+
# Adding the standard library to the list of installed and default libraries
130+
STDLIB_PATH="$AGDA_DIR/agda-stdlib-$STDLIB_VERSION/standard-library.agda-lib"
131+
AGDA_LIBRARIES_FILE="libraries-$AGDA_VERSION"
132+
133+
if ! grep -Eq "$STDLIB_PATH" "$AGDA_LIBRARIES_FILE"; then
134+
echo "$STDLIB_PATH" >> "$AGDA_LIBRARIES_FILE"
135+
fi
136+
137+
if ! grep -Eq "^standard-library$" "defaults-$AGDA_VERSION"; then
138+
echo "standard-library" >> "defaults-$AGDA_VERSION"
139+
fi
140+
141+
logHappy "Successfully installed the standard library"

0 commit comments

Comments
 (0)