/
bootstrap.sh
191 lines (157 loc) · 4.8 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
#!/bin/bash
#
# bootstrap.sh
# OpenFirmwareManager
#
#
# Released under "The GNU General Public License (GPL-2.0)"
#
# Copyright (c) 2021 cjiang. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# This script is supposed to quickly bootstrap OpenFirmwareManger for plugin building.
# A compiled OpenFirmwareManager release will be bootstrapped in the working directory.
#
# Latest version available at:
# https://raw.githubusercontent.com/AppleBluetooth/OpenFirmwareManager/master/bootstrap.sh
#
# Example usage:
# src=$(/usr/bin/curl -Lfs https://raw.githubusercontent.com/AppleBluetooth/OpenFirmwareManager/master/bootstrap.sh) && eval "$src" || exit 1
#
REPO_PATH="AppleBluetooth/OpenFirmwareManager"
SDK_PATH="OpenFirmwareManager.kext"
SDK_CHECK_PATH="${SDK_PATH}/Contents/Resources/OpenFirmwareManager.h"
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
if [ -e "${SDK_PATH}" ]; then
echo "ERROR: Found existing SDK directory ${SDK_PATH}, aborting!"
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/ofmtmp.${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 manually compiled SDK for development builds.
install_compiled_sdk() {
local ret=0
echo "Installing compiled SDK..."
echo "-> Cloning the latest version from master..."
local url="https://github.com/${REPO_PATH}"
"${GIT}" clone "${url}" -b "master" --depth=1 "tmp" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to clone repository with code ${ret}!"
return 1
fi
echo "-> Building the latest SDK..."
cd "tmp" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to cd to temporary directory tmp with code ${ret}!"
return 1
fi
"${GIT}" clone "https://github.com/acidanthera/MacKernelSDK" -b "master" --depth=1 || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to clone MacKernelSDK with code ${ret}!"
return 1
fi
"${XCODEBUILD}" -configuration Debug -arch x86_64 || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to compile the latest version with code ${ret}!"
return 1
fi
echo "-> Installing compiled SDK..."
if [ ! -d "build/Debug/${SDK_PATH}" ] || [ ! -f "build/Debug/${SDK_CHECK_PATH}" ]; then
echo "ERROR: Failed to find the built SDK!"
return 1
fi
"${MV}" "build/Debug/${SDK_PATH}" "${PROJECT_PATH}/${SDK_PATH}" || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Failed to install SDK with code ${ret}!"
return 1
fi
echo "Installed compiled SDK from master!"
}
prepare_environment || exit 1
ret=0
install_compiled_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