Skip to content

Commit

Permalink
调整
Browse files Browse the repository at this point in the history
  • Loading branch information
gfdgd-xi committed Jan 31, 2025
1 parent a673dde commit 571b80c
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/program-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ on:
- "*"

jobs:
call:
uses: GXDE-OS/GXDE/.github/workflows/building-deb.yml@master
sid:
uses: GXDE-OS/GXDE/.github/workflows/building-deb-sid.yml@master
secrets: inherit

tianlu-bpo:
uses: GXDE-OS/GXDE/.github/workflows/building-deb-backport.yml@master
secrets: inherit

meimei:
uses: GXDE-OS/GXDE/.github/workflows/building-deb-meimei.yml@master
secrets: inherit
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build:
export GO111MODULE=on
GO111MODULE=on go mod tidy
GO111MODULE=on go generate ../...
GO111MODULE=on go build ..
GO111MODULE=on go generate ./...
GO111MODULE=on go build .

install:
make build -j4
Expand Down
137 changes: 137 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash


TEMP_DIR=$(mktemp -d)

status() { echo ">>> $*" >&2; }
error() { echo "${red}ERROR:${plain} $*"; exit 1; }
warning() { echo "${red}WARNING:${plain} $*"; }
cleanup() { rm -rf $TEMP_DIR; }
available() { command -v $1 >/dev/null; }

BINDIR=/bin
IS_WSL2=false

KERN=$(uname -r)
case "$KERN" in
*icrosoft*WSL2 | *icrosoft*wsl2) IS_WSL2=true;;
*icrosoft) error "Microsoft WSL1 is not currently supported. Please use WSL2 with 'wsl --set-version <distro> 2'" ;;
*) ;;
esac


install_success() {
status 'The Ollama API is now available at 127.0.0.1:11434.'
status 'Install complete. Run "ollama" from the command line.'
}
trap install_success EXIT

# Everything from this point onwards is optional.

configure_systemd() {
if ! id ollama >/dev/null 2>&1; then
status "Creating ollama user..."
$SUDO useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama
fi
if getent group render >/dev/null 2>&1; then
status "Adding ollama user to render group..."
$SUDO usermod -a -G render ollama
fi
if getent group video >/dev/null 2>&1; then
status "Adding ollama user to video group..."
$SUDO usermod -a -G video ollama
fi

status "Adding current user to ollama group..."
$SUDO usermod -a -G ollama $(whoami)

status "Creating ollama systemd service..."
cat <<EOF | $SUDO tee /etc/systemd/system/ollama.service >/dev/null
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=$BINDIR/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
[Install]
WantedBy=default.target
EOF
SYSTEMCTL_RUNNING="$(systemctl is-system-running || true)"
case $SYSTEMCTL_RUNNING in
running|degraded)
status "Enabling and starting ollama service..."
$SUDO systemctl daemon-reload
$SUDO systemctl enable ollama

start_service() { $SUDO systemctl restart ollama; }
trap start_service EXIT
;;
*)
warning "systemd is not running"
if [ "$IS_WSL2" = true ]; then
warning "see https://learn.microsoft.com/en-us/windows/wsl/systemd#how-to-enable-systemd to enable it"
fi
;;
esac
}

if available systemctl; then
configure_systemd
fi

# WSL2 only supports GPUs via nvidia passthrough
# so check for nvidia-smi to determine if GPU is available
if [ "$IS_WSL2" = true ]; then
if available nvidia-smi && [ -n "$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")" ]; then
status "Nvidia GPU detected."
fi
install_success
exit 0
fi

# Don't attempt to install drivers on Jetson systems
if [ -f /etc/nv_tegra_release ] ; then
status "NVIDIA JetPack ready."
install_success
exit 0
fi

# Install GPU dependencies on Linux
if ! available lspci && ! available lshw; then
warning "Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies."
exit 0
fi

check_gpu() {
# Look for devices based on vendor ID for NVIDIA and AMD
case $1 in
lspci)
case $2 in
nvidia) available lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;;
amdgpu) available lspci && lspci -d '1002:' | grep -q 'AMD' || return 1 ;;
esac ;;
lshw)
case $2 in
nvidia) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[10DE\]' || return 1 ;;
amdgpu) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[1002\]' || return 1 ;;
esac ;;
nvidia-smi) available nvidia-smi || return 1 ;;
esac
}

if check_gpu nvidia-smi; then
status "NVIDIA GPU installed."
exit 0
fi

if ! check_gpu lspci nvidia && ! check_gpu lshw nvidia && ! check_gpu lspci amdgpu && ! check_gpu lshw amdgpu; then
install_success
warning "No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode."
exit 0
fi
2 changes: 2 additions & 0 deletions debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo rm -rfv /etc/systemd/system/ollama.service
2 changes: 2 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
%:
dh $@

override_dh_dwz:
true

# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
Expand Down

0 comments on commit 571b80c

Please sign in to comment.