dotfiles/.local/bin/podllama

55 lines
1.1 KiB
Bash
Executable file

#! /usr/bin/bash
set -euo pipefail
IFS=$'\n\t'
if ! PARSED_OPTIONS=$(getopt -o "" --long "offline,volatile" --name "$0" -- "$@"); then
echo "Error parsing options." >&2
exit 1
fi
eval set -- "$PARSED_OPTIONS"
offline=false
volatile=false
while true; do
case "$1" in
--offline)
offline=true
shift
;;
--volatile)
volatile=true
shift
;;
--)
shift
break
;;
*)
echo "Internal error!" >&2
exit 1
;;
esac
done
mkdir --parents ~/.local/share/ollama/
if [[ "true" == "${volatile}" ]]; then
PODMAN=(podman --transient-store)
MOUNTS=()
else
PODMAN=(podman)
MOUNTS=(--volume ~/.local/share/ollama/:/root/.ollama)
fi
if [[ "true" == "${offline}" ]]; then
NETWORK=(--network none)
else
NETWORK=()
fi
pod_id=$("${PODMAN[@]}" run --detach --rm "${MOUNTS[@]}" "${NETWORK[@]}" ollama:latest)
"${PODMAN[@]}" exec --interactive --tty "${pod_id}" ollama "$@"
"${PODMAN[@]}" kill "${pod_id}" > /dev/null