s/available/runnable/

This commit is contained in:
Michael Yang 2023-11-21 17:10:28 -08:00
parent b84115f777
commit c36eca97ae

View File

@ -8,11 +8,11 @@ status() { echo ">>> $*" >&2; }
error() { echo "ERROR $*"; exit 1; } error() { echo "ERROR $*"; exit 1; }
warning() { echo "WARNING: $*"; } warning() { echo "WARNING: $*"; }
available() { command -v "$1" >/dev/null; } runnable() { command -v "$1" >/dev/null; }
require() { require() {
MISSING='' MISSING=''
for TOOL in "$@"; do for TOOL in "$@"; do
if ! available "$TOOL"; then if ! runnable "$TOOL"; then
MISSING="$MISSING $TOOL" MISSING="$MISSING $TOOL"
fi fi
done done
@ -32,7 +32,7 @@ esac
SUDO= 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 ! available sudo; then if ! runnable sudo; then
error "This script requires superuser permissions. Please re-run as root." error "This script requires superuser permissions. Please re-run as root."
fi fi
@ -53,11 +53,11 @@ cleanup() {
EXIT_CODE=$? EXIT_CODE=$?
rm -rf "$TEMP_DIR" rm -rf "$TEMP_DIR"
if available nvidia-smi && lsmod | grep -qv nvidia; then if runnable nvidia-smi && lsmod | grep -qv nvidia; then
status 'Reboot to complete NVIDIA CUDA driver install.' status 'Reboot to complete NVIDIA CUDA driver install.'
fi fi
if available systemctl >/dev/null; then if runnable systemctl >/dev/null; then
$SUDO systemctl restart ollama $SUDO systemctl restart ollama
timeout 10 sh -c 'while :; do [ "$(curl -s http://127.0.0.1:11434)" = "Ollama is running" ] && break; sleep 0.2; done' \ timeout 10 sh -c 'while :; do [ "$(curl -s http://127.0.0.1:11434)" = "Ollama is running" ] && break; sleep 0.2; done' \
@ -65,7 +65,7 @@ cleanup() {
|| true || true
fi fi
if available ollama; then if runnable ollama; then
status 'Install completed. Run "ollama --help" to get started.' status 'Install completed. Run "ollama --help" to get started.'
fi fi
@ -121,15 +121,15 @@ EOF
esac esac
} }
if available systemctl; then if runnable systemctl; then
configure_systemd configure_systemd
fi fi
check_gpu() { check_gpu() {
case $1 in case $1 in
lspci) available lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;; lspci) runnable lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;;
lshw) available lshw && $SUDO lshw -c display -numeric | grep -q 'vendor: .* \[10DE\]' || return 1 ;; lshw) runnable lshw && $SUDO lshw -c display -numeric | grep -q 'vendor: .* \[10DE\]' || return 1 ;;
nvidia-smi) available nvidia-smi || return 1 ;; nvidia-smi) runnable nvidia-smi || return 1 ;;
esac esac
} }
@ -138,7 +138,7 @@ if check_gpu nvidia-smi; then
exit exit
fi fi
if ! available lspci && ! available lshw; then if ! runnable lspci && ! runnable lshw; then
warning "Unable to detect NVIDIA GPU. Install lspci or lshw to automatically detect and install NVIDIA CUDA drivers." warning "Unable to detect NVIDIA GPU. Install lspci or lshw to automatically detect and install NVIDIA CUDA drivers."
exit exit
fi fi
@ -217,7 +217,7 @@ OS_VERSION=$VERSION_ID
PACKAGE_MANAGER= PACKAGE_MANAGER=
for PACKAGE_MANAGER in dnf yum apt-get; do for PACKAGE_MANAGER in dnf yum apt-get; do
if available $PACKAGE_MANAGER; then if runnable $PACKAGE_MANAGER; then
break break
fi fi
done done