-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathstdlib-install.sh
More file actions
177 lines (147 loc) · 5.16 KB
/
stdlib-install.sh
File metadata and controls
177 lines (147 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/sh
########################################################################
# DEBUG AND LOGGING
set -eu
isDebugMode() {
[ -n "${DEBUG-}" ]
}
if [ -n "${SHELL_DEBUG-}" ]; then
set -x
fi
throwError() {
printf "\033[91m✗\033[0m %s.\n" "$1" >&2
exit 1
}
logHappy() { printf "\033[32m✔\033[0m %s.\n" "$1"; }
logUnhappy() { printf "\033[91m✗\033[0m %s.\n" "$1"; }
logWarning() { printf "\033[93m⚠\033[0m %s.\n" "$1"; }
########################################################################
## PRELIMINARY CHECKS
checkDependency () {
if ! [ -x "$(command -v "$1")" ]; then
throwError "Missing dependency: I could not find the executable '$1'"
elif isDebugMode; then
logHappy "Found '$1'"
fi
}
checkDependency "grep"
checkDependency "head"
checkDependency "mkdir"
checkDependency "sed"
checkDependency "tar"
checkDependency "touch"
checkDependency "wget"
########################################################################
## IDENTIFY AND INSTALL THE CORRECT STDLIB VERSION
# Pick the Agda executable to analyse
# unless the caller has specified one
if [ -z "${AGDA_EXEC-}" ]; then
while true; do
printf "What's the name of your Agda executable (default: agda)? "
read -r AGDA_EXEC
if [ -z "$AGDA_EXEC" ]; then
AGDA_EXEC=agda
fi
# Double check that the command exists
if ! [ -x "$(command -v "$AGDA_EXEC")" ]; then
logUnhappy "'$AGDA_EXEC' is not a valid executable"
else
break
fi
done
elif ! [ -x "$(command -v "$AGDA_EXEC")" ]; then
throwError "'$AGDA_EXEC' is not a valid executable"
fi
logHappy "Agda executable: $AGDA_EXEC"
# Ask the executable for its version number
# unless the caller has specified one
if [ -z "${AGDA_VERSION-}" ]; then
# There is a more recent "--numeric-version" option but old
# versions of Agda do not implement it!
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
printf "Where do you want to install the library (default: %s)? " "$AGDA_DIR"
read -r AGDA_DIR_OVERWRITE
if [ -n "$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.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_DIR_NAME="agda-stdlib-$STDLIB_VERSION"
STDLIB_TARBALL_NAME="/tmp/$STDLIB_DIR_NAME.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 || throwError "Download of $STDLIB_TARBALL_URL failed"
logHappy "Successfully downloaded the standard library"
if [ -d "$STDLIB_DIR_NAME" ]; then
logWarning "The directory $AGDA_DIR/$STDLIB_DIR_NAME already exists"
while true; do
printf "Do you want to overwrite it? (yN) "
read -r DIR_OVERWRITE
DIR_OVERWRITE=${DIR_OVERWRITE:-n}
case "$DIR_OVERWRITE" in
[yY]*) DIR_OVERWRITE="y"; break;;
[nN]*) DIR_OVERWRITE="n"; break;;
*) logUnhappy "Invalid answer: '$DIR_OVERWRITE'. Please answer y or n";;
esac
done
if [ "$DIR_OVERWRITE" = "y" ]; then
rm -rf "$STDLIB_DIR_NAME"
tar -zxvf "$STDLIB_TARBALL_NAME" > logs/tar
fi
else
tar -zxvf "$STDLIB_TARBALL_NAME" > logs/tar
fi
# 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"
# For now we shove it in the 'defaults' file as using a version-specific
# "defaults-$AGDA_VERSION" is not supported yet by Agda :(
AGDA_DEFAULTS_FILE="defaults"
touch "$AGDA_LIBRARIES_FILE"
if ! grep -Eq "$STDLIB_PATH" "$AGDA_LIBRARIES_FILE"; then
echo "$STDLIB_PATH" >> "$AGDA_LIBRARIES_FILE"
fi
touch "$AGDA_DEFAULTS_FILE"
if ! grep -Eq "^standard-library$" "$AGDA_DEFAULTS_FILE"; then
echo "standard-library" >> "$AGDA_DEFAULTS_FILE"
fi
logHappy "Successfully installed the standard library"