-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
115 lines (104 loc) · 2.57 KB
/
update.sh
File metadata and controls
115 lines (104 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
###########################################################################
#
# COPYRIGHT (C) 2025
#
###########################################################################
#
# Author: Casey Cannady - me@caseycannady.com
#
###########################################################################
#
# Script: update.sh
# Version: 1.11
# Created: 02/13/2024
# Updated: 01/23/2025
#
###########################################################################
#
# _function: Get Installed Version of Ollama
#
get_installed_version() {
local version
version=$(ollama -v | cut -d' ' -f4)
if [[ -n "$version" ]]; then
echo "$version"
else
echo "not_installed"
fi
}
#
# _function: Get Ollama Version
#
get_latest_version() {
local version
version=$(curl -s "https://api.github.com/repos/ollama/ollama/releases/latest" | \
grep '"tag_name":' | \
sed -E 's/.*"v([^"]+)".*/\1/')
echo "$version"
}
#
# _function: Version Compare
#
version_compare() {
test "$(printf '%s\n' "$1" "$2" | sort -V | tail -n 1)" == "$2"
}
#
# Let's get started!
#
echo " "
echo "[*** STARTING | update.sh | `date` ***]"
#
# Run all APT commands for system updates.
#
echo " "
echo "Executing all APT update commands"
systemctl daemon-reload
apt-get update --fix-missing
apt-get full-upgrade -y --fix-missing
apt-get dist-upgrade -y --fix-missing
apt-get clean
apt-get autoremove
#
# Update all SNAP installs.
#
echo " "
echo "Updating all SNAPs"
killall snap-store
snap refresh
#
# Update ollama version to latest IF its installed.
#
INSTALLED_VERSION=$(get_installed_version)
LATEST_VERSION=$(get_latest_version)
if [ "$INSTALLED_VERSION" = "not_installed" ]; then
echo "Ollama is not installed on this system"
elif version_compare "$INSTALLED_VERSION" "$LATEST_VERSION"; then
echo "Ollama version $INSTALLED_VERSION meets minimum requirement of $LATEST_VERSION"
else
echo "Ollama version $INSTALLED_VERSION needs to be updated to $LATEST_VERSION"
curl -fsSL https://ollama.com/install.sh | sh;
fi
#
# Update local models IF ollama is installed.
#
if [ "$INSTALLED_VERSION" != "not_installed" ]; then
ollama list | tail -n +2 | awk '{print $1}' | xargs -I {} ollama pull {};
fi
#
# Check if reboot is required and notify user.
#
echo " ";
if [ -f /var/run/reboot-required ]
then
echo "[*** Attention $USER: you must reboot your machine ***]"
else
echo "[*** Attention $USER: your device has been updated ***]"
fi
#
# We're done!
#
echo " "
echo "[*** FINISHED | update.sh | `date` ***]"
echo " "
exit