-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInstall_VLC.sh
More file actions
165 lines (142 loc) · 3.58 KB
/
Install_VLC.sh
File metadata and controls
165 lines (142 loc) · 3.58 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/zsh
# Automatically download and install VLC
if [[ -z $4 ]]; then
echo "Version not specified"
exit 1
fi
if [[ -z $5 ]]; then
echo "Checksum not specified"
exit 1
fi
# Variables
appName="VLC.app"
appPath="/Applications/${appName}"
appProcessName="VLC"
dmgName="vlc-$4-universal.dmg"
dmgVolumePath="/Volumes/VLC media player"
#downloadUrl="https://download.videolan.org/pub/videolan/vlc/$4/macosx"
downloadUrl="https://get.videolan.org/vlc/$4/macosx"
checksum="$5"
cleanup () {
if [[ -f "${tmpDir}/${dmgName}" ]]; then
if rm -f "${tmpDir}/${dmgName}"; then
echo "Removed file ${tmpDir}/${dmgName}"
fi
fi
if [[ -d "${tmpDir}" ]]; then
if rm -R "${tmpDir}"; then
echo "Removed directory ${tmpDir}"
fi
fi
if [[ -d "${dmgVolumePath}" ]]; then
if hdiutil detach "${dmgVolumePath}" -quiet; then
echo "Unmounted DMG"
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"
cleanup
exit 0
else
echo "${appProcessName} not currently running"
fi
}
tryDownload () {
if curl -LSs "${downloadUrl}/${dmgName}" -o "${tmpDir}/${dmgName}"; then
echo "Download successful"
tryDownloadState=1
else
echo "Download unsuccessful"
tryDownloadCounter=$((tryDownloadCounter+1))
fi
}
verifyChecksum () {
if [[ $(shasum -a 256 "${tmpDir}/${dmgName}" | awk '{print $1}') == "${checksum}" ]]; then
echo "Checksum verified"
else
echo "Checksum verification failed"
echo "Failed checksum is $(shasum -a 256 "${tmpDir}/${dmgName}" | awk '{print $1}')"
cleanup
exit 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
# Make sure volume is not already mounted and unmount if needed
if [[ -d "${dmgVolumePath}" ]]; then
echo "${dmgVolumePath} already in use. Attempting to unmount"
hdiutil detach "${dmgVolumePath}"
fi
# Download dmg file into tmp dir (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}/${dmgName}" ]]; then
echo "Download unsuccessful"
cleanup
exit 1
fi
# Verify SHA256 checksum
verifyChecksum
# Mount dmg file
if hdiutil attach "${tmpDir}/${dmgName}" -nobrowse -quiet; then
echo "Mounted DMG"
else
echo "Failed to mount DMG"
cleanup
exit 1
fi
# Check for expected dmg path
if [[ ! -d "${dmgVolumePath}" ]]; then
echo "Could not locate ${dmgVolumePath}"
cleanup
exit 1
fi
# Remove app if already installed
if [[ -d "${appPath}" ]]; then
if rm -R "${appPath}"; then
echo "Removed existing ${appName} from /Applications directory"
else
echo "Failed to remove existing ${appName} from /Applications directory"
cleanup
exit 1
fi
fi
# Copy application to /Applications
if cp -R "${dmgVolumePath}/${appName}" /Applications/; then
echo "Copied ${appName} to /Applications directory"
else
echo "Failed to copy ${appName} to /Applications directory"
fi
# Remove tmp dir and downloaded dmg file
cleanup
# List version and exit with error code if not found
versionCheck
if [[ ${versionCheckStatus} -eq 0 ]]; then
exit 1
fi