Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install-sdk script #787

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions bin/install-sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

# Error codes + association:
# 1 - api.github.com request failed
# 2 - Invalid argument(s)
# 3 - Requested SDK DNE
PoomSmart marked this conversation as resolved.
Show resolved Hide resolved
# 4 - No $THEOS
# 5 - Requested SDK already exists
# 6 - Failed curl

set -e

urls=$(curl -s https://api.github.com/repos/theos/sdks/releases/latest | grep download_url | sed 's/.*: "\(.*\)"/\1/')
if [[ -z "$urls" ]]; then
echo "ERROR: api.github.com request failed?!" >&2
exit 1
fi

sdks=( $(echo "$urls" | sed -e 's/.*\///' -e 's/\.sdk.*//' | tr '\n' ' ') )
sdks+=( "latest" "latest-tv" )
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <sdk_name>"
echo "Available <sdk_name>s: ${sdks[@]}"
exit 2
fi

if ! printf '%s\0' "${sdks[@]}" | grep -F -x -z -- "${1}"; then
echo "ERROR: we do not currently provide $1.sdk!" >&2
exit 3
fi

if [[ -z "$THEOS" ]]; then
echo "ERROR: \$THEOS does not exist." >&2
echo "Please install Theos from https://theos.dev/docs/installation before proceeding." >&2
exit 4
elif ! [[ -d "$THEOS/sdks/" ]]; then
mkdir -pv "$THEOS/sdks/"
fi

if [[ $1 == latest ]]; then
url=$(echo "$urls" | grep 'iPhoneOS' | sort -V | tail -n1)
elif [[ $1 == latest-tv ]]; then
url=$(echo "$urls" | grep 'AppleTVOS' | sort -V | tail -n1)
else
url=$(echo "$urls" | grep "$1")
fi

sdk=$(echo "$url" | sed -e 's/.*\///' -e 's/\.sdk.*//').sdk
if [[ -d "$THEOS/sdks/$sdk" ]]; then
echo "ERROR: $sdk already exists!" >&2
exit 5
else
curl -L "$url" | tar -xJv -C "$THEOS/sdks" \
|| (echo "ERROR: $sdk download failed." >&2; exit 6)
fi
10 changes: 2 additions & 8 deletions bin/install-theos
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,8 @@ get_sdks() {
update "SDKs appear to already be installed."
else
update "SDKs do not appear to be installed. Installing now..."
# Grab latest for provided platforms
urls=$(curl https://api.github.com/repos/theos/sdks/releases/latest | grep download_url | sed 's/.*: "\(.*\)"/\1/')
ios_url=$(echo "$urls" | grep 'iPhoneOS' | sort -V | tail -n1)
tvos_url=$(echo "$urls" | grep 'AppleTVOS' | sort -V | tail -n1)
curl -L "$ios_url" | tar -xJv -C "$THEOS/sdks"
curl -L "$tvos_url" | tar -xJv -C "$THEOS/sdks"

if [[ -d $THEOS/sdks/ && $(ls -A "$THEOS/sdks/" | grep sdk) ]]; then
$THEOS/bin/install-sdk latest && $THEOS/bin/install-sdk latest-tv
if ! [[ -z $(ls -A "$THEOS/sdks/" | grep sdk) ]]; then
update "SDKs successfully installed!"
else
error "Something appears to have gone wrong. Please try again."
Expand Down