diff --git a/tools/install-base.sh b/tools/install-base.sh index 6343d1f90..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 -LO $TLURL - [ -e $PRNAME ] || curl -LO $PRURL/$PRNAME else alias sedi="sed -i" - [ -e $TLINST ] || wget $TLURL - [ -e $PRNAME ] || wget $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 a7be1830f..a618f0421 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 --progress=dot:giga -O "$2" "$1" + fi +} + if [ $OSNAME = 'Darwin' ]; then TEXDIR=${TINYTEX_DIR:-~/Library}/TinyTeX else @@ -94,19 +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 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 --progress=dot:giga -O "${INSTALLER_FILE}" ${TINYTEX_URL} - fi + # prebuilt TinyTeX bundle 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} 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-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..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' else TEXDIR=${TINYTEX_DIR:-~/.TinyTeX} - alias download='wget -qO-' +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 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-*