-
Notifications
You must be signed in to change notification settings - Fork 7
/
deps.sh
executable file
·190 lines (167 loc) · 4.4 KB
/
deps.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# Copyright 2022 Mitchell Kember. Subject to the MIT License.
set -eufo pipefail
usage() {
cat <<EOS
Usage: $0 {check,install}
Manage dependencies for the SICP Study project
Commands:
check Check if dependencies are installed
install Install missing dependencies (macOS only)
EOS
}
lua_version=$(make print-LUA_VERSION)
platform=
warned=false
say() {
echo "*** $*"
}
run() {
echo "> $*"
"$@"
}
ask() {
echo -n "*** $* [y/N] "
read -r
case $REPLY in
y|Y) ;;
*) return 1 ;;
esac
}
warn() {
echo "warning: $*" >&2
warned=true
}
die() {
echo "error: $*" >&2
exit 1
}
installed() {
command -v "$1" &> /dev/null
}
racket_file_installed() {
[[ -z "$(racket -I "$1" -e '' 2>&1)" ]]
}
say_already_installed() {
say "note: $1 is already installed"
}
get_platform() {
platform=$(uname -s)
case $platform in
Darwin) platform=macos ;;
*) return 1 ;;
esac
}
check() {
# Note: Lua is only needed for its headers, to compile the C libraries in
# tools/lua. But we assume you just install the entire Lua package.
say "checking programs"
for cmd in chez guile racket pandoc lua$lua_version deno svgbob python3 \
vnu shellcheck clang-format
do
installed "$cmd" || warn "$cmd not installed"
done
say "checking racket packages"
if installed racket; then
for x in compiler-lib:compiler/sig.rkt r6rs-lib:r6rs; do
racket_file_installed "${x#*:}" || warn "${x%:*} not installed"
done
else
warn "cannot check racket packages: need racket"
fi
say "checking python packages"
if installed pip3; then
pip3 -qq show "requests" || warn "requests not installed"
else
warn "cannot check python packages: need pip3"
fi
say "checking pandoc lua version"
if installed pandoc; then
v=$(pandoc --lua-filter <(echo 'print(_VERSION)') <<< '' \
| grep -o '\d\.\d')
if [[ "$v" != "$lua_version" ]]; then
warn "pandoc is built with lua $v; expected lua $lua_version"
fi
else
warn "cannot check pandoc lua version: need pandoc"
fi
}
install() {
get_platform || die "unsupported platform: $platform"
"install_${platform}_prep"
if ask "install all supported schemes?"; then
"install_${platform}_scheme"
fi
if ask "install dependencies for buiding docs?"; then
"install_${platform}_docs"
fi
if ask "install other development tools?"; then
"install_${platform}_other"
fi
}
install_macos_prep() {
if ! installed brew; then
die "try again after installing https://brew.sh"
fi
}
install_macos_scheme() {
install_macos_formulas chezscheme:chez guile minimal-racket:racket
for x in compiler-lib:compiler/sig.rkt r6rs-lib:r6rs; do
if ! racket_file_installed "${x#*:}"; then
raco pkg install --auto --no-docs "${x%:*}"
fi
done
}
install_macos_docs() {
lua="lua@$lua_version"
lua_dir=$(brew --prefix "$lua")
install_macos_formulas pandoc deno "$lua:$lua_dir/bin/lua"
if installed svgbob; then
say_already_installed svgbob
else
if ! installed cargo; then
die "try again after installing https://rustup.rs (need for svgbob)"
fi
# Latest commit as of 2021-03-27.
svgbob_git=https://github.com/ivanceras/svgbob
svgbob_rev=3a2fdd784044130909ad992bede02b971e4b8721
run cargo install svgbob_cli --git $svgbob_git --rev $svgbob_rev
if ! installed svgbob; then
warn "svgbob executable not found; is ~/.cargo/bin in your PATH?"
fi
fi
}
install_macos_other() {
install_macos_formulas python3 vnu clang-format shellcheck
if pip3 -qq show requests; then
say_already_installed requests
else
pip3 install requests
fi
}
install_macos_formulas() {
args=()
for cmd in "$@"; do
if installed "${cmd#*:}"; then
say_already_installed "${cmd#*:}"
else
args+=("${cmd%:*}")
fi
done
if [[ ${#args[@]} -gt 0 ]]; then
run brew install "${args[@]}"
fi
}
case $# in
1)
case $1 in
-h|--help|help) usage ;;
check|install) "$1" ;;
*) die "$1: invalid command" ;;
esac
;;
*) usage >&2; exit 1 ;;
esac
if [[ $warned = true ]]; then
exit 1
fi