Skip to content

Commit

Permalink
feat: ✨ add common utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgrv authored Dec 27, 2024
1 parent 8bbc3cf commit 9c8717a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- @format -->

# 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.
19 changes: 19 additions & 0 deletions src/utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
21 changes: 21 additions & 0 deletions src/utils/install-feature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

### Init directories
caller_filename=$(ps -o args= $PPID)
caller_filepath=$(readlink -f ${caller_filename##/bin/sh})
export source=$(dirname $caller_filepath)
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/ \;
25 changes: 25 additions & 0 deletions src/utils/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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

### Init directories
export source=$(dirname $(readlink -f $0))
$source/install-feature.sh

0 comments on commit 9c8717a

Please sign in to comment.