Skip to content

Commit

Permalink
Attempting ollama install system-wide 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mecattaf committed Dec 5, 2024
1 parent 63712c4 commit 6e03a72
Showing 1 changed file with 21 additions and 56 deletions.
77 changes: 21 additions & 56 deletions files/scripts/install-ollama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ set -oue pipefail
status() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] >>> $*" >&2; }
error() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $*"; exit 1; }

# Check for required commands
for cmd in curl tar install mkdir; do
if ! command -v "$cmd" >/dev/null 2>&1; then
error "Required command '$cmd' not found. Please install it first."
fi
done

# Create and manage temporary workspace with verbose logging
# Create temporary workspace
TEMP_DIR=$(mktemp -d)
status "Created temporary directory: $TEMP_DIR"
cleanup() {
Expand All @@ -30,19 +23,16 @@ cleanup() {
}
trap cleanup EXIT

# Verify we're on Linux
if [ "$(uname -s)" != "Linux" ]; then
error 'This script is intended to run on Linux only.'
fi
# Verify platform
[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.'

# Check and verify architecture
# Check architecture
ARCH=$(uname -m)
status "Detected architecture: $ARCH"

case "$ARCH" in
x86_64)
ARCH="amd64"
status "Converting architecture name to: $ARCH"
status "Converting architecture name to: amd64"
;;
*)
error "This script only supports x86_64 architecture. Detected: $ARCH"
Expand All @@ -57,50 +47,31 @@ else
status "No specific version specified, using latest"
fi

# Set installation directory
# Set and create installation directory
BINDIR="/usr/bin"
status "Target installation directory: $BINDIR"
install -o0 -g0 -m755 -d "$BINDIR" || error "Failed to create installation directory"

# Create installation directory with error checking
status "Creating installation directory"
if ! install -o0 -g0 -m755 -d "$BINDIR"; then
error "Failed to create installation directory: $BINDIR"
fi

# First attempt: Try downloading and extracting the bundle
# Download and extract the bundle
BUNDLE_URL="https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}"
status "Attempting to download bundle from: $BUNDLE_URL"
status "Downloading bundle from: $BUNDLE_URL"

if curl -I --silent --fail --location "$BUNDLE_URL" >/dev/null; then
status "Downloading Linux ${ARCH} bundle"
if ! curl --fail --show-error --location --progress-bar "$BUNDLE_URL" | tar -xvzf - -C "$TEMP_DIR"; then
error "Failed to download or extract bundle"
fi

status "Listing contents of temporary directory:"
ls -la "$TEMP_DIR"

if [ ! -f "$TEMP_DIR/ollama" ]; then
status "Bundle extraction didn't produce expected binary, falling back to direct binary download"
# Fallback to direct binary download
BINARY_URL="https://ollama.com/download/ollama-linux-${ARCH}${VER_PARAM}"
status "Downloading standalone binary from: $BINARY_URL"
if ! curl --fail --show-error --location --progress-bar "$BINARY_URL" -o "$TEMP_DIR/ollama"; then
error "Failed to download standalone binary"
fi
fi
# Extract with verbose logging to see the actual paths
if ! curl --fail --show-error --location --progress-bar "$BUNDLE_URL" | tar -xvzf - -C "$TEMP_DIR"; then
error "Failed to download or extract bundle"
fi

# Find the ollama binary in the extracted contents
if [ -f "$TEMP_DIR/bin/ollama" ]; then
status "Found ollama binary at bin/ollama"
OLLAMA_PATH="$TEMP_DIR/bin/ollama"
else
# Direct binary download if bundle is not available
BINARY_URL="https://ollama.com/download/ollama-linux-${ARCH}${VER_PARAM}"
status "Bundle not available, downloading standalone binary from: $BINARY_URL"
if ! curl --fail --show-error --location --progress-bar "$BINARY_URL" -o "$TEMP_DIR/ollama"; then
error "Failed to download standalone binary"
fi
error "Could not locate ollama binary in extracted archive"
fi

# Install the binary
status "Installing ollama binary to $BINDIR"
if ! install -v -o0 -g0 -m755 "$TEMP_DIR/ollama" "$BINDIR/ollama"; then
if ! install -v -o0 -g0 -m755 "$OLLAMA_PATH" "$BINDIR/ollama"; then
error "Failed to install ollama binary"
fi

Expand All @@ -109,11 +80,5 @@ if [ ! -x "$BINDIR/ollama" ]; then
error "Installation verification failed - binary is not executable"
fi

# Verify binary architecture
BINARY_ARCH=$(file "$BINDIR/ollama" | grep -o "x86-64\|amd64" || echo "unknown")
status "Installed binary architecture: $BINARY_ARCH"
if [[ "$BINARY_ARCH" != "x86-64" && "$BINARY_ARCH" != "amd64" ]]; then
error "Installed binary architecture mismatch: expected x86-64/amd64, got $BINARY_ARCH"
fi

status "Ollama installation completed successfully"

0 comments on commit 6e03a72

Please sign in to comment.