-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_coq.sh
executable file
·146 lines (134 loc) · 4.14 KB
/
setup_coq.sh
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
#!/bin/bash
##
## Copyright (c) 2023 Radiance Technologies, Inc.
##
## This file is part of PRISM
## (see https://github.com/orgs/Radiance-Technologies/prism).
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as
## published by the Free Software Foundation, either version 3 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this program. If not, see
## <http://www.gnu.org/licenses/>.
##
if [ "${BASH_SOURCE[0]}" == "$0" ] ; then
echo "Please invoke as 'source $(basename $BASH_SOURCE)' instead."
exit
fi
HELP="Usage: setup_coq.sh [Coq version number] [-n|-y]
Install a sandboxed version of Coq. No administrator privileges required.
[-n|-y] Do (-y) or do not (-n) overwrite existing switches.
-h Display this message."
if [ "$1" == "-h" ] ; then
echo -e "$HELP" && return 0
fi
if [ "$1" == "" ] || [ "$1" == "-n" ] || [ "$1" == "-y" ] ; then
echo "Defaulting to Coq version 8.10.2"
export COQ_VERSION=8.10.2
export SERAPI_VERSION=8.10.0+0.7.1
if [ "$1" == "-n" ] ; then
REINSTALL=false
elif [ "$1" == "-y" ] ; then
REINSTALL=true
fi
else
case $1 in
"8.9.1")
export COQ_VERSION=8.9.1
export SERAPI_VERSION=8.9.0+0.6.1
;;
"8.10.2")
export COQ_VERSION=8.10.2
export SERAPI_VERSION=8.10.0+0.7.2
;;
"8.11.2")
export COQ_VERSION=8.11.2
export SERAPI_VERSION=8.11.0+0.11.1
;;
"8.12.2")
export COQ_VERSION=8.12.2
export SERAPI_VERSION=8.12.0+0.12.1
;;
"8.13.2")
export COQ_VERSION=8.13.2
export SERAPI_VERSION=8.13.0+0.13.1
;;
"8.14.1")
export COQ_VERSION=8.14.1
export SERAPI_VERSION=8.14.0+0.14.0
;;
"8.15.2")
export COQ_VERSION=8.15.2
export SERAPI_VERSION=8.15.0+0.15.4
;;
*)
echo "${1} is not a supported version of Coq." && return 1
esac
echo "Using Coq version ${COQ_VERSION} and SerAPI version ${SERAPI_VERSION}."
fi
if [ ! -z ${2+x} ] ; then
if [ "$REINSTALL" == "" ] ; then
if [ "$2" == "-n" ] ; then
REINSTALL=false
elif [ "$2" == "-y" ] ; then
REINSTALL=true
fi
else
echo -e "$HELP" && return 1
fi
fi
if [ -z ${GITROOT+x} ];
echo "Setting GITROOT environment variable."
then GITROOT=$(while :; do
[ -d .git ] && [ -f .prism ] && { echo `pwd`; break; };
[ `pwd` = "/" ] && { echo ""; break; };
cd ..;
done);
fi
OPAM_SWITCH="prism-$COQ_VERSION"
echo "Checking if switch exists..."
SWITCH_DETECTED=$((opam switch list || true) | (grep $OPAM_SWITCH || true))
# remove artifacts from previous setup
if [ ! "$SWITCH_DETECTED" == "" ] ; then
echo "Previous switch $OPAM_SWITCH with Coq==$COQ_VERSION detected. "
if [ "$REINSTALL" == "" ] ; then
while true; do
read -p "Do you want to remove and reinstall?[y/n]" yn
case $yn in
[Yy]* ) REINSTALL=true; break;;
[Nn]* ) REINSTALL=false; break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
else
echo "No existing switch named $OPAM_SWITCH detected."
REINSTALL=""
fi
if [ "$REINSTALL" == "true" ] || [ "$REINSTALL" = "" ] ; then
test "$REINSTALL" == "true" && echo "Removing $OPAM_SWITCH" && opam switch remove $OPAM_SWITCH -y
echo "Installing requested version of Coq in switch $OPAM_SWITCH"
opam switch create $OPAM_SWITCH 4.09.1 -y
opam switch $OPAM_SWITCH
echo "Updating shell environment"
eval $(opam env --switch=$OPAM_SWITCH --set-switch)
opam update
opam pin add coq $COQ_VERSION -y
opam pin add coq-serapi $SERAPI_VERSION -y
else
opam switch $OPAM_SWITCH
echo "Updating shell environment"
eval $(opam env --switch=$OPAM_SWITCH --set-switch)
fi
# clean up environment
unset REINSTALL
unset OPAM_SWITCH
unset SWITCH_DETECTED