summaryrefslogtreecommitdiff
path: root/data/iphoneos-sdk/download-theos-sdk
blob: c17dd3143e643f9d03c49ae1d7c9959c5fde643d (plain)
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
#!/bin/bash
# download-theos-sdk
# Provides a copy of the SDK through download.
#
# Report any issues to the maintainer of this package.

url='https://github.com/theos/sdks/archive/master.zip'
_SDK='/usr/share/SDKs/iPhoneOS.sdk'
# FUNCTIONS
function die(){
	local msg="$@"
	printf 'ERROR: %s\n' "${msg}" 1>&2
	exit 1
}

function _root() {
	if sudo -n /bin/true &>/dev/null; then
		cmd="sudo"
	elif command -v crux &>/dev/null; then
		cmd="crux"
	else
		die "Run this script as root."
	fi
	${cmd} $(realpath ${BASH_SOURCE[0]})
	exit $?
}

# START
# Check for the SDK.
if [[ -d ${_SDK}/usr/lib ]]; then
	echo "Installed to ${_SDK}, nothing more to do."
	exit 0
fi

[[ ${UID} != 0 ]] && _root
set -e
function error(){
	die "Something went wrong."
}
trap "error" ERR

cd $(mktemp -d)
echo 'Please wait.' 1>&2
/usr/bin/wget ${url} &>/dev/null	|| die "Failed to download ${url}"
/usr/bin/unzip ${url##**/} &>/dev/null	|| die "Failed to extract ${url##**/}"
SDK="$(for d in */*.sdk; do echo "${d}"; done | sort -rVtx | head -n1 )"
mkdir -p ${_SDK}
cp -rn ${SDK:-/nonexist}/* ${_SDK}

echo "${SDK##**/} was installed to ${_SDK}"
exit 0