From a18eb1292e6ddae0d22af3e9caaa609d7f04e51b Mon Sep 17 00:00:00 2001 From: Eric Platon Date: Wed, 6 Aug 2025 09:42:02 +0900 Subject: [PATCH] Make download resuming possible on large files This change modifies the pattern to cURL and pipe into TAR, so that cURL resumption on network error works properly. The new pattern is for cURL to download to an actual (resumable) file. Three spots affected in the install script, assumedly the only three large file downloads. The cleanup logic is also extended to keep files around in a temp directory, until full success of the script. The temp directory needs a predictable name, so the script does not use `mktemp` anymore. --- scripts/install.sh | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 9c232400f..ea308274c 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,9 +11,21 @@ status() { echo ">>> $*" >&2; } error() { echo "${red}ERROR:${plain} $*"; exit 1; } warning() { echo "${red}WARNING:${plain} $*"; } -TEMP_DIR=$(mktemp -d) -cleanup() { rm -rf $TEMP_DIR; } -trap cleanup EXIT +TEMP_ROOT_DIR=/tmp/ollama +TEMP_DIR=${TEMP_ROOT_DIR}/install +mkdir -p $TEMP_DIR +cleanup () { + if [ -n "$1" ]; then + >&2 echo "Aborted by $1" + elif [ $status -ne 0 ]; then + >&2 echo "Failure (status $status). Current progress can be resumed and available in ${TEMP_DIR}" + else + rm -rf $TEMP_DIR + # If install is the only tmp content, remove all traces + rmdir --ignore-fail-on-non-empty $TEMP_ROOT_DIR || true + fi +} +trap 'status=$?; cleanup; exit $status' EXIT available() { command -v $1 >/dev/null; } require() { @@ -80,8 +92,9 @@ $SUDO install -o0 -g0 -m755 -d $BINDIR $SUDO install -o0 -g0 -m755 -d "$OLLAMA_INSTALL_DIR/lib/ollama" status "Downloading Linux ${ARCH} bundle" curl --fail --show-error --location --progress-bar \ - "https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" | \ - $SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR" + --output-dir $TEMP_DIR --continue-at - --remote-name \ + "https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" +$SUDO tar -xzf "${TEMP_DIR}/ollama-linux-${ARCH}.tgz${VER_PARAM}" -C "$OLLAMA_INSTALL_DIR" if [ "$OLLAMA_INSTALL_DIR/bin/ollama" != "$BINDIR/ollama" ] ; then status "Making ollama accessible in the PATH in $BINDIR" @@ -93,13 +106,15 @@ if [ -f /etc/nv_tegra_release ] ; then if grep R36 /etc/nv_tegra_release > /dev/null ; then status "Downloading JetPack 6 components" curl --fail --show-error --location --progress-bar \ - "https://ollama.com/download/ollama-linux-${ARCH}-jetpack6.tgz${VER_PARAM}" | \ - $SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR" + --output-dir $TEMP_DIR --continue-at - --remote-name \ + "https://ollama.com/download/ollama-linux-${ARCH}-jetpack6.tgz${VER_PARAM}" + $SUDO tar -xzf "${TEMP_DIR}/ollama-linux-${ARCH}.tgz${VER_PARAM}" -C "$OLLAMA_INSTALL_DIR" elif grep R35 /etc/nv_tegra_release > /dev/null ; then status "Downloading JetPack 5 components" curl --fail --show-error --location --progress-bar \ - "https://ollama.com/download/ollama-linux-${ARCH}-jetpack5.tgz${VER_PARAM}" | \ - $SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR" + --output-dir $TEMP_DIR --continue-at - --remote-name \ + "https://ollama.com/download/ollama-linux-${ARCH}-jetpack5.tgz${VER_PARAM}" + $SUDO tar -xzf "${TEMP_DIR}/ollama-linux-${ARCH}-jetpack5.tgz${VER_PARAM}" -C "$OLLAMA_INSTALL_DIR" else warning "Unsupported JetPack version detected. GPU may not be supported" fi @@ -224,8 +239,9 @@ fi if check_gpu lspci amdgpu || check_gpu lshw amdgpu; then status "Downloading Linux ROCm ${ARCH} bundle" curl --fail --show-error --location --progress-bar \ - "https://ollama.com/download/ollama-linux-${ARCH}-rocm.tgz${VER_PARAM}" | \ - $SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR" + --output-dir $TEMP_DIR --continue-at - --remote-name \ + "https://ollama.com/download/ollama-linux-${ARCH}-rocm.tgz${VER_PARAM}" + $SUDO tar -xzf "${TEMP_DIR}/ollama-linux-${ARCH}-rocm.tgz${VER_PARAM}" -C "$OLLAMA_INSTALL_DIR" install_success status "AMD GPU ready."