-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbootstrap.sh
executable file
·307 lines (240 loc) · 7.32 KB
/
bootstrap.sh
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
#
# bootstrap.sh
#
# Copyright © 2019 hieplpvip. All rights reserved.
#
# This script is supposed to quickly bootstrap Lilu/VirtualSMC SDK for plugin building.
#
# Latest version available at:
# https://raw.githubusercontent.com/hieplpvip/AsusSMC/master/Scripts/bootstrap.sh
#
# Example usage:
# src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/hieplpvip/AsusSMC/master/Scripts/bootstrap.sh) && eval "$src" || exit 1
#
SDK_PATH="Lilu.kext"
PROJECT_PATH="$(pwd)"
if [ $? -ne 0 ] || [ ! -d "${PROJECT_PATH}" ]; then
echo "ERROR: Failed to determine working directory!"
exit 1
fi
# Avoid conflicts with PATH overrides.
CURL="/usr/bin/curl"
GIT="/usr/bin/git"
GREP="/usr/bin/grep"
MKDIR="/bin/mkdir"
MV="/bin/mv"
RM="/bin/rm"
SED="/usr/bin/sed"
UNAME="/usr/bin/uname"
UNZIP="/usr/bin/unzip"
UUIDGEN="/usr/bin/uuidgen"
XCODEBUILD="/usr/bin/xcodebuild"
TOOLS=(
"${CURL}"
"${GIT}"
"${GREP}"
"${MKDIR}"
"${MV}"
"${RM}"
"${SED}"
"${UNAME}"
"${UNZIP}"
"${UUIDGEN}"
"${XCODEBUILD}"
)
for tool in "${TOOLS[@]}"; do
if [ ! -x "${tool}" ]; then
echo "ERROR: Missing ${tool}!"
exit 1
fi
done
# Prepare temporary directory to avoid conflicts with other scripts.
# Sets TMP_PATH.
prepare_environment() {
local ret=0
local sys=$("${UNAME}") || ret=$?
if [ $ret -ne 0 ] || [ "$sys" != "Darwin" ]; then
echo "ERROR: This script is only meant to be used on Darwin systems!"
return 1
fi
local uuid=$("${UUIDGEN}") || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to generate temporary UUID with code ${ret}!"
return 1
fi
TMP_PATH="/tmp/lilutmp.${uuid}"
if [ -e "${TMP_PATH}" ]; then
echo "ERROR: Found existing temporary directory ${TMP_PATH}, aborting!"
return 1
fi
"${MKDIR}" "${TMP_PATH}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to create temporary directory ${TMP_PATH} with code ${ret}!"
return 1
fi
cd "${TMP_PATH}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory ${TMP_PATH} with code ${ret}!"
"${RM}" -rf "${TMP_PATH}"
return 1
fi
return 0
}
# Install prebuilt Lilu SDK for release distribution.
install_lilu_sdk() {
local ret=0
echo "Installing prebuilt Lilu SDK..."
echo "-> Obtaining release manifest..."
echo "-> Cloning the latest version from master..."
# This is a really ugly hack due to GitHub API rate limits.
local url="/~https://github.com/acidanthera/Lilu"
"${GIT}" clone "${url}" -b "master" "lilu" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to clone repository with code ${ret}!"
return 1
fi
echo "-> Obtaining the latest tag..."
cd "lilu" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory lilu with code ${ret}!"
return 1
fi
local vers=$("${GIT}" describe --abbrev=0 --tags) || ret=$?
if [ "$vers" = "" ]; then
echo "ERROR: Failed to determine the latest release tag!"
return 1
fi
echo "-> Discovered the latest tag ${vers}."
cd .. || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd back from temporary directory with code ${ret}!"
return 1
fi
"${RM}" -rf lilu || ret=$?
if [ $ret -ne 0 ] || [ -d lilu ]; then
echo "ERROR: Failed to remove temporary directory lilu with code ${ret}!"
return 1
fi
local file="Lilu-${vers}-DEBUG.zip"
echo "-> Downloading prebuilt debug version ${file}..."
local url="/~https://github.com/acidanthera/Lilu/releases/download/${vers}/${file}"
"${CURL}" -LfsO "${url}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to download ${file} with code ${ret}!"
return 1
fi
echo "-> Extracting SDK from prebuilt debug version..."
if [ ! -f "${file}" ]; then
echo "ERROR: Failed to download ${file} to a non-existent location!"
return 1
fi
"${MKDIR}" "lilu" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to create temporary directory at ${TMP_PATH} with code ${ret}!"
return 1
fi
cd "lilu" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory lilu with code ${ret}!"
return 1
fi
"${UNZIP}" -q ../"${file}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to unzip ${file} with code ${ret}!"
return 1
fi
echo "-> Installing SDK from the prebuilt debug version..."
"${RM}" -rf "${PROJECT_PATH}/Lilu.kext"
"${MV}" "Lilu.kext" "${PROJECT_PATH}/Lilu.kext" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to install SDK with code ${ret}!"
return 1
fi
echo "Installed prebuilt Lilu SDK ${vers}!"
return 0
}
# Install prebuilt VirtualSMC SDK for release distribution.
install_vsmc_sdk() {
local ret=0
echo "Installing prebuilt VirtualSMC SDK..."
echo "-> Obtaining release manifest..."
echo "-> Cloning the latest version from master..."
# This is a really ugly hack due to GitHub API rate limits.
local url="/~https://github.com/acidanthera/VirtualSMC"
"${GIT}" clone "${url}" -b "master" "vsmc" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to clone repository with code ${ret}!"
return 1
fi
echo "-> Obtaining the latest tag..."
cd "vsmc" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory vsmc with code ${ret}!"
return 1
fi
local vers=$("${GIT}" describe --abbrev=0 --tags) || ret=$?
if [ "$vers" = "" ]; then
echo "ERROR: Failed to determine the latest release tag!"
return 1
fi
echo "-> Discovered the latest tag ${vers}."
cd .. || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd back from temporary directory with code ${ret}!"
return 1
fi
"${RM}" -rf vsmc || ret=$?
if [ $ret -ne 0 ] || [ -d vsmc ]; then
echo "ERROR: Failed to remove temporary directory vsmc with code ${ret}!"
return 1
fi
local file="VirtualSMC-${vers}-DEBUG.zip"
echo "-> Downloading prebuilt debug version ${file}..."
local url="/~https://github.com/acidanthera/VirtualSMC/releases/download/${vers}/${file}"
"${CURL}" -LfsO "${url}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to download ${file} with code ${ret}!"
return 1
fi
echo "-> Extracting SDK from prebuilt debug version..."
if [ ! -f "${file}" ]; then
echo "ERROR: Failed to download ${file} to a non-existent location!"
return 1
fi
"${MKDIR}" "vsmc" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to create temporary directory at ${TMP_PATH} with code ${ret}!"
return 1
fi
cd "vsmc" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory vsmc with code ${ret}!"
return 1
fi
"${UNZIP}" -q ../"${file}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to unzip ${file} with code ${ret}!"
return 1
fi
echo "-> Installing SDK from the prebuilt debug version..."
"${RM}" -rf "${PROJECT_PATH}/VirtualSMC.kext"
"${MV}" "Kexts/VirtualSMC.kext" "${PROJECT_PATH}/VirtualSMC.kext" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to install SDK with code ${ret}!"
return 1
fi
echo "Installed prebuilt VirtualSMC SDK ${vers}!"
return 0
}
prepare_environment || exit 1
ret=0
install_lilu_sdk || ret=$?
echo "------------------------------"
install_vsmc_sdk || ret=$?
cd "${PROJECT_PATH}" || ret=$?
"${RM}" -rf "${TMP_PATH}"
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to bootstrap SDK with code ${ret}!"
exit 1
fi