-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilemaker_pro.sh
More file actions
executable file
·82 lines (67 loc) · 3.56 KB
/
filemaker_pro.sh
File metadata and controls
executable file
·82 lines (67 loc) · 3.56 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
#!/bin/sh
appInstallPath="/Applications"
bundleName="FileMaker Pro"
appName="${bundleName}"
installedVers=$(/usr/bin/defaults read "${appInstallPath}"/"${bundleName}.app"/Contents/Info.plist CFBundleShortVersionString 2>/dev/null)
htmlData=$(/usr/bin/curl -s "https://www.filemaker.com/redirects/ss.txt")
if [ "$(/usr/bin/sw_vers -buildVersion | /usr/bin/cut -c 1-2 -)" -ge 24 ]; then
majVers=$(printf '%s' "${htmlData}" | /usr/bin/grep "PRO..MAC\"" | /usr/bin/tail -n 1 | /usr/bin/sed 's/,$//' | /usr/bin/jq -r .file | /usr/bin/sed 's/[a-zA-Z]//g')
downloadURL="$(printf '%s' "${htmlData}" | /usr/bin/grep "PRO${majVers}MAC" | /usr/bin/head -n 1 | /usr/bin/sed 's/,$//' | /usr/bin/jq -r .url)"
else
majVers=$(printf '%s' "${htmlData}" | /usr/bin/grep "PRO..MAC\"" | /usr/bin/tail -n 1 | /usr/bin/sed 's/,$//' | plutil -extract file raw -o - - | /usr/bin/sed 's/[a-zA-Z]//g')
downloadURL="$(printf '%s' "${htmlData}" | /usr/bin/grep "PRO${majVers}MAC" | /usr/bin/head -n 1 | /usr/bin/sed 's/,$//' | plutil -extract url raw -o - -)"
fi
FILE=${downloadURL##*/}
currentVers="$(printf '%s' "${downloadURL}" | rev | /usr/bin/cut -d "/" -f 1 - | rev | /usr/bin/sed 's/[a-zA-Z_]//g' | /usr/bin/awk -F. '{print $1"."$2"."$3}')"
# 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
curlParts=5
contentLength=$(/usr/bin/curl -sI "${downloadURL}" | /usr/bin/grep ^Content-Length | /usr/bin/awk '{print $2}' | /usr/bin/sed 's/[^0-9]//g')
partSize=$((contentLength/5))
/usr/bin/curl --retry 3 --retry-delay 0 --retry-all-errors -sL -r 0-$partSize -o /tmp/"${FILE}".bin1 "${downloadURL}" &
i=1
while [ $i -le $((curlParts-2)) ]; do
x=$((i + 1))
/usr/bin/curl --retry 3 --retry-delay 0 --retry-all-errors -sL -r $((partSize*i+1))-$((partSize*x)) -o /tmp/"${FILE}".bin$x "${downloadURL}" &
i=$((i + 1))
done
/usr/bin/curl --retry 3 --retry-delay 0 --retry-all-errors -sL -r $((partSize*curlParts-partSize+1))-"${contentLength}" -o /tmp/"${FILE}".bin${curlParts} "${downloadURL}" &
# wait for all background processes to finish
wait
i=1
while [ $i -le $curlParts ]; do
cat /tmp/"${FILE}".bin${i} >> /tmp/"${FILE}"
i=$((i + 1))
done
/bin/rm /tmp/"${FILE}".bin*
if /usr/bin/hdiutil verify -quiet /tmp/"${FILE}"; then
/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