generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
232 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
### Get indent size from devcontainer.json with jq, default to 2 if not found | ||
export tabSize=$(sed 's/\/\/.*//' .devcontainer/devcontainer.json | jq '.customizations.vscode.settings["editor.tabSize"] // 2') | ||
|
||
### Init directories | ||
ps -o args= $PPID | ||
caller_filename=$(ps -o args= $PPID | awk '{print $NF}') | ||
caller_filepath=$(readlink -f ${caller_filename}) | ||
export source=$(dirname $caller_filepath) | ||
export feature=$(basename $source | sed 's/_.*$//') | ||
export target=${1:-/usr/local/share}/$feature | ||
|
||
echo "Configuring feature <$feature>" | ||
echo "from <$source>" | ||
echo "to <$target>" | ||
|
||
### Go to the module root | ||
cd "$(git rev-parse --show-toplevel)" >/dev/null | ||
|
||
### Create package.json if not exists or is empty | ||
echo "Merge all package folder json files into top level package.json" | npx --yes chalk-cli --stdin blue | ||
if [ ! -f package.json -o ! -s package.json ]; then | ||
# Create empty package.json | ||
echo "{}" >package.json | ||
else | ||
# Pre-sort | ||
npx --yes sort-package-json | ||
fi | ||
|
||
### Merge all package folder json files into top level package.json | ||
find $source -name _*.json | sort | while read file; do | ||
echo "Merge $file" | npx --yes chalk-cli --stdin yellow | ||
jq --indent ${tabSize:-2} -s '.[0] * .[1]' $file package.json >/tmp/package.json && mv -f /tmp/package.json package.json | ||
done | ||
|
||
### Call all configure-xxx.sh scripts | ||
find $source -name configure-*.sh | sort | while read file; do | ||
echo "Run $file" | npx --yes chalk-cli --stdin yellow | ||
$file || true | ||
done | ||
|
||
### Sort package.json | ||
npx --yes sort-package-json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/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 "configure-*.sh" \) -type f -exec cp {} $target \; | ||
find $target -type f -name "*.sh" -exec chmod +x {} \; | ||
|
||
### Call all the install-xxx scripts in the feature directory | ||
echo "Calling all install scripts in $source..." | ||
find $source -type f -name "install-*.sh" | while read script; do | ||
echo "Calling $script..." | ||
sh $script | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/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 "Merging stubs files of <$feature>" | ||
echo "from <$source>" | ||
echo "to <$target>" | ||
|
||
### Merge all files from stub folder to root with git merge-file | ||
for file in $(find $source/stubs -type f); do | ||
|
||
### Get middle part of the path | ||
folder=$(dirname ${file#$source/stubs/}) | ||
|
||
### Create folder if not exists | ||
mkdir -p $folder | ||
|
||
### Merge file | ||
echo "Merge $folder/$(basename $file)" | ||
git merge-file -p $file $folder/$(basename $file) ${folder#$source/}/$(basename $file) >$folder/$(basename $file) | ||
|
||
### Apply rights | ||
chmod $(stat -c "%a" $file) $folder/$(basename $file) | ||
done | ||
|
||
### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash | ||
echo "Add files to .gitignore" | ||
for file in $(find . -type f -name "#*" ! -path "*/stubs/*" ! -path "./node_modules/*" ! -path "./vendors/*"); do | ||
|
||
echo "Add $file to .gitignore" | ||
|
||
### Remove # occurences in file path | ||
clean=${file#./#} | ||
|
||
### Add to .gitignore if not already there | ||
grep -qxF $clean .gitignore || echo "$clean" >>.gitignore | ||
|
||
### Rename file | ||
mv $file $clean | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Common Utils", | ||
"version": "1.1.3", | ||
"description": "Common utils for tomgrv/devcontainer-features", | ||
"dependsOn": { | ||
"ghcr.io/devcontainers/features/common-utils": {} | ||
}, | ||
"id": "common-utils", | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/common-utils" | ||
], | ||
"options": { | ||
"utils": { | ||
"type": "string", | ||
"default": "jq dos2unix", | ||
"description": "utilities to install" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
### Create links to utils in /usr/bin | ||
find $target -type f -name "_*.sh" -exec echo {} \; -exec chmod +x {} \; | while read file | ||
do | ||
link=/usr/bin/$(basename $file | sed -e 's/^_//' -e 's/.sh$//') | ||
rm -f $link || true | ||
ln -s $file $link || true | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/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 | ||
|
||
### Install this feature | ||
$(dirname $0)/_install-feature.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,5 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
### Check if utils are installed | ||
utils() { | ||
for bin in $* dos2unix jq; 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 | ||
} && utils | ||
|
||
### Init directories | ||
export source=$(dirname $(readlink -f $0)) | ||
export feature=$(basename $source | sed 's/_.*$//') | ||
export target=${1:-/usr/local/share}/$feature | ||
echo "Activating feature <$feature>..." | ||
|
||
### Makes sure the target directory exists | ||
mkdir -p $target | ||
|
||
### Copy the config script to the target directory and create a git alias for it | ||
find $source \( -name "_*" -o -name "configure*.sh" \) -type f -exec cp {} $target \; | ||
find $target -type f -name "*.sh" -exec chmod +x {} \; | ||
|
||
### Call all the install-xxx scripts in the feature directory | ||
echo "Calling all install scripts in $source..." | ||
find $source -type f -name "install-*.sh" | while read script; do | ||
echo "Calling $script..." | ||
sh $script | ||
done | ||
### Install feature | ||
install-feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters