-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupersonic-updater-macos.sh
executable file
·61 lines (48 loc) · 5.13 KB
/
supersonic-updater-macos.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
56
57
58
59
60
61
# Supersonic Update Script for macOS.
# Created by Gavin Liddell
# https://github.com/GavinL2001/supersonic-update-script
#!/bin/bash
# Functions
get_local_version() {
defaults read /Applications/Supersonic.app/Contents/Info.plist CFBundleShortVersionString # Fetch current version installed.
}
get_latest_version() { # Credit to @lukechilds on Github for the function.
curl --silent "https://api.github.com/repos/dweymouth/supersonic/releases/latest" | # Get latest release from GitHub api.
grep '"tag_name":' | # Get tag line.
sed -E 's/.*"v([^"]+)".*/\1/' # Pluck JSON value.
}
get_platform() {
uname -m | sed 's/86_//' # Get the processor type of the user's machine.
}
get_kernel() {
uname -r | sed 's/\..*//' # Get macOS version number.
}
install() {
[ -d $HOME/tmp ] || mkdir -p $HOME/tmp
curl -sL $download_url -o $location # Grab the latest .zip file from GitHub and move to the user's tmp folder.
unzip -o -qq $location -d /Applications/ # Unzip file into the Applications folder.
rm $location # Remove the downloaded zip file after unzipping.
[ "$(get_local_version)" == "$latest" ] && echo "Update completed!" || echo "Update failed." # Check that the update worked as intended.
exit 0
}
# Variables
local=$(get_local_version) # Sets the local version function as a variable.
latest=$(get_latest_version) # Sets the latest version as a variable.
platform=$(get_platform) # Set the platform version as a variable.
kernel=$(get_kernel) # Set the kernel version as a variable.
location=$HOME/tmp/Supersonic.zip # Set the download directory as a variable.
# The Update Process
printf "Supersonic Update Script for macOS\nCreated by Gavin Liddell\nRepo: https://github.com/GavinL2001/supersonic-update-script\n" # Show source and creator of the project.
sleep 1
printf "\nChecking for update.\nYour Supersonic Version: $local\nLatest Supersonic Version: $latest\n" # Output current and latest version.
[ "$local" == "$latest" ] && echo "You are up-to-date!" && exit 0 || # Compare the installed and latest version from GitHub.
if [[ $kernel < 18 ]] # Checks if OS version is legacy.
then # Installs legacy version if the statement is true.
download_url="https://github.com/dweymouth/supersonic/releases/latest/download/Supersonic-$latest-mac-legacy-HighSierra-x64.zip" # Set the download_url variable.
printf "Your Supersonic version is out-of-date!\nInstalling the latest legacy update.\n" # Explain that the application is out-of-date and that the update is being downloaded.
install # Calls the install function.
else
download_url="https://github.com/dweymouth/supersonic/releases/latest/download/Supersonic-$latest-mac-$platform.zip" # Set the download_url variable.
printf "Your Supersonic version is out-of-date!\nInstalling the latest update.\n" # Explain that the application is out-of-date and that the update is being downloaded.
install # Calls the install function.
fi