@@ -16,11 +16,45 @@ echoerr() {
1616 echo " $@ " 1>&2
1717}
1818
19+ download_and_extract () {
20+ local archive_name=$1
21+
22+ echoerr " > Downloading..."
23+ curl --fail --location --connect-timeout 30 --max-time 300 --tlsv1.2 -o " $archive_name " " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name "
24+ echoerr " > Done."
25+
26+ echoerr " > Cleaning up existing artifacts..."
27+ rm -rf artifacts
28+ rm -rf forge-artifacts
29+ rm -rf cache
30+ echoerr " > Done."
31+
32+ echoerr " > Extracting artifacts..."
33+ if [[ " $archive_name " == * .tar.zst ]]; then
34+ zstd -dc " $archive_name " | tar -xf - --exclude=' *..*'
35+ else
36+ tar -xzvf " $archive_name " --exclude=' *..*'
37+ fi
38+ echoerr " > Done."
39+
40+ echoerr " > Cleaning up."
41+ rm " $archive_name "
42+ echoerr " > Done."
43+ exit 0
44+ }
45+
1946# Check for help flag
2047if [ " ${1:- } " = " --help" ] || [ " ${1:- } " = " -h" ]; then
2148 usage
2249fi
2350
51+ # Check for fallback-to-latest flag
52+ USE_LATEST_FALLBACK=false
53+ if [ " ${1:- } " = " --fallback-to-latest" ]; then
54+ USE_LATEST_FALLBACK=true
55+ echoerr " > Fallback to latest enabled"
56+ fi
57+
2458SCRIPT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd )
2559CONTRACTS_DIR=" $SCRIPT_DIR /../.."
2660
@@ -41,57 +75,43 @@ echoerr "> Checking for existing artifacts..."
4175if [ " $HAS_ZSTD " = true ]; then
4276 archive_name_zst=" artifacts-v1-$checksum .tar.zst"
4377 exists_zst=$( curl -s -o /dev/null --fail -LI " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst " || echo " fail" )
44-
78+
4579 if [ " $exists_zst " != " fail" ]; then
46- echoerr " > Found .tar.zst artifacts. Downloading..."
47- curl -o " $archive_name_zst " " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst "
48- echoerr " > Done."
49-
50- echoerr " > Cleaning up existing artifacts..."
51- rm -rf artifacts
52- rm -rf forge-artifacts
53- rm -rf cache
54- echoerr " > Done."
55-
56- echoerr " > Extracting existing artifacts..."
57- zstd -dc " $archive_name_zst " | tar -xf -
58- echoerr " > Done."
59-
60- echoerr " > Cleaning up."
61- rm " $archive_name_zst "
62- echoerr " > Done."
63- exit 0
80+ download_and_extract " $archive_name_zst "
81+ fi
82+
83+ # Try latest fallback if enabled
84+ if [ " $USE_LATEST_FALLBACK " = true ]; then
85+ echoerr " > Exact checksum not found, trying latest artifacts..."
86+ archive_name_zst=" artifacts-v1-latest.tar.zst"
87+ exists_latest_zst=$( curl -s -o /dev/null --fail -LI " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst " || echo " fail" )
88+
89+ if [ " $exists_latest_zst " != " fail" ]; then
90+ download_and_extract " $archive_name_zst "
91+ fi
6492 fi
6593fi
6694
6795archive_name_gz=" artifacts-v1-$checksum .tar.gz"
6896exists_gz=$( curl -s -o /dev/null --fail -LI " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz " || echo " fail" )
6997
7098if [ " $exists_gz " == " fail" ]; then
71- echoerr " > No existing artifacts found, exiting."
72- exit 0
73- fi
74-
75- if [ " $HAS_ZSTD " = true ]; then
76- echoerr " > Only .tar.gz artifacts available (zstd format not found)."
77- else
78- echoerr " > Found .tar.gz artifacts (zstd not available)."
99+ # Try latest fallback if enabled
100+ if [ " $USE_LATEST_FALLBACK " = true ]; then
101+ echoerr " > Exact checksum not found, trying latest artifacts..."
102+ archive_name_gz=" artifacts-v1-latest.tar.gz"
103+ exists_latest_gz=$( curl -s -o /dev/null --fail -LI " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz " || echo " fail" )
104+
105+ if [ " $exists_latest_gz " == " fail" ]; then
106+ echoerr " > No existing artifacts found (including latest), exiting."
107+ exit 0
108+ fi
109+
110+ echoerr " > Found latest .tar.gz artifacts."
111+ else
112+ echoerr " > No existing artifacts found, exiting."
113+ exit 0
114+ fi
79115fi
80116
81- echoerr " > Cleaning up existing artifacts..."
82- rm -rf artifacts
83- rm -rf forge-artifacts
84- rm -rf cache
85- echoerr " > Done."
86-
87- echoerr " > Downloading artifacts..."
88- curl -o " $archive_name_gz " " https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz "
89- echoerr " > Done."
90-
91- echoerr " > Extracting existing artifacts..."
92- tar -xzvf " $archive_name_gz "
93- echoerr " > Done."
94-
95- echoerr " > Cleaning up."
96- rm " $archive_name_gz "
97- echoerr " > Done."
117+ download_and_extract " $archive_name_gz "
0 commit comments