-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAC-Google Chrome-Version Check.sh
55 lines (46 loc) · 1.67 KB
/
MAC-Google Chrome-Version Check.sh
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
#!/bin/bash
# Constants
chrome_app="/Applications/Google Chrome.app"
info_plist="$chrome_app/Contents/Info.plist"
temp_pkg="/tmp/googlechrome.pkg"
# Function to get the installed version of Chrome
get_installed_version() {
if [ -f "$info_plist" ]; then
installed_version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${info_plist}")
echo "$installed_version"
else
echo "" # Return empty string to indicate not installed
fi
}
# Function to get the latest available version of Chrome
get_latest_version() {
# Ensure curl is installed
if ! command -v curl &> /dev/null; then
echo "curl could not be found. Please install curl."
exit 1
fi
# Make a GET request to the API endpoint for macOS
response=$(curl -s "https://versionhistory.googleapis.com/v1/chrome/platforms/mac/channels/stable/versions")
# Parse the response using grep and awk to extract the version number
latest_version=$(echo "$response" | grep -o '"version": "[^"]*' | grep -o '[0-9.]*' | head -1)
if [ -z "$latest_version" ]; then
echo "Failed to fetch the latest version"
exit 1
fi
echo "$latest_version"
}
# Function to install or update Chrome using .pkg
version_check() {
current_version=$(get_installed_version)
latest_version=$(get_latest_version)
#echo "Current Version: $current_version"
#echo "Latest Version: $latest_version"
# Check if Chrome is not installed or up to date
if [ -z "$current_version" ] || [ "$current_version" == "$latest_version" ]; then
echo "Up to date/Not Installed"
else
echo "Out of date"
fi
}
# Main Section
version_check