fix minor install script issues on debian

This commit is contained in:
Jeffrey Morgan 2023-09-23 10:25:47 -04:00
parent cbc40aa996
commit e29662ab5c

View file

@ -30,12 +30,14 @@ case "$(uname -m)" in
*) error "Unsupported architecture: $ARCH" ;; *) error "Unsupported architecture: $ARCH" ;;
esac esac
SUDO_CMD= SUDO=
if [ "$(id -u)" -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
# Running as root, no need for sudo # Running as root, no need for sudo
if ! command -v sudo >/dev/null; then if ! command -v sudo >/dev/null; then
error "Ollama install.sh requires elevated privileges. Please re-run as root." error "Ollama install.sh requires elevated privileges. Please re-run as root."
fi fi
SUDO="sudo"
fi fi
MISSING_TOOLS=$(required_tools curl awk grep sed tee xargs) MISSING_TOOLS=$(required_tools curl awk grep sed tee xargs)
@ -44,11 +46,11 @@ if [ -n "$MISSING_TOOLS" ]; then
fi fi
status "Downloading ollama..." status "Downloading ollama..."
$SUDO_CMD curl -fsSL -o $TEMP_DIR/ollama "https://ollama.ai/download/ollama-linux-$ARCH" $SUDO curl -fsSL -o $TEMP_DIR/ollama "https://ollama.ai/download/ollama-linux-$ARCH"
status "Installing ollama to /usr/bin..." status "Installing ollama to /usr/bin..."
$SUDO_CMD install -o0 -g0 -m755 -d /usr/bin $SUDO install -o0 -g0 -m755 -d /usr/bin
$SUDO_CMD install -o0 -g0 -m755 $TEMP_DIR/ollama /usr/bin/ollama $SUDO install -o0 -g0 -m755 $TEMP_DIR/ollama /usr/bin/ollama
install_success() { status 'Install complete. Run "ollama" from the command line.'; } install_success() { status 'Install complete. Run "ollama" from the command line.'; }
trap install_success EXIT trap install_success EXIT
@ -58,11 +60,11 @@ trap install_success EXIT
configure_systemd() { configure_systemd() {
if ! id ollama >/dev/null 2>&1; then if ! id ollama >/dev/null 2>&1; then
status "Creating ollama user..." status "Creating ollama user..."
$SUDO_CMD useradd -r -s /bin/false -m -d /usr/share/ollama ollama $SUDO useradd -r -s /bin/false -m -d /usr/share/ollama ollama
fi fi
status "Creating ollama systemd service..." status "Creating ollama systemd service..."
cat <<EOF | $SUDO_CMD tee /etc/systemd/system/ollama.service >/dev/null cat <<EOF | $SUDO tee /etc/systemd/system/ollama.service >/dev/null
[Unit] [Unit]
Description=Ollama Service Description=Ollama Service
After=network-online.target After=network-online.target
@ -80,9 +82,9 @@ WantedBy=default.target
EOF EOF
if [ "$(systemctl is-system-running || echo 'not running')" = 'running' ]; then if [ "$(systemctl is-system-running || echo 'not running')" = 'running' ]; then
status "Enabling and starting ollama service..." status "Enabling and starting ollama service..."
$SUDO_CMD systemctl daemon-reload $SUDO systemctl daemon-reload
$SUDO_CMD systemctl enable ollama $SUDO systemctl enable ollama
$SUDO_CMD systemctl restart ollama $SUDO systemctl restart ollama
fi fi
} }
@ -111,11 +113,11 @@ install_cuda_driver_yum() {
status 'Installing NVIDIA repository...' status 'Installing NVIDIA repository...'
case $PACKAGE_MANAGER in case $PACKAGE_MANAGER in
yum) yum)
$SUDO_CMD $PACKAGE_MANAGER -y install yum-utils $SUDO $PACKAGE_MANAGER -y install yum-utils
$SUDO_CMD $PACKAGE_MANAGER-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo $SUDO $PACKAGE_MANAGER-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo
;; ;;
dnf) dnf)
$SUDO_CMD dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo $SUDO dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo
;; ;;
esac esac
@ -123,16 +125,16 @@ install_cuda_driver_yum() {
rhel) rhel)
status 'Installing EPEL repository...' status 'Installing EPEL repository...'
# EPEL is required for third-party dependencies such as dkms and libvdpau # EPEL is required for third-party dependencies such as dkms and libvdpau
$SUDO_CMD $PACKAGE_MANAGER -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$2.noarch.rpm $SUDO $PACKAGE_MANAGER -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$2.noarch.rpm
;; ;;
esac esac
status 'Installing CUDA driver...' status 'Installing CUDA driver...'
$SUDO_CMD $PACKAGE_MANAGER -y update $SUDO $PACKAGE_MANAGER -y update
$SUDO_CMD $PACKAGE_MANAGER -y install cuda-drivers $SUDO $PACKAGE_MANAGER -y install cuda-drivers
if [ "$1" = 'centos' ] || [ "$1$2" = 'rhel7' ]; then if [ "$1" = 'centos' ] || [ "$1$2" = 'rhel7' ]; then
$SUDO_CMD $PACKAGE_MANAGER -y install nvidia-driver-latest-dkms $SUDO $PACKAGE_MANAGER -y install nvidia-driver-latest-dkms
fi fi
} }
@ -145,14 +147,14 @@ install_cuda_driver_apt() {
case $1 in case $1 in
debian) debian)
status 'Enabling contrib sources...' status 'Enabling contrib sources...'
sed 's/main/contrib/' </etc/apt/sources.list >/etc/apt/sources.list.d/contrib.list $SUDO sed 's/main/contrib/' < /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/contrib.list > /dev/null
;; ;;
esac esac
status 'Installing CUDA driver...' status 'Installing CUDA driver...'
$SUDO_CMD dpkg -i $TEMP_DIR/cuda-keyring.deb $SUDO dpkg -i $TEMP_DIR/cuda-keyring.deb
$SUDO_CMD apt-get update $SUDO apt-get update
$SUDO_CMD apt-get -y install cuda-drivers DEBIAN_FRONTEND=noninteractive $SUDO apt-get -y install cuda-drivers -q
} }
if [ ! -f "/etc/os-release" ]; then if [ ! -f "/etc/os-release" ]; then
@ -187,10 +189,10 @@ fi
if ! lsmod | grep -q nvidia; then if ! lsmod | grep -q nvidia; then
KERNEL_RELEASE="$(uname -r)" KERNEL_RELEASE="$(uname -r)"
case $OS_NAME in case $OS_NAME in
centos|rhel|rocky|fedora) $SUDO_CMD $PACKAGE_MANAGER -y install kernel-devel-$KERNEL_RELEASE kernel-headers-$KERNEL_RELEASE ;; centos|rhel|rocky|fedora) $SUDO $PACKAGE_MANAGER -y install kernel-devel-$KERNEL_RELEASE kernel-headers-$KERNEL_RELEASE ;;
debian|ubuntu) $SUDO_CMD apt-get -y install linux-headers-$KERNEL_RELEASE ;; debian|ubuntu) $SUDO apt-get -y install linux-headers-$KERNEL_RELEASE ;;
esac esac
$SUDO_CMD dkms status | awk -F: '/added/ { print $1 }' | xargs -n1 $SUDO_CMD dkms install $SUDO dkms status | awk -F: '/added/ { print $1 }' | xargs -n1 $SUDO dkms install
$SUDO_CMD modprobe nvidia $SUDO modprobe nvidia
fi fi