-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgimp.sh
More file actions
executable file
·80 lines (69 loc) · 2.84 KB
/
gimp.sh
File metadata and controls
executable file
·80 lines (69 loc) · 2.84 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
#!/bin/sh
appInstallPath="/Applications"
bundleName="GIMP"
appName="${bundleName}"
installedVers=$(/usr/bin/defaults read "${appInstallPath}"/"${bundleName}.app"/Contents/Info.plist CFBundleShortVersionString 2>/dev/null)
case $(uname -m) in
arm64)
archType="arm64"
;;
x86_64)
archType="x86_64"
;;
*)
/bin/echo "Unknown processor architecture. Exiting"
exit 1
;;
esac
xmlData=$(/usr/bin/curl -sL "https://gimp.org/downloads" | /usr/bin/xmllint --html --xpath "//*[@id=\"mac-${archType}-buttons\"]/span[1]/a" - 2>/dev/null)
downloadURL="https:$(printf '%s' "${xmlData}" | /usr/bin/xmllint --html --xpath 'string(//*/a/@href)' -)"
currentVers=$(printf '%s' "${downloadURL}" | /usr/bin/grep -oE 'gimp-[0-9]+(\.[0-9]+)*' | /usr/bin/sed 's/gimp-//')
FILE=${downloadURL##*/}
SHAHash=$(/usr/bin/curl -s "https://www.gimp.org/downloads/" | /usr/bin/grep "${FILE}" | /usr/bin/grep SHA256 | /usr/bin/xmllint --html --xpath '//*/kbd/text()' -)
# 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
SHAResult=$(printf '%s' "${SHAHash} */tmp/${FILE}" | /usr/bin/shasum -a 256 -c 2>/dev/null)
case "${SHAResult}" in
*OK)
/bin/echo "SHA hash has successfully verifed."
;;
*FAILED)
/bin/echo "SHA hash has failed verification"
exit 1
;;
*)
/bin/echo "An unknown error has occured."
exit 1
;;
esac
/bin/rm -rf "${appInstallPath}"/"${bundleName}.app" >/dev/null 2>&1
TMPDIR=$(mktemp -d)
/usr/bin/hdiutil attach /tmp/"${FILE}" -noverify -quiet -nobrowse -mountpoint "${TMPDIR}"
/usr/bin/ditto "${TMPDIR}"/"${bundleName}.app" "${appInstallPath}"/"${bundleName}.app"
/usr/bin/xattr -r -d com.apple.quarantine "${appInstallPath}"/"${bundleName}.app"
/usr/sbin/chown -R root:admin "${appInstallPath}"/"${bundleName}.app"
/bin/chmod -R 755 "${appInstallPath}"/"${bundleName}.app"
/usr/bin/hdiutil eject "${TMPDIR}" -quiet
/bin/rmdir "${TMPDIR}"
/bin/rm /tmp/"${FILE}"
fi