ollama-models/install.sh
2025-04-03 12:17:04 +01:00

66 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
usage(){
echo "Usage: $(basename $0) {model file|all|list}"
exit 1
}
installAll(){
echo "Installing ALL model files..."
# Install all the files
for file in */*; do
res=$(checkExists $(basename $file))
if [[ $? -lt 1 ]]; then
echo "Installing model: $(basename $file)"
ollama create $(basename ${file}) -f ${file}
else
echo "$(basename $file) already exists, skipping."
fi
done
}
installFile(){
res=$(checkExists $(basename $1))
if [[ $? -lt 1 ]]; then
if [[ -f $1 ]]; then
echo "Installing model file: $1"
ollama create $(basename $1) -f $1
else
echo "File $1 not found, aborting!"
fi
else
echo "$(basename $1) already exists, skipped."
fi
}
listFiles(){
echo "Listing available model files..."
echo
[[ $1 ]] && CAT=$1 || CAT="*"
(echo "Model Name Modelfile"
for file in ${CAT}/*; do
echo -e "$(basename $file)\t$file"
done) | column -t -s ' '
echo
echo -e "To install one, run $0 modelfile\nTo install all, run $0 all\n"
echo "Example; $0 startrek/Jean-Luc_Picard"
echo
}
checkExists(){
models="$(ollama list|awk '{print $1}'|sed 's/:.*//g'|grep $1)"
if [[ $models ]]; then
return 1
else
return 0
fi
}
[[ ${#1} -lt 1 ]] && usage
case $1 in
[aA][lL][lL]) installAll ;;
[lL][iI][sS][tT]) listFiles $2 ;;
*) installFile $1 ;;
esac