59 lines
1.0 KiB
Bash
Executable File
59 lines
1.0 KiB
Bash
Executable File
#!/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 not found, aborting!"
|
|
fi
|
|
else
|
|
echo "$(basename $1) already exists, skipped."
|
|
fi
|
|
}
|
|
|
|
listFiles(){
|
|
[[ $1 ]] && CAT=$1 || CAT="*"
|
|
for file in ${CAT}/*; do
|
|
echo "$file"
|
|
done
|
|
}
|
|
|
|
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
|