mirror of
https://github.com/ApfelTeeSaft/OpenRoyale.git
synced 2026-08-26 19:33:32 +00:00
99 lines
3.0 KiB
Bash
99 lines
3.0 KiB
Bash
#!/usr/bin/env bash
|
|
# fetch_sdk_portable.sh - portable Android SDK + portable Java.
|
|
# Installs into the parent folder of this script by default:
|
|
# ../android-sdk
|
|
# ../java
|
|
# No global packages are installed and no shell profile is modified.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PORTABLE_ROOT="$(cd "${PORTABLE_ROOT:-$SCRIPT_DIR/..}" && pwd)"
|
|
SDK_ROOT="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-$PORTABLE_ROOT/android-sdk}}"
|
|
JAVA_ROOT="${JAVA_HOME:-$PORTABLE_ROOT/java}"
|
|
|
|
PLATFORM="${ANDROID_PLATFORM_PKG:-platforms;android-34}"
|
|
BUILDTOOLS="${ANDROID_BUILDTOOLS_PKG:-build-tools;34.0.0}"
|
|
CLT_URL="${CLT_URL:-https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip}"
|
|
|
|
# Android sdkmanager currently works well with JDK 17. Override if needed:
|
|
# JDK_MAJOR=21 ./fetch_sdk_portable.sh
|
|
JDK_MAJOR="${JDK_MAJOR:-17}"
|
|
JDK_API_URL="${JDK_API_URL:-https://api.adoptium.net/v3/binary/latest/${JDK_MAJOR}/ga/linux/x64/jdk/hotspot/normal/eclipse?project=jdk}"
|
|
|
|
need_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || {
|
|
echo "[!] Missing required command: $1" >&2
|
|
echo " Install it once with your OS package manager, then rerun this script." >&2
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
fetch_java() {
|
|
if [ -x "$JAVA_ROOT/bin/java" ]; then
|
|
echo "[*] Portable Java already exists: $JAVA_ROOT"
|
|
return
|
|
fi
|
|
|
|
need_cmd curl
|
|
need_cmd tar
|
|
|
|
echo "[*] Downloading portable Eclipse Temurin JDK $JDK_MAJOR ..."
|
|
tmp="$(mktemp -d)"
|
|
curl -fL "$JDK_API_URL" -o "$tmp/jdk.tar.gz"
|
|
|
|
rm -rf "$JAVA_ROOT"
|
|
mkdir -p "$JAVA_ROOT"
|
|
tar -xzf "$tmp/jdk.tar.gz" -C "$tmp"
|
|
|
|
jdk_dir="$(find "$tmp" -maxdepth 1 -type d -name 'jdk*' | head -n 1)"
|
|
if [ -z "$jdk_dir" ]; then
|
|
echo "[!] Could not find extracted JDK directory." >&2
|
|
exit 1
|
|
fi
|
|
|
|
shopt -s dotglob
|
|
mv "$jdk_dir"/* "$JAVA_ROOT"/
|
|
shopt -u dotglob
|
|
rm -rf "$tmp"
|
|
}
|
|
|
|
fetch_cmdline_tools() {
|
|
need_cmd curl
|
|
need_cmd unzip
|
|
|
|
mkdir -p "$SDK_ROOT/cmdline-tools"
|
|
if [ ! -x "$SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" ]; then
|
|
echo "[*] Downloading Android command-line tools (official Google source) ..."
|
|
tmp="$(mktemp -d)"
|
|
curl -fL "$CLT_URL" -o "$tmp/clt.zip"
|
|
unzip -q "$tmp/clt.zip" -d "$tmp"
|
|
rm -rf "$SDK_ROOT/cmdline-tools/latest"
|
|
mkdir -p "$SDK_ROOT/cmdline-tools/latest"
|
|
mv "$tmp/cmdline-tools/"* "$SDK_ROOT/cmdline-tools/latest/"
|
|
rm -rf "$tmp"
|
|
fi
|
|
}
|
|
|
|
fetch_java
|
|
export JAVA_HOME="$JAVA_ROOT"
|
|
export PATH="$JAVA_HOME/bin:$PATH"
|
|
|
|
fetch_cmdline_tools
|
|
SDKM="$SDK_ROOT/cmdline-tools/latest/bin/sdkmanager"
|
|
|
|
yes | "$SDKM" --sdk_root="$SDK_ROOT" --licenses >/dev/null || true
|
|
"$SDKM" --sdk_root="$SDK_ROOT" "platform-tools" "$PLATFORM" "$BUILDTOOLS"
|
|
|
|
BUILD_TOOLS_DIR="$SDK_ROOT/${BUILDTOOLS/;//}"
|
|
|
|
cat <<OUT
|
|
[+] Portable Android SDK ready at: $SDK_ROOT
|
|
[+] Portable Java ready at: $JAVA_ROOT
|
|
|
|
Use this in your current shell:
|
|
export JAVA_HOME="$JAVA_ROOT"
|
|
export ANDROID_SDK_ROOT="$SDK_ROOT"
|
|
export ANDROID_HOME="$SDK_ROOT"
|
|
export PATH="\$JAVA_HOME/bin:\$ANDROID_SDK_ROOT/platform-tools:$BUILD_TOOLS_DIR:\$PATH"
|
|
OUT
|