changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / bootstrap.sh

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