From a18eb1292e6ddae0d22af3e9caaa609d7f04e51b Mon Sep 17 00:00:00 2001 From: Eric Platon Date: Wed, 6 Aug 2025 09:42:02 +0900 Subject: [PATCH 1/3] 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." From 20e5c74316311c17e54968f2f693b50f20210744 Mon Sep 17 00:00:00 2001 From: Eric Platon Date: Wed, 6 Aug 2025 10:42:57 +0900 Subject: [PATCH 2/3] Add missing trap handlers Based on https://unix.stackexchange.com/a/512333 --- scripts/install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index ea308274c..0ea9916a8 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -26,6 +26,9 @@ cleanup () { fi } trap 'status=$?; cleanup; exit $status' EXIT +trap 'trap - HUP; cleanup SIGHUP; kill -HUP $$' HUP +trap 'trap - INT; cleanup SIGINT; kill -INT $$' INT +trap 'trap - TERM; cleanup SIGTERM; kill -TERM $$' TERM available() { command -v $1 >/dev/null; } require() { From 5b63d8190cf1fe41b053083faf067324bfb1bf9c Mon Sep 17 00:00:00 2001 From: Eric Platon Date: Wed, 6 Aug 2025 10:50:02 +0900 Subject: [PATCH 3/3] Fix EXIT trap function call The function call is valid, but the script uses `set -u`, so function calls without "optional" arguments trigger errors. --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 0ea9916a8..a2bcc25d6 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -25,7 +25,7 @@ cleanup () { rmdir --ignore-fail-on-non-empty $TEMP_ROOT_DIR || true fi } -trap 'status=$?; cleanup; exit $status' EXIT +trap 'status=$?; cleanup ""; exit $status' EXIT trap 'trap - HUP; cleanup SIGHUP; kill -HUP $$' HUP trap 'trap - INT; cleanup SIGINT; kill -INT $$' INT trap 'trap - TERM; cleanup SIGTERM; kill -TERM $$' TERM