-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavid_link.sh
More file actions
executable file
·40 lines (33 loc) · 1.75 KB
/
avid_link.sh
File metadata and controls
executable file
·40 lines (33 loc) · 1.75 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
#!/bin/sh
appInstallPath="/Applications/Avid/Avid Link"
bundleName="Avid Link"
appName="${bundleName}"
installedVers=$(/usr/bin/defaults read "${appInstallPath}"/"${bundleName}.app"/Contents/Info.plist CFBundleVersion 2>/dev/null)
downloadURL=$(/usr/bin/curl -s "https://www.avid.com/products/avid-link#Downloads" | /usr/bin/grep macOS | /usr/bin/xmllint --html --xpath "//script[@id='__NEXT_DATA__']/text()" - 2>/dev/null | /usr/bin/sed -e 's/<!\[CDATA\[//' -e 's/]]>$//' | /usr/bin/grep -oE 'https?://[^"]+\.pkg' | /usr/bin/head -n 1)
currentVers=$(printf '%s' "${downloadURL}" | /usr/bin/rev | /usr/bin/cut -d "/" -f 1 - | /usr/bin/cut -c 5- - | /usr/bin/rev | /usr/bin/sed 's/[^0-9.]//g')
FILE=${downloadURL##*/}
# compare version numbers
if [ "${installedVers}" ]; then
/bin/echo "${appName} v${installedVers} is installed."
installedVersNoDots=$(printf '%s' "${installedVers}" | /usr/bin/sed 's/\.//g')
currentVersNoDots=$(printf '%s' "${currentVers}" | /usr/bin/sed 's/\.//g')
# pad out currentVersNoDots to match installedVersNoDots
installedVersNoDotsCount=${#installedVersNoDots}
currentVersNoDotsCount=${#currentVersNoDots}
while [ "${currentVersNoDotsCount}" -lt "${installedVersNoDotsCount}" ]; do
currentVersNoDots="${currentVersNoDots}0"
currentVersNoDotsCount=$((currentVersNoDotsCount + 1))
done
if [ "${installedVersNoDots}" -ge "${currentVersNoDots}" ]; then
/bin/echo "${appName} does not need to be updated"
exit 0
else
/bin/echo "Updating ${appName} to v${currentVers}"
fi
else
/bin/echo "Installing ${appName} v${currentVers}"
fi
if /usr/bin/curl --retry 3 --retry-delay 0 --retry-all-errors -sL "${downloadURL}" -o /tmp/"${FILE}"; then
/usr/sbin/installer -pkg /tmp/"${FILE}" -target /
/bin/rm /tmp/"${FILE}"
fi