-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1password.sh
More file actions
executable file
·45 lines (38 loc) · 1.9 KB
/
Copy path1password.sh
File metadata and controls
executable file
·45 lines (38 loc) · 1.9 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
#!/bin/sh
appInstallPath="/Applications"
bundleName="1Password"
appName="${bundleName}"
installedVers=$(/usr/bin/defaults read "${appInstallPath}"/"${bundleName}.app"/Contents/Info.plist CFBundleShortVersionString 2>/dev/null)
downloadURL="https://downloads.1password.com/mac/1Password.pkg"
FILE=${downloadURL##*/}
currentVers=$(/usr/bin/curl -s "https://releases.1password.com/mac/" | /usr/bin/xmllint --format --html - 2>/dev/null | /usr/bin/grep -B 7 '<h2 class="c-heading c-heading--2 u-mb-2 u-mb-0@md u-mt-4 u-mt-0@md">1Password for Mac</h2>' | /usr/bin/grep "Updated to" | /usr/bin/awk -F ">" '{ print $2 }' | /usr/bin/awk '{print $3}' | /usr/bin/head -n 1)
# compare version numbers
if [ "${installedVers}" ]; then
printf '%s\n' "${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
printf '%s\n' "${appName} does not need to be updated"
exit 0
else
printf '%s\n' "Updating ${appName} to v${currentVers}"
fi
else
printf '%s\n' "Installing ${appName} v${currentVers}"
fi
if /usr/bin/curl --retry 3 --retry-delay 0 --retry-all-errors -sL "${downloadURL}" -o /tmp/"${FILE}"; then
if ! installResult=$(/usr/sbin/installer -pkg /tmp/"${FILE}" -target / 2>&1); then
printf '%s\n' "An error occurred installing ${FILE}:"
printf '%s\n' "${installResult}"
else
printf '%s\n' "Successfully installed ${FILE}"
fi
/bin/rm /tmp/"${FILE}"
fi