From 11c01dc32d4f1f3c9a4838d440f56dbf349b395d Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:13:27 +0200 Subject: [PATCH 1/2] feat: add `android-sdk` feature (#31) * feat: add `android-sdk` feature * feat(android-sdk): add to CI test workflow --- .github/workflows/test.yaml | 2 + src/android-sdk/NOTES.md | 3 ++ src/android-sdk/devcontainer-feature.json | 51 ++++++++++++++++++ src/android-sdk/install.sh | 64 +++++++++++++++++++++++ test/android-sdk/scenarios.json | 1 + test/android-sdk/test.sh | 18 +++++++ 6 files changed, 139 insertions(+) create mode 100644 src/android-sdk/NOTES.md create mode 100644 src/android-sdk/devcontainer-feature.json create mode 100644 src/android-sdk/install.sh create mode 100644 test/android-sdk/scenarios.json create mode 100644 test/android-sdk/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ff39acc..aa196f8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,6 +13,7 @@ jobs: strategy: matrix: features: + - android-sdk - coder - cutter - ghidra @@ -37,6 +38,7 @@ jobs: strategy: matrix: features: + - android-sdk - coder - burp-suite - cutter diff --git a/src/android-sdk/NOTES.md b/src/android-sdk/NOTES.md new file mode 100644 index 0000000..3ede173 --- /dev/null +++ b/src/android-sdk/NOTES.md @@ -0,0 +1,3 @@ +> [!NOTE] +> It's fine if we let `version` run out of date since it's rarely updated. +> (version from "Command line tools only" section @ https://developer.android.com/studio?hl=en) \ No newline at end of file diff --git a/src/android-sdk/devcontainer-feature.json b/src/android-sdk/devcontainer-feature.json new file mode 100644 index 0000000..5ca4ae2 --- /dev/null +++ b/src/android-sdk/devcontainer-feature.json @@ -0,0 +1,51 @@ +{ + "name": "Android SDK (via Google CDN)", + "id": "android-sdk", + "version": "1.0.0", + "description": "A feature that installs the Android command line tools and SDK", + "keywords": ["android", "mobile", "mobile-development"], + "options": { + "version": { + "type": "string", + "proposals": [ + "11076708" + ], + "default": "11076708", + "description": "Select the Android command line tools version ('latest' is not supported)" + }, + + "installMavenRepos": { + "type": "boolean", + "default": true, + "description": "Whether or not to install the Android and Google Maven repos" + }, + + "installPlayServices": { + "type": "boolean", + "default": true, + "description": "Whether or not to install Play Services" + }, + + "installEmulator": { + "type": "boolean", + "default": false, + "description": "Whether or not to install the Android Emulator (NOTE: you still have to install the images yourself using sdkmanager)" + } + }, + + "containerEnv": { + "ANDROID_HOME": "/usr/local/android-sdk", + "ANDROID_CMDLINE_TOOLS_HOME": "${ANDROID_HOME}/cmdline-tools", + "PATH": "${PATH}:${ANDROID_HOME}:${ANDROID_CMDLINE_TOOLS_HOME}/latest/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools" + }, + + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ], + + "dependsOn": { + "ghcr.io/phorcys420/devcontainer-features/lib-common:1": {}, + + "ghcr.io/devcontainers/features/java:1": {} + } +} diff --git a/src/android-sdk/install.sh b/src/android-sdk/install.sh new file mode 100644 index 0000000..abf0e2a --- /dev/null +++ b/src/android-sdk/install.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +set -euo pipefail + +FEATURE_NAME="android-sdk" +echo "Activating feature '$FEATURE_NAME'" + +# Source lib-common feature (DEVCONTAINER_LIBRARIES_HOME is defined by lib-common) +source "$DEVCONTAINER_LIBRARIES_HOME/common/1/main.sh" + +# Load options +VERSION=${VERSION:-11076708} + +INSTALL_MAVEN_REPOS=${INSTALL_MAVEN_REPOS:-"true"} +INSTALL_PLAY_SERVICES=${INSTALL_PLAY_SERVICES:-"true"} +INSTALL_EMULATOR=${INSTALL_EMULATOR:-"false"} + +# ANDROID_HOME and ANDROID_CMDLINE_TOOLS_HOME are defined in the containerEnv value of the feature's manifest +ANDROID_HOME=${ANDROID_HOME:-/usr/local/android-sdk} +ANDROID_CMDLINE_TOOLS_HOME=${ANDROID_CMDLINE_TOOLS_HOME:-${ANDROID_HOME}/cmdline-tools} + +# Check for dependencies +checkPackages curl ca-certificates unzip + +TMP=$(mktemp -d) +DESTINATION_FILE="$TMP/android-sdk.zip" + +echo "[$FEATURE_NAME] [+] Downloading version $VERSION of Android command line tools" + +curl --get --location --silent --show-error --fail \ + --output "$DESTINATION_FILE" \ + "https://dl.google.com/android/repository/commandlinetools-linux-${VERSION}_latest.zip" + +mkdir -p "$ANDROID_CMDLINE_TOOLS_HOME" + +echo "[$FEATURE_NAME] [+] Extracting Android command line tools" +unzip "$TMP/android-sdk.zip" -d "$ANDROID_CMDLINE_TOOLS_HOME" +mv "$ANDROID_CMDLINE_TOOLS_HOME/cmdline-tools" "$ANDROID_CMDLINE_TOOLS_HOME/latest" + +echo "[$FEATURE_NAME] [+] Accepting sdkmanager's licenses" +(yes || true) | sdkmanager --licenses + + +TOOLS=("tools" "platform-tools" "build-tools;34.0.0") + +if [ "$INSTALL_MAVEN_REPOS" = "true" ]; then + echo "[$FEATURE_NAME] [+] Adding Android and Google's Maven repositories to the list of tools" + TOOLS+=("extras;android;m2repository" "extras;google;m2repository") +fi + +if [ "$INSTALL_PLAY_SERVICES" = "true" ]; then + echo "[$FEATURE_NAME] [+] Adding play services to the list of tools" + TOOLS+=("extras;google;google_play_services") +fi + +if [ "$INSTALL_EMULATOR" = "true" ]; then + echo "[$FEATURE_NAME] [+] Adding the emulator to the list of tools" + TOOLS+=("emulator") +fi + +echo "[$FEATURE_NAME] [+] Installing SDK tools" +sdkmanager --install "${TOOLS[@]}" + +rm -rf "$TMP" \ No newline at end of file diff --git a/test/android-sdk/scenarios.json b/test/android-sdk/scenarios.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/test/android-sdk/scenarios.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/android-sdk/test.sh b/test/android-sdk/test.sh new file mode 100644 index 0000000..a79e4c3 --- /dev/null +++ b/test/android-sdk/test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +check "Android SDK folder exists" test -d "$ANDROID_HOME" + +BINARY_LIST=("sdkmanager" "adb") + +for binary in "${BINARY_LIST[@]}"; do + check "Android SDK binary '$binary' is in the PATH" which "$binary" +done + +# Report results +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults \ No newline at end of file From 21ddcec55f6c51006a8292a2d61d50cfd77c82fb Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:14:20 +0200 Subject: [PATCH 2/2] fix: fix burp tests and add `$BURP_HOME` (#32) * fix: fix burp tests and add `$BURP_HOME` * chore: "Burp" -> "Burp Suite" --- .github/workflows/test.yaml | 4 +++- src/burp-suite/devcontainer-feature.json | 5 +++++ src/burp-suite/install.sh | 13 ++++++++----- test/burp-suite/desktop.sh | 3 --- test/burp-suite/scenarios.json | 11 +---------- test/burp-suite/test.sh | 3 ++- 6 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 test/burp-suite/desktop.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index aa196f8..cbcf171 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,6 +14,7 @@ jobs: matrix: features: - android-sdk + - burp-suite - coder - cutter - ghidra @@ -39,8 +40,9 @@ jobs: matrix: features: - android-sdk - - coder - burp-suite + - coder + - coder - cutter - ghidra - lib-common diff --git a/src/burp-suite/devcontainer-feature.json b/src/burp-suite/devcontainer-feature.json index 1230da9..bfbe8a4 100644 --- a/src/burp-suite/devcontainer-feature.json +++ b/src/burp-suite/devcontainer-feature.json @@ -26,6 +26,11 @@ } }, + "containerEnv": { + "BURP_HOME": "/opt/burp-suite", + "PATH": "${PATH}:${BURP_HOME}" + }, + "installsAfter": [ "ghcr.io/devcontainers/features/common-utils", "ghcr.io/devcontainers/features/desktop-lite" diff --git a/src/burp-suite/install.sh b/src/burp-suite/install.sh index 17b4ed9..4f27690 100755 --- a/src/burp-suite/install.sh +++ b/src/burp-suite/install.sh @@ -8,15 +8,18 @@ echo "Activating feature '$FEATURE_NAME'" # Source lib-common feature source "/usr/share/phorcys-devcontainer-libraries/common/1/main.sh" -# Check for dependencies -checkPackages curl ca-certificates jq sudo +# Check for dependencies (libfreetype6 is only really needed to run in CI, otherwise you would always have this library if you have the desktop-lite feature) +checkPackages curl ca-certificates jq sudo libfreetype6 # Load options EDITION=${EDITION:-community} VERSION=${VERSION:-latest} +# CUTTER_HOME is defined in the containerEnv value of the feature's manifest +BURP_HOME=${BURP_HOME:-/opt/burp-suite} + if [ $VERSION = "latest" ]; then - echo "[$FEATURE_NAME] [+] Grabbing the latest Burp version" + echo "[$FEATURE_NAME] [+] Grabbing the latest Burp Suite version" RELEASE_DATA=$(curl 'https://portswigger.net/burp/releases/data?previousLastId=-1&lastId=-1&pageSize=5' --silent --show-error --fail) @@ -39,7 +42,7 @@ curl --get --location --silent --show-error --fail \ # Make temporary directory accessible to all users chmod +rx "$TMP" -R -echo "[$FEATURE_NAME] [+] Installing Burp $EDITION" -sudo -u "$_REMOTE_USER" "$DESTINATION_FILE" -q # $_REMOTE_USER_HOME +echo "[$FEATURE_NAME] [+] Installing Burp Suite $EDITION edition" +"$DESTINATION_FILE" -q -dir "$BURP_HOME" -overwrite rm -rf "$TMP" \ No newline at end of file diff --git a/test/burp-suite/desktop.sh b/test/burp-suite/desktop.sh deleted file mode 100644 index b5de05b..0000000 --- a/test/burp-suite/desktop.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -# Do nothing \ No newline at end of file diff --git a/test/burp-suite/scenarios.json b/test/burp-suite/scenarios.json index e0c6b06..9e26dfe 100644 --- a/test/burp-suite/scenarios.json +++ b/test/burp-suite/scenarios.json @@ -1,10 +1 @@ -{ - "desktop": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "ghcr.io/devcontainers/features/desktop-lite:1": {}, - - "burp-suite": {} - } - } -} \ No newline at end of file +{} \ No newline at end of file diff --git a/test/burp-suite/test.sh b/test/burp-suite/test.sh index 4378ccd..b747390 100644 --- a/test/burp-suite/test.sh +++ b/test/burp-suite/test.sh @@ -5,7 +5,8 @@ set -euo pipefail # Optional: Import test library bundled with the devcontainer CLI source dev-container-features-test-lib -# Do nothing +check "Burp folder exists" test -d "$BURP_HOME" +check "Burp binary is in the PATH" which BurpSuiteCommunity # Report results # If any of the checks above exited with a non-zero exit code, the test will fail.