Skip to content

Commit 1ae3ecc

Browse files
Copilotyihui
andauthored
Add retry logic (10 retries, 30s delay) to all download commands in installation scripts (#499)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yihui <163582+yihui@users.noreply.github.com> Co-authored-by: Yihui Xie <xie@yihui.name>
1 parent 224824b commit 1ae3ecc

6 files changed

Lines changed: 67 additions & 24 deletions

File tree

tools/install-base.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ TLINST="install-tl-unx.tar.gz"
77
TLURL=$TLREPO/$TLINST
88
PRNAME="tinytex.profile"
99
PRURL="https://tinytex.yihui.org"
10+
11+
# download a URL and save to its basename; pick curl or wget by availability
12+
download_file() {
13+
if command -v curl > /dev/null 2>&1; then
14+
curl -L -f --retry 10 --retry-delay 30 -O "$1"
15+
else
16+
wget --tries=11 --waitretry=30 "$1"
17+
fi
18+
}
19+
1020
if [ $(uname) = 'Darwin' ]; then
1121
alias sedi="sed -i ''"
12-
[ -e $TLINST ] || curl -LO $TLURL
13-
[ -e $PRNAME ] || curl -LO $PRURL/$PRNAME
1422
else
1523
alias sedi="sed -i"
16-
[ -e $TLINST ] || wget $TLURL
17-
[ -e $PRNAME ] || wget $PRURL/$PRNAME
24+
fi
25+
26+
[ -e "$TLINST" ] || download_file "$TLURL"
27+
[ -e "$PRNAME" ] || download_file "$PRURL/$PRNAME"
28+
29+
if [ $(uname) != 'Darwin' ]; then
1830
# ask `tlmgr path add` to add binaries to ~/bin instead of the default
1931
# /usr/local/bin unless this script is invoked with the argument '--admin'
2032
# (e.g., users want to make LaTeX binaries available system-wide), in which

tools/install-bin-unix.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ is_musl() {
4040
fi
4141
}
4242

43+
# download URL to output file; pick curl or wget by availability
44+
# $1 = URL, $2 = output file
45+
download_file() {
46+
if command -v curl > /dev/null 2>&1; then
47+
curl -L -f --retry 10 --retry-delay 30 "$1" -o "$2"
48+
else
49+
wget --retry-connrefused --tries=11 --waitretry=30 --progress=dot:giga -O "$2" "$1"
50+
fi
51+
}
52+
4353
if [ $OSNAME = 'Darwin' ]; then
4454
TEXDIR=${TINYTEX_DIR:-~/Library}/TinyTeX
4555
else
@@ -94,19 +104,14 @@ fi
94104

95105
INSTALLER_FILE="${TINYTEX_INSTALLER}${OS_ARCH}.${EXT}"
96106

107+
download_file "${TINYTEX_URL}" "${INSTALLER_FILE}"
97108
if [ "${TINYTEX_INSTALLER#"TinyTeX"}" != "$TINYTEX_INSTALLER" ]; then
98-
# prebuilt TinyTeX bundle: download with platform-appropriate tool
99-
if [ $OSNAME = 'Darwin' ]; then
100-
curl -L -f --retry 10 --retry-delay 30 ${TINYTEX_URL} -o "${INSTALLER_FILE}"
101-
else
102-
wget --retry-connrefused --progress=dot:giga -O "${INSTALLER_FILE}" ${TINYTEX_URL}
103-
fi
109+
# prebuilt TinyTeX bundle
104110
tar xf "${INSTALLER_FILE}" -C $(dirname $TEXDIR)
105111
if [ -n "$1" ]; then mv "${INSTALLER_FILE}" "$1/"; else rm "${INSTALLER_FILE}"; fi
106112
else
107113
echo "We do not have a prebuilt TinyTeX package for this operating system ($(uname -s) $(uname -m))."
108114
echo "I will try to install from source for you instead."
109-
wget --retry-connrefused -O "${INSTALLER_FILE}" ${TINYTEX_URL}
110115
tar xf "${INSTALLER_FILE}"
111116
./install.sh
112117
mkdir -p $TEXDIR

tools/install-bin-windows.bat

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
where /q powershell || echo PowerShell not found && exit /b
2-
3-
cd /d "%TEMP%"
4-
5-
powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest 'https://tinytex.yihui.org/install-bin-windows.ps1' -OutFile 'install-bin-windows.ps1'"
6-
powershell -ExecutionPolicy Bypass -File "install-bin-windows.ps1" %*
7-
del "install-bin-windows.ps1"
1+
powershell -ExecutionPolicy Bypass -Command "irm 'https://tinytex.yihui.org/install-bin-windows.ps1' | iex"

tools/install-bin-windows.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
$ErrorActionPreference = 'Stop'
22

3+
function Invoke-DownloadWithRetry {
4+
param([string]$Uri, [string]$OutFile, [int]$MaxRetries = 10, [int]$RetryDelay = 30)
5+
for ($i = 1; $i -le ($MaxRetries + 1); $i++) {
6+
try {
7+
Invoke-WebRequest $Uri -OutFile $OutFile
8+
return
9+
} catch {
10+
if ($i -gt $MaxRetries) { throw }
11+
Write-Host "Download failed (attempt $i of $($MaxRetries + 1)), retrying in $RetryDelay seconds..."
12+
Start-Sleep -Seconds $RetryDelay
13+
}
14+
}
15+
}
16+
317
# switch to a temp directory
418
cd $env:TEMP
519
[Environment]::CurrentDirectory = $PWD.Path
@@ -39,7 +53,7 @@ $DownloadedFile = "$TinyTeXFilename.$BundleExt"
3953

4054
# download the bundle
4155
Write-Host "Download $BundleExt file..."
42-
Invoke-WebRequest $TinyTeXURL -OutFile $DownloadedFile
56+
Invoke-DownloadWithRetry $TinyTeXURL $DownloadedFile
4357

4458
# unzip the downloaded file
4559
Write-Host 'Unbundle TinyTeX'

tools/install-unx.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ cd ${TMPDIR:-/tmp}
77

88
if [ $(uname) = 'Darwin' ]; then
99
TEXDIR=${TINYTEX_DIR:-~/Library/TinyTeX}
10-
alias download='curl -sL'
1110
else
1211
TEXDIR=${TINYTEX_DIR:-~/.TinyTeX}
13-
alias download='wget -qO-'
12+
fi
13+
14+
if command -v curl > /dev/null 2>&1; then
15+
download() { curl -sL --retry 10 --retry-delay 30 "$1"; }
16+
else
17+
download() { wget -qO- --tries=11 --waitretry=30 "$1"; }
1418
fi
1519

1620
rm -f install-tl-unx.tar.gz tinytex.profile

tools/install-windows.ps1

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
$ErrorActionPreference = 'Stop'
22

3+
function Invoke-DownloadWithRetry {
4+
param([string]$Uri, [string]$OutFile, [int]$MaxRetries = 10, [int]$RetryDelay = 30)
5+
for ($i = 1; $i -le ($MaxRetries + 1); $i++) {
6+
try {
7+
Invoke-WebRequest $Uri -OutFile $OutFile
8+
return
9+
} catch {
10+
if ($i -gt $MaxRetries) { throw }
11+
Write-Host "Download failed (attempt $i of $($MaxRetries + 1)), retrying in $RetryDelay seconds..."
12+
Start-Sleep -Seconds $RetryDelay
13+
}
14+
}
15+
}
16+
317
# switch to a temp directory
418
cd $env:TEMP
519
[Environment]::CurrentDirectory = $PWD.Path
@@ -11,18 +25,18 @@ $TLREPO = if ($env:CTAN_REPO) { $env:CTAN_REPO } else { 'https://tlnet.yihui.org
1125
$TLURL = "$TLREPO/install-tl.zip"
1226

1327
# download install-tl.zip and unzip it
14-
Invoke-WebRequest $TLURL -OutFile install-tl.zip
28+
Invoke-DownloadWithRetry $TLURL install-tl.zip
1529
Add-Type -A 'System.IO.Compression.FileSystem'
1630
[IO.Compression.ZipFile]::ExtractToDirectory('install-tl.zip', '.')
1731
del install-tl.zip
1832

1933
# download tinytex.profile and modify it (set texdir to ./TinyTeX)
20-
Invoke-WebRequest 'https://tinytex.yihui.org/tinytex.profile' -OutFile tinytex.profile
34+
Invoke-DownloadWithRetry 'https://tinytex.yihui.org/tinytex.profile' tinytex.profile
2135
Add-Content tinytex.profile 'TEXMFCONFIG $TEXMFSYSCONFIG'
2236
Add-Content tinytex.profile 'TEXMFVAR $TEXMFSYSVAR'
2337

2438
# download the custom package list
25-
Invoke-WebRequest 'https://tinytex.yihui.org/pkgs-custom.txt' -OutFile pkgs-custom.txt
39+
Invoke-DownloadWithRetry 'https://tinytex.yihui.org/pkgs-custom.txt' pkgs-custom.txt
2640

2741
# an automated installation of TeX Live (infrastructure only)
2842
cd install-tl-*

0 commit comments

Comments
 (0)