From c96c559a8551c496bc25b4e27c4b9d691fd55d39 Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:29:34 +0000 Subject: [PATCH 1/6] feat: add `lib-github` feature --- src/lib-github/devcontainer-feature.json | 22 ++++++++++++++ src/lib-github/install.sh | 37 ++++++++++++++++++++++++ src/lib-github/src/main.sh | 17 +++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/lib-github/devcontainer-feature.json create mode 100644 src/lib-github/install.sh create mode 100644 src/lib-github/src/main.sh diff --git a/src/lib-github/devcontainer-feature.json b/src/lib-github/devcontainer-feature.json new file mode 100644 index 0000000..7eddd33 --- /dev/null +++ b/src/lib-github/devcontainer-feature.json @@ -0,0 +1,22 @@ +{ + "name": "Library - GitHub", + "id": "lib-github", + "version": "1.0.0", + "description": "A feature that contains utilities to fetch releases from GitHub", + "keywords": ["library"], + "options": { + "baseDir": { + "type": "string", + "default": "/usr/share/phorcys-devcontainer-libraries", + "description": "Select the base directory where the library should be installed" + } + }, + + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ], + + "dependsOn": [ + "ghcr.io/phorcys420/devcontainer-features/lib-common:1" + ] +} diff --git a/src/lib-github/install.sh b/src/lib-github/install.sh new file mode 100644 index 0000000..e63864e --- /dev/null +++ b/src/lib-github/install.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -euo pipefail + +FEATURE_NAME="github" +echo "Activating feature '$FEATURE_NAME'" + +# Define the base directory where the feature libraries are stored +BASE_DIR=${BASEDIR:-"/usr/share/phorcys-devcontainer-libraries"} + +# Source lib-common feature +source "$BASE_DIR/common/main.sh" + +# Grab current feature version and split it in parts +VERSION=$(getFeatureVersion) +VERSION_PARTS=($(getVersionParts "$VERSION")) + +# Define the installation directory for the current feature and the current feature version +FEATURE_DIR="$BASE_DIR/$FEATURE_NAME" +INSTALL_DIR="$FEATURE_DIR/$VERSION" + +# Create directory for current feature version +echo "[$FEATURE_NAME] [+] Installing library to $INSTALL_DIR" +mkdir --parents "$INSTALL_DIR" +cp --recursive src/. "$INSTALL_DIR" + +# Make links to each subversion (e.g if version is 1.0.0, then link to 1.0 and 1) and "current" +SUBFOLDERS=( + "${VERSION_PARTS[0]}.${VERSION_PARTS[1]}", # 1.0 + "${VERSION_PARTS[0]}", # 1 + "current" +) + +for SUBFOLDER in "${SUBFOLDERS[@]}" +do + ln --symbolic --force "$INSTALL_DIR" "$FEATURE_DIR/$SUBFOLDER" +done \ No newline at end of file diff --git a/src/lib-github/src/main.sh b/src/lib-github/src/main.sh new file mode 100644 index 0000000..89ff155 --- /dev/null +++ b/src/lib-github/src/main.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +getRelease() { + REPOSITORY=$1 + TAG=${2:-latest} + + if [ $TAG = "latest" ]; then + RELEASE_API_URL="https://api.github.com/repos/$REPOSITORY/releases/latest" + else + RELEASE_API_URL="https://api.github.com/repos/$REPOSITORY/releases/tags/$TAG" + fi + + curl "$RELEASE_API_URL" --silent --show-error +} + +# Check for necessary packages +checkPackages curl jq \ No newline at end of file From f39cb1aea14803028669a9f6b602350e934914cc Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:34:02 +0000 Subject: [PATCH 2/6] fix(lib-github: fix `dependsOn` --- src/lib-github/devcontainer-feature.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib-github/devcontainer-feature.json b/src/lib-github/devcontainer-feature.json index 7eddd33..73bc08f 100644 --- a/src/lib-github/devcontainer-feature.json +++ b/src/lib-github/devcontainer-feature.json @@ -16,7 +16,7 @@ "ghcr.io/devcontainers/features/common-utils" ], - "dependsOn": [ - "ghcr.io/phorcys420/devcontainer-features/lib-common:1" - ] + "dependsOn": { + "ghcr.io/phorcys420/devcontainer-features/lib-common:1": {} + } } From 478f6355f85e5b2978e086468c9d72ec010212db Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:40:21 +0000 Subject: [PATCH 3/6] feat(lib-github): add tests --- .github/workflows/test.yaml | 2 ++ test/lib-github/test.sh | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/lib-github/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6cd9312..00829c5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,6 +15,7 @@ jobs: features: - ghidra - lib-common + - lib-github baseImage: - debian:latest - ubuntu:latest @@ -37,6 +38,7 @@ jobs: - burp-suite - ghidra - lib-common + - lib-github steps: - uses: actions/checkout@v3 diff --git a/test/lib-github/test.sh b/test/lib-github/test.sh new file mode 100644 index 0000000..d1e41e7 --- /dev/null +++ b/test/lib-github/test.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +check "Library folder exists" test -d "/usr/share/phorcys-devcontainer-libraries/github" + +# 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 eb1363003f342837394497319d34cfa53a9f81d1 Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:49:04 +0000 Subject: [PATCH 4/6] fix(lib-github): use version path for lib-common sourcing --- src/lib-github/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib-github/install.sh b/src/lib-github/install.sh index e63864e..eef8fe0 100644 --- a/src/lib-github/install.sh +++ b/src/lib-github/install.sh @@ -9,7 +9,7 @@ echo "Activating feature '$FEATURE_NAME'" BASE_DIR=${BASEDIR:-"/usr/share/phorcys-devcontainer-libraries"} # Source lib-common feature -source "$BASE_DIR/common/main.sh" +source "$BASE_DIR/common/1/main.sh" # Grab current feature version and split it in parts VERSION=$(getFeatureVersion) From 5bbe8fda885b7b556fddac53245c967df316c234 Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:50:23 +0000 Subject: [PATCH 5/6] (test) --- src/lib-github/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib-github/install.sh b/src/lib-github/install.sh index eef8fe0..afe04dc 100644 --- a/src/lib-github/install.sh +++ b/src/lib-github/install.sh @@ -8,6 +8,8 @@ echo "Activating feature '$FEATURE_NAME'" # Define the base directory where the feature libraries are stored BASE_DIR=${BASEDIR:-"/usr/share/phorcys-devcontainer-libraries"} +find /usr/share/phorcys-devcontainer-libraries/common + # Source lib-common feature source "$BASE_DIR/common/1/main.sh" From 5f0907817fb954510bf8b45084ccbf8e014a1005 Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:53:57 +0000 Subject: [PATCH 6/6] fix(lib-github): do not use commas in subfolder names --- src/lib-github/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib-github/install.sh b/src/lib-github/install.sh index afe04dc..57dd9e3 100644 --- a/src/lib-github/install.sh +++ b/src/lib-github/install.sh @@ -28,8 +28,8 @@ cp --recursive src/. "$INSTALL_DIR" # Make links to each subversion (e.g if version is 1.0.0, then link to 1.0 and 1) and "current" SUBFOLDERS=( - "${VERSION_PARTS[0]}.${VERSION_PARTS[1]}", # 1.0 - "${VERSION_PARTS[0]}", # 1 + "${VERSION_PARTS[0]}.${VERSION_PARTS[1]}" # 1.0 + "${VERSION_PARTS[0]}" # 1 "current" )