-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInstall_GoogleChrome.sh
More file actions
99 lines (84 loc) · 2.3 KB
/
Install_GoogleChrome.sh
File metadata and controls
99 lines (84 loc) · 2.3 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/zsh
# Automatically download and install the latest Google Chrome
# https://support.google.com/chrome/a/answer/9915669?hl=en
# Variables
appName="Google Chrome.app"
appPath="/Applications/${appName}"
appProcessName="Google Chrome"
downloadUrl="https://dl.google.com/chrome/mac/stable"
#downloadUrl="https://dl.google.com/chrome/mac/universal/stable/gcem"
pkgName="GoogleChrome.pkg"
acceptTerms="accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms"
cleanup () {
if [[ -f "${tmpDir}/${pkgName}" ]]; then
if rm -f "${tmpDir}/${pkgName}"; then
echo "Removed file ${tmpDir}/${pkgName}"
fi
fi
if [[ -d "${tmpDir}" ]]; then
if rm -R "${tmpDir}"; then
echo "Removed directory ${tmpDir}"
fi
fi
}
createTmpDir () {
if [ -z ${tmpDir+x} ]; then
tmpDir=$(mktemp -d)
echo "Temp dir set to ${tmpDir}"
fi
}
processCheck () {
if pgrep -x "${appProcessName}" > /dev/null; then
echo "${appProcessName} is currently running"
echo "Aborting install"
exit 0
else
echo "${appProcessName} not currently running"
fi
}
tryDownload () {
if curl -LSs "${downloadUrl}/${acceptTerms}/${pkgName}" -o "${tmpDir}/${pkgName}"; then
echo "Download successful"
tryDownloadState=1
else
echo "Download unsuccessful"
tryDownloadCounter=$((tryDownloadCounter+1))
fi
}
versionCheck () {
if [[ -d "${appPath}" ]]; then
echo "${appName} version is $(defaults read "${appPath}/Contents/Info.plist" CFBundleShortVersionString)"
versionCheckStatus=1
else
echo "${appName} not installed"
versionCheckStatus=0
fi
}
# Start
# List version
versionCheck
# Download pkg file into tmpDir (60 second timeout)
tryDownloadState=0
tryDownloadCounter=0
while [[ ${tryDownloadState} -eq 0 && ${tryDownloadCounter} -le 60 ]]; do
processCheck
createTmpDir
tryDownload
sleep 1
done
# Check for successful download
if [[ ! -f "${tmpDir}/${pkgName}" ]]; then
echo "Download failed"
cleanup
exit 1
fi
# Install package
echo "Starting install"
installer -pkg "${tmpDir}/${pkgName}" -target /
# Remove tmp dir and downloaded pkg file
cleanup
# List version and exit with error code if not found
versionCheck
if [[ ${versionCheckStatus} -eq 0 ]]; then
exit 1
fi