diff --git a/scripts/install.sh b/scripts/install.sh index 9c232400f..a2bcc25d6 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,9 +11,24 @@ 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 +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() { @@ -80,8 +95,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 +109,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 +242,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."