From 48457b9a4b073575df18ec61c3b3f46baed8e6b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Apr 2026 15:54:00 +0000 Subject: [PATCH 1/4] Add retry logic to all download commands in installation scripts Agent-Logs-Url: https://github.com/rstudio/tinytex/sessions/f4c6a244-9b14-4b53-bed3-3245fd7f67e7 Co-authored-by: yihui <163582+yihui@users.noreply.github.com> --- tools/install-base.sh | 8 ++++---- tools/install-bin-unix.sh | 4 ++-- tools/install-bin-windows.ps1 | 16 +++++++++++++++- tools/install-unx.sh | 4 ++-- tools/install-windows.ps1 | 20 +++++++++++++++++--- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tools/install-base.sh b/tools/install-base.sh index 6343d1f90..17c0936e8 100755 --- a/tools/install-base.sh +++ b/tools/install-base.sh @@ -9,12 +9,12 @@ PRNAME="tinytex.profile" PRURL="https://tinytex.yihui.org" if [ $(uname) = 'Darwin' ]; then alias sedi="sed -i ''" - [ -e $TLINST ] || curl -LO $TLURL - [ -e $PRNAME ] || curl -LO $PRURL/$PRNAME + [ -e $TLINST ] || curl -L --retry 10 --retry-delay 30 -O $TLURL + [ -e $PRNAME ] || curl -L --retry 10 --retry-delay 30 -O $PRURL/$PRNAME else alias sedi="sed -i" - [ -e $TLINST ] || wget $TLURL - [ -e $PRNAME ] || wget $PRURL/$PRNAME + [ -e $TLINST ] || wget --tries=11 --waitretry=30 $TLURL + [ -e $PRNAME ] || wget --tries=11 --waitretry=30 $PRURL/$PRNAME # ask `tlmgr path add` to add binaries to ~/bin instead of the default # /usr/local/bin unless this script is invoked with the argument '--admin' # (e.g., users want to make LaTeX binaries available system-wide), in which diff --git a/tools/install-bin-unix.sh b/tools/install-bin-unix.sh index a7be1830f..ea64f1654 100755 --- a/tools/install-bin-unix.sh +++ b/tools/install-bin-unix.sh @@ -99,14 +99,14 @@ if [ "${TINYTEX_INSTALLER#"TinyTeX"}" != "$TINYTEX_INSTALLER" ]; then if [ $OSNAME = 'Darwin' ]; then curl -L -f --retry 10 --retry-delay 30 ${TINYTEX_URL} -o "${INSTALLER_FILE}" else - wget --retry-connrefused --progress=dot:giga -O "${INSTALLER_FILE}" ${TINYTEX_URL} + wget --retry-connrefused --tries=11 --waitretry=30 --progress=dot:giga -O "${INSTALLER_FILE}" ${TINYTEX_URL} fi tar xf "${INSTALLER_FILE}" -C $(dirname $TEXDIR) if [ -n "$1" ]; then mv "${INSTALLER_FILE}" "$1/"; else rm "${INSTALLER_FILE}"; fi else echo "We do not have a prebuilt TinyTeX package for this operating system ($(uname -s) $(uname -m))." echo "I will try to install from source for you instead." - wget --retry-connrefused -O "${INSTALLER_FILE}" ${TINYTEX_URL} + wget --retry-connrefused --tries=11 --waitretry=30 -O "${INSTALLER_FILE}" ${TINYTEX_URL} tar xf "${INSTALLER_FILE}" ./install.sh mkdir -p $TEXDIR diff --git a/tools/install-bin-windows.ps1 b/tools/install-bin-windows.ps1 index 4bcef1455..017c98cae 100644 --- a/tools/install-bin-windows.ps1 +++ b/tools/install-bin-windows.ps1 @@ -1,5 +1,19 @@ $ErrorActionPreference = 'Stop' +function Invoke-DownloadWithRetry { + param([string]$Uri, [string]$OutFile, [int]$MaxRetries = 10, [int]$RetryDelay = 30) + for ($i = 1; $i -le ($MaxRetries + 1); $i++) { + try { + Invoke-WebRequest $Uri -OutFile $OutFile + return + } catch { + if ($i -gt $MaxRetries) { throw } + Write-Host "Download failed (attempt $i of $($MaxRetries + 1)), retrying in $RetryDelay seconds..." + Start-Sleep -Seconds $RetryDelay + } + } +} + # switch to a temp directory cd $env:TEMP [Environment]::CurrentDirectory = $PWD.Path @@ -39,7 +53,7 @@ $DownloadedFile = "$TinyTeXFilename.$BundleExt" # download the bundle Write-Host "Download $BundleExt file..." -Invoke-WebRequest $TinyTeXURL -OutFile $DownloadedFile +Invoke-DownloadWithRetry $TinyTeXURL $DownloadedFile # unzip the downloaded file Write-Host 'Unbundle TinyTeX' diff --git a/tools/install-unx.sh b/tools/install-unx.sh index 39020f806..c5275f7d4 100755 --- a/tools/install-unx.sh +++ b/tools/install-unx.sh @@ -7,10 +7,10 @@ cd ${TMPDIR:-/tmp} if [ $(uname) = 'Darwin' ]; then TEXDIR=${TINYTEX_DIR:-~/Library/TinyTeX} - alias download='curl -sL' + alias download='curl -sL --retry 10 --retry-delay 30' else TEXDIR=${TINYTEX_DIR:-~/.TinyTeX} - alias download='wget -qO-' + alias download='wget -qO- --tries=11 --waitretry=30' fi rm -f install-tl-unx.tar.gz tinytex.profile diff --git a/tools/install-windows.ps1 b/tools/install-windows.ps1 index 406d42018..7e448318b 100644 --- a/tools/install-windows.ps1 +++ b/tools/install-windows.ps1 @@ -1,5 +1,19 @@ $ErrorActionPreference = 'Stop' +function Invoke-DownloadWithRetry { + param([string]$Uri, [string]$OutFile, [int]$MaxRetries = 10, [int]$RetryDelay = 30) + for ($i = 1; $i -le ($MaxRetries + 1); $i++) { + try { + Invoke-WebRequest $Uri -OutFile $OutFile + return + } catch { + if ($i -gt $MaxRetries) { throw } + Write-Host "Download failed (attempt $i of $($MaxRetries + 1)), retrying in $RetryDelay seconds..." + Start-Sleep -Seconds $RetryDelay + } + } +} + # switch to a temp directory cd $env:TEMP [Environment]::CurrentDirectory = $PWD.Path @@ -11,18 +25,18 @@ $TLREPO = if ($env:CTAN_REPO) { $env:CTAN_REPO } else { 'https://tlnet.yihui.org $TLURL = "$TLREPO/install-tl.zip" # download install-tl.zip and unzip it -Invoke-WebRequest $TLURL -OutFile install-tl.zip +Invoke-DownloadWithRetry $TLURL install-tl.zip Add-Type -A 'System.IO.Compression.FileSystem' [IO.Compression.ZipFile]::ExtractToDirectory('install-tl.zip', '.') del install-tl.zip # download tinytex.profile and modify it (set texdir to ./TinyTeX) -Invoke-WebRequest 'https://tinytex.yihui.org/tinytex.profile' -OutFile tinytex.profile +Invoke-DownloadWithRetry 'https://tinytex.yihui.org/tinytex.profile' tinytex.profile Add-Content tinytex.profile 'TEXMFCONFIG $TEXMFSYSCONFIG' Add-Content tinytex.profile 'TEXMFVAR $TEXMFSYSVAR' # download the custom package list -Invoke-WebRequest 'https://tinytex.yihui.org/pkgs-custom.txt' -OutFile pkgs-custom.txt +Invoke-DownloadWithRetry 'https://tinytex.yihui.org/pkgs-custom.txt' pkgs-custom.txt # an automated installation of TeX Live (infrastructure only) cd install-tl-* From 037fab0bb851265e6b5fc282b8a6a09d648142e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 5 Apr 2026 16:27:00 +0000 Subject: [PATCH 2/4] Refactor download commands: capability-based curl/wget, deduplicate into functions, simplify bat Agent-Logs-Url: https://github.com/rstudio/tinytex/sessions/f0fdfcff-e11d-498e-9d8e-f4ee26ded6c1 Co-authored-by: yihui <163582+yihui@users.noreply.github.com> --- tools/install-base.sh | 20 ++++++++++++++++---- tools/install-bin-unix.sh | 20 +++++++++++++------- tools/install-bin-windows.bat | 8 +------- tools/install-unx.sh | 8 ++++++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tools/install-base.sh b/tools/install-base.sh index 17c0936e8..63f81e15b 100755 --- a/tools/install-base.sh +++ b/tools/install-base.sh @@ -7,14 +7,26 @@ TLINST="install-tl-unx.tar.gz" TLURL=$TLREPO/$TLINST PRNAME="tinytex.profile" PRURL="https://tinytex.yihui.org" + +# download a URL and save to its basename; pick curl or wget by availability +download_file() { + if command -v curl > /dev/null 2>&1; then + curl -L -f --retry 10 --retry-delay 30 -O "$1" + else + wget --tries=11 --waitretry=30 "$1" + fi +} + if [ $(uname) = 'Darwin' ]; then alias sedi="sed -i ''" - [ -e $TLINST ] || curl -L --retry 10 --retry-delay 30 -O $TLURL - [ -e $PRNAME ] || curl -L --retry 10 --retry-delay 30 -O $PRURL/$PRNAME else alias sedi="sed -i" - [ -e $TLINST ] || wget --tries=11 --waitretry=30 $TLURL - [ -e $PRNAME ] || wget --tries=11 --waitretry=30 $PRURL/$PRNAME +fi + +[ -e "$TLINST" ] || download_file "$TLURL" +[ -e "$PRNAME" ] || download_file "$PRURL/$PRNAME" + +if [ $(uname) != 'Darwin' ]; then # ask `tlmgr path add` to add binaries to ~/bin instead of the default # /usr/local/bin unless this script is invoked with the argument '--admin' # (e.g., users want to make LaTeX binaries available system-wide), in which diff --git a/tools/install-bin-unix.sh b/tools/install-bin-unix.sh index ea64f1654..248c16d0b 100755 --- a/tools/install-bin-unix.sh +++ b/tools/install-bin-unix.sh @@ -40,6 +40,16 @@ is_musl() { fi } +# download URL to output file; pick curl or wget by availability +# $1 = URL, $2 = output file +download_file() { + if command -v curl > /dev/null 2>&1; then + curl -L -f --retry 10 --retry-delay 30 "$1" -o "$2" + else + wget --retry-connrefused --tries=11 --waitretry=30 -O "$2" "$1" + fi +} + if [ $OSNAME = 'Darwin' ]; then TEXDIR=${TINYTEX_DIR:-~/Library}/TinyTeX else @@ -95,18 +105,14 @@ fi INSTALLER_FILE="${TINYTEX_INSTALLER}${OS_ARCH}.${EXT}" if [ "${TINYTEX_INSTALLER#"TinyTeX"}" != "$TINYTEX_INSTALLER" ]; then - # prebuilt TinyTeX bundle: download with platform-appropriate tool - if [ $OSNAME = 'Darwin' ]; then - curl -L -f --retry 10 --retry-delay 30 ${TINYTEX_URL} -o "${INSTALLER_FILE}" - else - wget --retry-connrefused --tries=11 --waitretry=30 --progress=dot:giga -O "${INSTALLER_FILE}" ${TINYTEX_URL} - fi + # prebuilt TinyTeX bundle + download_file "${TINYTEX_URL}" "${INSTALLER_FILE}" tar xf "${INSTALLER_FILE}" -C $(dirname $TEXDIR) if [ -n "$1" ]; then mv "${INSTALLER_FILE}" "$1/"; else rm "${INSTALLER_FILE}"; fi else echo "We do not have a prebuilt TinyTeX package for this operating system ($(uname -s) $(uname -m))." echo "I will try to install from source for you instead." - wget --retry-connrefused --tries=11 --waitretry=30 -O "${INSTALLER_FILE}" ${TINYTEX_URL} + download_file "${TINYTEX_URL}" "${INSTALLER_FILE}" tar xf "${INSTALLER_FILE}" ./install.sh mkdir -p $TEXDIR diff --git a/tools/install-bin-windows.bat b/tools/install-bin-windows.bat index b28e93abb..f1c6b4125 100644 --- a/tools/install-bin-windows.bat +++ b/tools/install-bin-windows.bat @@ -1,7 +1 @@ -where /q powershell || echo PowerShell not found && exit /b - -cd /d "%TEMP%" - -powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest 'https://tinytex.yihui.org/install-bin-windows.ps1' -OutFile 'install-bin-windows.ps1'" -powershell -ExecutionPolicy Bypass -File "install-bin-windows.ps1" %* -del "install-bin-windows.ps1" +powershell -ExecutionPolicy Bypass -Command "irm 'https://tinytex.yihui.org/install-bin-windows.ps1' | iex" diff --git a/tools/install-unx.sh b/tools/install-unx.sh index c5275f7d4..9d6d44539 100755 --- a/tools/install-unx.sh +++ b/tools/install-unx.sh @@ -7,10 +7,14 @@ cd ${TMPDIR:-/tmp} if [ $(uname) = 'Darwin' ]; then TEXDIR=${TINYTEX_DIR:-~/Library/TinyTeX} - alias download='curl -sL --retry 10 --retry-delay 30' else TEXDIR=${TINYTEX_DIR:-~/.TinyTeX} - alias download='wget -qO- --tries=11 --waitretry=30' +fi + +if command -v curl > /dev/null 2>&1; then + download() { curl -sL --retry 10 --retry-delay 30 "$1"; } +else + download() { wget -qO- --tries=11 --waitretry=30 "$1"; } fi rm -f install-tl-unx.tar.gz tinytex.profile From fc258f1e0575da2f246b65dc68f917ebef18783e Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Sun, 5 Apr 2026 11:37:37 -0500 Subject: [PATCH 3/4] Enhance wget command with progress indicator --- tools/install-bin-unix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-bin-unix.sh b/tools/install-bin-unix.sh index 248c16d0b..ac53025ce 100755 --- a/tools/install-bin-unix.sh +++ b/tools/install-bin-unix.sh @@ -46,7 +46,7 @@ download_file() { if command -v curl > /dev/null 2>&1; then curl -L -f --retry 10 --retry-delay 30 "$1" -o "$2" else - wget --retry-connrefused --tries=11 --waitretry=30 -O "$2" "$1" + wget --retry-connrefused --tries=11 --waitretry=30 --progress=dot:giga -O "$2" "$1" fi } From 13fbd7b9af257b1bf4ab81f585dd484425ca4f4b Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Sun, 5 Apr 2026 11:44:35 -0500 Subject: [PATCH 4/4] Download installer once before branching Avoid duplicate downloads by performing download once before OS branch --- tools/install-bin-unix.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/install-bin-unix.sh b/tools/install-bin-unix.sh index ac53025ce..a618f0421 100755 --- a/tools/install-bin-unix.sh +++ b/tools/install-bin-unix.sh @@ -104,15 +104,14 @@ fi INSTALLER_FILE="${TINYTEX_INSTALLER}${OS_ARCH}.${EXT}" +download_file "${TINYTEX_URL}" "${INSTALLER_FILE}" if [ "${TINYTEX_INSTALLER#"TinyTeX"}" != "$TINYTEX_INSTALLER" ]; then # prebuilt TinyTeX bundle - download_file "${TINYTEX_URL}" "${INSTALLER_FILE}" tar xf "${INSTALLER_FILE}" -C $(dirname $TEXDIR) if [ -n "$1" ]; then mv "${INSTALLER_FILE}" "$1/"; else rm "${INSTALLER_FILE}"; fi else echo "We do not have a prebuilt TinyTeX package for this operating system ($(uname -s) $(uname -m))." echo "I will try to install from source for you instead." - download_file "${TINYTEX_URL}" "${INSTALLER_FILE}" tar xf "${INSTALLER_FILE}" ./install.sh mkdir -p $TEXDIR