Skip to content

Commit

Permalink
feat: move features to libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
phorcys420 committed Jul 12, 2024
1 parent 3c815d3 commit 7eb7691
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
6 changes: 5 additions & 1 deletion src/burp-suite/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@

"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
],

"dependsOn": {
"ghcr.io/phorcys420/devcontainer-features/lib-common:1": {}
}
}
18 changes: 13 additions & 5 deletions src/burp-suite/install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#!/usr/bin/env bash

echo "Activating feature 'burp-suite'"

set -euo pipefail

FEATURE_NAME="burp-suite"
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

# Load options
EDITION=${VERSION:-community}
VERSION=${VERSION:-latest}

if [ $VERSION = "latest" ]; then
echo "[burp-suite] [+] Grabbing the latest Burp version"
echo "[$FEATURE_NAME] [+] Grabbing the latest Burp version"

RELEASE_DATA=$(curl 'https://portswigger.net/burp/releases/data?previousLastId=-1&lastId=-1&pageSize=1' --silent --show-error)
VERSION=$(echo -n "$RELEASE_DATA" | jq -r '.ResultSet.Results[0].version')
Expand All @@ -17,7 +25,7 @@ fi
TMP=$(mktemp -d)
DESTINATION_FILE="$TMP/burp_install.sh"

echo "[burp-suite] [+] Downloading version $CURRENT_VERSION"
echo "[$FEATURE_NAME] [+] Downloading version $CURRENT_VERSION"
curl --location --silent --show-error \
--data-urlencode "product=$EDITION" \
--data-urlencode "version=$CURRENT_VERSION" \
Expand All @@ -27,7 +35,7 @@ curl --location --silent --show-error \

chmod +x "$DESTINATION_FILE"

echo "[burp-suite] [+] Installing Burp CE"
echo "[$FEATURE_NAME] [+] Installing Burp CE"
sudo -u "$_REMOTE_USER" "$DESTINATION_FILE" -q # $_REMOTE_USER_HOME

rm -rf "$TMP"
7 changes: 6 additions & 1 deletion src/ghidra/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@

"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
],

"dependsOn": {
"ghcr.io/phorcys420/devcontainer-features/lib-common:1": {},
"ghcr.io/phorcys420/devcontainer-features/lib-github:1": {}
}
}
44 changes: 17 additions & 27 deletions src/ghidra/install.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
#!/usr/bin/env bash

echo "Activating feature 'ghidra'"

set -euo pipefail

REPOSITORY=${REPOSITORY:-NationalSecurityAgency/ghidra}
VERSION=${VERSION:-latest}
FEATURE_NAME="ghidra"
echo "Activating feature '$FEATURE_NAME'"

INSTALL_DIR=${INSTALL_DIR:-/opt/ghidra}
LIBRARY_FOLDER="/usr/share/phorcys-devcontainer-libraries"

# From aws-cli feature (https://github.com/devcontainers/features/blob/main/src/aws-cli/install.sh#L59-L72)
export DEBIAN_FRONTEND=noninteractive
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
# Source lib-common and lib-github features
source "$LIBRARY_FOLDER/common/1/main.sh"
source "$LIBRARY_FOLDER/github/1/main.sh"

apt-get install -y --no-install-recommends "$@"
fi
}
# Load options
REPOSITORY=${REPOSITORY:-NationalSecurityAgency/ghidra}
VERSION=${VERSION:-latest}

check_packages curl ca-certificates jq libarchive-tools
INSTALL_DIR=${INSTALL_DIR:-/opt/ghidra}

if [ $VERSION = "latest" ]; then
RELEASE_API_URL="https://api.github.com/repos/NationalSecurityAgency/ghidra/releases/latest"
else
RELEASE_API_URL="https://api.github.com/repos/NationalSecurityAgency/ghidra/releases/tags/$VERSION"
fi
# Check for dependencies
checkPackages curl ca-certificates jq libarchive-tools

ASSET_URL=$(curl "$RELEASE_API_URL" --silent --show-error | jq -r ".assets[0].browser_download_url")
ASSET_URL=$(getRelease "$REPOSITORY" "$VERSION" | jq -r ".assets[0].browser_download_url")

TMP=$(mktemp -d)
DESTINATION_FILE="$TMP/ghidra.zip"

echo "[ghidra] [+] Downloading version with tag $VERSION"
echo "[$FEATURE_NAME] [+] Downloading version with tag $VERSION"

curl --location --silent --show-error \
--output "$DESTINATION_FILE" \
"$ASSET_URL"
--output "$DESTINATION_FILE" \
"$ASSET_URL"

mkdir -p "$INSTALL_DIR"

echo "[ghidra] [+] Extracting to $INSTALL_DIR"
echo "[$FEATURE_NAME] [+] Extracting to $INSTALL_DIR"

# Extract the archive by stripping the first directory so that we don't end up with a subfolder (e.g ghidra_11.1.1_PUBLIC_20240614) in $INSTALL_DIR
bsdtar --strip-components=1 -xf "$DESTINATION_FILE" -C "$INSTALL_DIR"
Expand Down

0 comments on commit 7eb7691

Please sign in to comment.