From 43860031879a1807d83d786e709b53723155e774 Mon Sep 17 00:00:00 2001 From: "Thomas G." <1809566+tomgrv@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:11:03 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20common=20utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/README.md | 27 +++++++++++++++++++++++++++ src/utils/_install-feature.sh | 19 +++++++++++++++++++ src/utils/devcontainer-feature.json | 19 +++++++++++++++++++ src/utils/install.sh | 23 +++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/utils/README.md create mode 100644 src/utils/_install-feature.sh create mode 100644 src/utils/devcontainer-feature.json create mode 100644 src/utils/install.sh diff --git a/src/utils/README.md b/src/utils/README.md new file mode 100644 index 0000000..ee0b992 --- /dev/null +++ b/src/utils/README.md @@ -0,0 +1,27 @@ + + +# Utils Feature + +This feature installs the PHP Extension Community Library (PECL) in the dev container. PECL is a repository for PHP extensions. + +More information about PECL can be found on the [PECL website](https://pecl.php.net/). + +## Example Usage + +```json +"features": { + "ghcr.io/tomgrv/devcontainer-features/pecl:1": { + "extension": "zip" + } +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +| ---------- | ------------------------------------- | ------ | ------------- | +| version | The version of GitVersion to install. | string | latest | + +## Contributing + +If you have a feature that you would like to add to this repository, please open an issue or submit a pull request. diff --git a/src/utils/_install-feature.sh b/src/utils/_install-feature.sh new file mode 100644 index 0000000..bc76c94 --- /dev/null +++ b/src/utils/_install-feature.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -e + +### Init directories +export source=$(dirname $(readlink -f $(ps -o comm= $PPID))) +export feature=$(basename $source | sed 's/_.*$//') +export target=${1:-/usr/local/share}/$feature + +### Logs +echo "Activating feature <$feature>" +echo "from <$source>" +echo "to <$target>" + +### Makes sure the target directory exists +mkdir -p $target + +### Install specific utils +find $source \( -name "_*" -o -name "install-*.sh" \) -type f -exec cp {} $target \; +find $target -type f -name "install-*.sh" -exec chmod +x {} \; -exec ln -s {} /usr/bin/ \; diff --git a/src/utils/devcontainer-feature.json b/src/utils/devcontainer-feature.json new file mode 100644 index 0000000..4d41ee1 --- /dev/null +++ b/src/utils/devcontainer-feature.json @@ -0,0 +1,19 @@ +{ + "name": "Common Utils", + "version": "1.0.0", + "description": "Common utils for tomgrv/devcontainer-features", + "dependsOn": { + "ghcr.io/devcontainers/features/common-utils": "lts" + }, + "id": "tomgrv-common-utils", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ], + "options": { + "utils": { + "type": "string", + "default": "jq dos2unix", + "description": "utilities to install" + } + } +} diff --git a/src/utils/install.sh b/src/utils/install.sh new file mode 100644 index 0000000..26050fa --- /dev/null +++ b/src/utils/install.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +### Options +UTILS="${UTILS:-"jq dos2unix"}" + +### Install utils +for bin in $UTILS; do + if [ -n "$(command -v $bin)" ]; then + echo "$bin is installed." + elif [ -f /etc/alpine-release ]; then + apk update + apk add $bin + elif [ $(uname) = "Linux" ] || [ $(uname) = "Darwin" ]; then + sudo apt-get update + sudo apt-get install -y $bin + else + echo "Please install $bin." + exit 1 + fi +done + +