changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / bootstrap.sh

changeset 290: 02f74f65976c
parent: b83f6ec89f5d
child: 9c37db8ed167
author: Richard Westhaver <ellis@rwest.io>
date: Tue, 18 Jun 2024 16:38:44 -0400
permissions: -rwxr-xr-x
description: add back t-rec script
1 #!/bin/sh
2 set -eu
3 
4 main() {
5  . ./check.sh
6  download --check
7  local _arch=$(_read arch | tr -d '"')
8  local _ext=""
9  case "$_arch" in
10  *windows*)
11  _ext=".exe"
12  ;;
13  esac
14  local _url="https://packy.compiler.company/dist/${_arch}/pack"
15  local _stash
16  if ! _stash=".stash"; then
17  # Because the previous command ran in a subshell, we must manually
18  # propagate exit status.
19  exit 1
20  fi
21  ensure mkdir -p "${_stash}/src"
22  ensure mkdir -p "${_stash}/share/lisp/fasl"
23  ensure mkdir -p "${_stash}/bin"
24  ensure mkdir -p "${_stash}/lib"
25  ensure mkdir -p "${_stash}/include"
26  cd "${_stash}"
27  local _sbcl_pack="sbcl.tar.zst"
28  # local _rocksdb_pack="rocksdb.tar.zst"
29  local _core_pack="core.tar.zst"
30  # local _core_src_pack="core-source.tar.zst"
31  local _sbcl_url="${_url}/${_sbcl_pack}"
32  # local _rocksdb_url="${_url}/${_rocksdb_pack}"
33  local _core_url="${_url}/${_core_pack}"
34  # local _core_src_url="${_url}/${_core_src_pack}"
35  ensure download "$_sbcl_url" "$_sbcl_pack" "$_arch"
36  unzstd "${_sbcl_pack}"
37  tar -xf "sbcl.tar"
38  cd sbcl && INSTALL_ROOT=$(realpath ..) sh install.sh && cd ..
39  # ensure download "$_core_src_url" "$_core_src_pack" "$_arch"
40  # unzstd "${_core_src_pack}"
41  # tar -xvf "core-source.tar"
42  # mv core src/
43  # ensure download "$_rocksdb_url" "${_rocksdb_pack}" "$_arch"
44  # unzstd "${_rocksdb_pack}"
45  # tar -xvf "pack/rocksdb.tar"
46  # cp -rf rocksdb/include/* include/
47  # cp -rf rocksdb/*.so lib/
48  ensure download "$_core_url" "${_core_pack}" "$_arch"
49  unzstd "${_core_pack}"
50  tar -xf "core.tar"
51  cp -rf core/bin/* bin/
52  cp -rf core/share/* share/
53  chmod +x bin/*
54  rm -rf core sbcl
55  rm -rf *.tar
56  say "successfully unpacked core"
57  say "starting lisp..."
58  cd .. && \
59  .stash/bin/sbcl --core .stash/share/lisp/user.core \
60  --load autogen.lisp \
61  --eval "(infra/autogen:autogen)" \
62  --non-interactive \
63  --no-userinit --no-sysinit
64  say "OK"
65 }
66 
67 _read() {
68  grep ":$1" $INFRA_HOST_CONFIG | cut -d' ' -f 2-
69 }
70 
71 # Check if curl supports the --retry flag, then pass it to the curl invocation.
72 check_curl_for_retry_support() {
73  local _retry_supported=""
74  # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
75  if check_help_for "notspecified" "curl" "--retry"; then
76  _retry_supported="--retry 3"
77  if check_help_for "notspecified" "curl" "--continue-at"; then
78  # "-C -" tells curl to automatically find where to resume the download when retrying.
79  _retry_supported="--retry 3 -C -"
80  fi
81  fi
82  RETVAL="$_retry_supported"
83 }
84 
85 # Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites
86 # if support by local tools is detected. Detection currently supports these curl backends:
87 # GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty.
88 get_ciphersuites_for_curl() {
89  if [ -n "${TLS_CIPHERSUITES-}" ]; then
90  # user specified custom cipher suites, assume they know what they're doing
91  RETVAL="$TLS_CIPHERSUITES"
92  return
93  fi
94  local _openssl_syntax="no"
95  local _gnutls_syntax="no"
96  local _backend_supported="yes"
97  if curl -V | grep -q ' OpenSSL/'; then
98  _openssl_syntax="yes"
99  elif curl -V | grep -iq ' LibreSSL/'; then
100  _openssl_syntax="yes"
101  elif curl -V | grep -iq ' BoringSSL/'; then
102  _openssl_syntax="yes"
103  elif curl -V | grep -iq ' GnuTLS/'; then
104  _gnutls_syntax="yes"
105  else
106  _backend_supported="no"
107  fi
108  local _args_supported="no"
109  if [ "$_backend_supported" = "yes" ]; then
110  # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
111  if check_help_for "notspecified" "curl" "--tlsv1.2" "--ciphers" "--proto"; then
112  _args_supported="yes"
113  fi
114  fi
115  local _cs=""
116  if [ "$_args_supported" = "yes" ]; then
117  if [ "$_openssl_syntax" = "yes" ]; then
118  _cs=$(get_strong_ciphersuites_for "openssl")
119  elif [ "$_gnutls_syntax" = "yes" ]; then
120  _cs=$(get_strong_ciphersuites_for "gnutls")
121  fi
122  fi
123  RETVAL="$_cs"
124 }
125 
126 # Return cipher suite string specified by user, otherwise return strong TLS 1.2-1.3 cipher suites
127 # if support by local tools is detected. Detection currently supports these wget backends:
128 # GnuTLS and OpenSSL (possibly also LibreSSL and BoringSSL). Return value can be empty.
129 get_ciphersuites_for_wget() {
130  if [ -n "${TLS_CIPHERSUITES-}" ]; then
131  # user specified custom cipher suites, assume they know what they're doing
132  RETVAL="$TLS_CIPHERSUITES"
133  return
134  fi
135  local _cs=""
136  if wget -V | grep -q '\-DHAVE_LIBSSL'; then
137  # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
138  if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then
139  _cs=$(get_strong_ciphersuites_for "openssl")
140  fi
141  elif wget -V | grep -q '\-DHAVE_LIBGNUTLS'; then
142  # "unspecified" is for arch, allows for possibility old OS using macports, homebrew, etc.
143  if check_help_for "notspecified" "wget" "TLSv1_2" "--ciphers" "--https-only" "--secure-protocol"; then
144  _cs=$(get_strong_ciphersuites_for "gnutls")
145  fi
146  fi
147  RETVAL="$_cs"
148 }
149 
150 check_help_for() {
151  local _arch
152  local _cmd
153  local _arg
154  _arch="$1"
155  shift
156  _cmd="$1"
157  shift
158  local _category
159  if "$_cmd" --help | grep -q 'For all options use the manual or "--help all".'; then
160  _category="all"
161  else
162  _category=""
163  fi
164 
165  case "$_arch" in
166  *darwin*)
167  if check_cmd sw_vers; then
168  case $(sw_vers -productVersion) in
169  10.*)
170  # If we're running on macOS, older than 10.13, then we always
171  # fail to find these options to force fallback
172  if [ "$(sw_vers -productVersion | cut -d. -f2)" -lt 13 ]; then
173  # Older than 10.13
174  echo "Warning: Detected macOS platform older than 10.13"
175  return 1
176  fi
177  ;;
178  11.*)
179  # We assume Big Sur will be OK for now
180  ;;
181  *)
182  # Unknown product version, warn and continue
183  echo "Warning: Detected unknown macOS major version: $(sw_vers -productVersion)"
184  echo "Warning TLS capabilities detection may fail"
185  ;;
186  esac
187  fi
188  ;;
189  esac
190  for _arg in "$@"; do
191  if ! "$_cmd" --help "$_category" | grep -q -- "$_arg"; then
192  return 1
193  fi
194  done
195  true # not strictly needed
196 }
197 
198 # Return strong TLS 1.2-1.3 cipher suites in OpenSSL or GnuTLS syntax. TLS 1.2
199 # excludes non-ECDHE and non-AEAD cipher suites. DHE is excluded due to bad
200 # DH params often found on servers (see RFC 7919). Sequence matches or is
201 # similar to Firefox 68 ESR with weak cipher suites disabled via about:config.
202 # $1 must be openssl or gnutls.
203 get_strong_ciphersuites_for() {
204  if [ "$1" = "openssl" ]; then
205  # OpenSSL is forgiving of unknown values, no problems with TLS 1.3 values on versions that don't support it yet.
206  echo "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384"
207  elif [ "$1" = "gnutls" ]; then
208  # GnuTLS isn't forgiving of unknown values, so this may require a GnuTLS version that supports TLS 1.3 even if wget doesn't.
209  # Begin with SECURE128 (and higher) then remove/add to build cipher suites. Produces same 9 cipher suites as OpenSSL but in slightly different order.
210  echo "SECURE128:-VERS-SSL3.0:-VERS-TLS1.0:-VERS-TLS1.1:-VERS-DTLS-ALL:-CIPHER-ALL:-MAC-ALL:-KX-ALL:+AEAD:+ECDHE-ECDSA:+ECDHE-RSA:+AES-128-GCM:+CHACHA20-POLY1305:+AES-256-GCM"
211  fi
212 }
213 
214 # This wraps curl or wget. Try curl first, if not installed,
215 # use wget instead.
216 download() {
217  local _dld
218  local _ciphersuites
219  local _err
220  local _status
221  local _retry
222  if check_cmd curl; then
223  _dld=curl
224  elif check_cmd wget; then
225  _dld=wget
226  else
227  _dld='curl or wget' # to be used in error message of need_cmd
228  fi
229  if [ "$1" = --check ]; then
230  need_cmd "$_dld"
231  elif [ "$_dld" = curl ]; then
232  check_curl_for_retry_support
233  _retry="$RETVAL"
234  get_ciphersuites_for_curl
235  _ciphersuites="$RETVAL"
236  if [ -n "$_ciphersuites" ]; then
237  _err=$(curl $_retry --proto '=https' --tlsv1.2 --ciphers "$_ciphersuites" --silent --show-error --fail --location "$1" --output "$2" 2>&1)
238  _status=$?
239  else
240  echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure"
241  if ! check_help_for "$3" curl --proto --tlsv1.2; then
242  echo "Warning: Not enforcing TLS v1.2, this is potentially less secure"
243  _err=$(curl $_retry --silent --show-error --fail --location "$1" --output "$2" 2>&1)
244  _status=$?
245  else
246  _err=$(curl $_retry --proto '=https' --tlsv1.2 --silent --show-error --fail --location "$1" --output "$2" 2>&1)
247  _status=$?
248  fi
249  fi
250  if [ -n "$_err" ]; then
251  echo "$_err" >&2
252  if echo "$_err" | grep -q 404$; then
253  err "installer for platform '$3' not found, this may be unsupported"
254  fi
255  fi
256  return $_status
257  elif [ "$_dld" = wget ]; then
258  if [ "$(wget -V 2>&1|head -2|tail -1|cut -f1 -d" ")" = "BusyBox" ]; then
259  echo "Warning: using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure"
260  _err=$(wget "$1" -O "$2" 2>&1)
261  _status=$?
262  else
263  get_ciphersuites_for_wget
264  _ciphersuites="$RETVAL"
265  if [ -n "$_ciphersuites" ]; then
266  _err=$(wget --https-only --secure-protocol=TLSv1_2 --ciphers "$_ciphersuites" "$1" -O "$2" 2>&1)
267  _status=$?
268  else
269  echo "Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure"
270  if ! check_help_for "$3" wget --https-only --secure-protocol; then
271  echo "Warning: Not enforcing TLS v1.2, this is potentially less secure"
272  _err=$(wget "$1" -O "$2" 2>&1)
273  _status=$?
274  else
275  _err=$(wget --https-only --secure-protocol=TLSv1_2 "$1" -O "$2" 2>&1)
276  _status=$?
277  fi
278  fi
279  fi
280  if [ -n "$_err" ]; then
281  echo "$_err" >&2
282  if echo "$_err" | grep -q ' 404 Not Found$'; then
283  err "installer for platform '$3' not found, this may be unsupported"
284  fi
285  fi
286  return $_status
287  else
288  err "Unknown downloader" # should not reach here
289  fi
290 }
291 
292 main "$@" || exit 1