Skip to content

Commit

Permalink
Attempting ollama install system-wide 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mecattaf committed Dec 5, 2024
1 parent 1cba65a commit 99f500c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 44 deletions.
73 changes: 31 additions & 42 deletions files/scripts/install-ollama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,15 @@

set -oue pipefail

# Keep the original script's status/error functions for consistent output
red="$( (/usr/bin/tput bold || :; /usr/bin/tput setaf 1 || :) 2>&-)"
plain="$( (/usr/bin/tput sgr0 || :) 2>&-)"
# Simple status and error reporting
status() { echo ">>> $*" >&2; }
error() { echo "${red}ERROR:${plain} $*"; exit 1; }
error() { echo "ERROR: $*"; exit 1; }

# Create and manage temporary workspace
TEMP_DIR=$(mktemp -d)
cleanup() { rm -rf $TEMP_DIR; }
cleanup() { rm -rf "$TEMP_DIR"; }
trap cleanup EXIT

# Utility functions from original script
available() { command -v $1 >/dev/null; }
require() {
local MISSING=''
for TOOL in $*; do
if ! available $TOOL; then
MISSING="$MISSING $TOOL"
fi
done
echo $MISSING
}

# Check platform and architecture
[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.'
ARCH=$(uname -m)
Expand All @@ -43,35 +30,37 @@ esac
# Version parameter handling from original script
VER_PARAM="${OLLAMA_VERSION:+?version=$OLLAMA_VERSION}"

# Check for required tools
NEEDS=$(require curl grep)
if [ -n "$NEEDS" ]; then
status "ERROR: The following tools are required but missing:"
for NEED in $NEEDS; do
echo " - $NEED"
done
exit 1
fi

# Determine installation directory
for BINDIR in /usr/local/bin /usr/bin /bin; do
echo $PATH | grep -q $BINDIR && break || continue
done
OLLAMA_INSTALL_DIR=$(dirname ${BINDIR})
# Set installation directory - using /usr/bin for atomic system compatibility
BINDIR="/usr/bin"

# Install binary
status "Installing ollama to $OLLAMA_INSTALL_DIR"
status "Installing ollama to $BINDIR"
install -o0 -g0 -m755 -d $BINDIR
install -o0 -g0 -m755 -d "$OLLAMA_INSTALL_DIR"

status "Downloading Linux ${ARCH} bundle"
curl --fail --show-error --location --progress-bar \
"https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" | \
tar -xzf - -C "$OLLAMA_INSTALL_DIR"
# Try bundle first, fallback to standalone binary if bundle fails
if curl -I --silent --fail --location "https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" >/dev/null ; then
status "Downloading Linux ${ARCH} bundle"
curl --fail --show-error --location --progress-bar \
"https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" | \
tar -xzf - -C "$TEMP_DIR"

if [ ! -f "$TEMP_DIR/ollama" ]; then
error "Ollama binary not found in extracted archive"
fi

install -v -o0 -g0 -m755 "$TEMP_DIR/ollama" "$BINDIR/ollama"
else
status "Downloading Linux ${ARCH} CLI"
curl --fail --show-error --location --progress-bar \
"https://ollama.com/download/ollama-linux-${ARCH}${VER_PARAM}" \
-o "$TEMP_DIR/ollama"

install -v -o0 -g0 -m755 "$TEMP_DIR/ollama" "$BINDIR/ollama"
fi

if [ "$OLLAMA_INSTALL_DIR/bin/ollama" != "$BINDIR/ollama" ] ; then
status "Making ollama accessible in the PATH in $BINDIR"
ln -sf "$OLLAMA_INSTALL_DIR/ollama" "$BINDIR/ollama"
# Verify successful installation
if [ ! -x "$BINDIR/ollama" ]; then
error "Installation verification failed"
fi

status "Ollama installation complete."
status "Ollama installation complete"
4 changes: 2 additions & 2 deletions files/systemd/system/ollama.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/ollama serve
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
Environment="PATH=/usr/bin:/bin"

[Install]
WantedBy=multi-user.target

0 comments on commit 99f500c

Please sign in to comment.