Skip to content

Commit 27efa6f

Browse files
authored
Feature/pkgx.sh (#9)
* feat(`pkgx.sh`): Add feature. * feat(`pkgx.sh`): Fix installer.
1 parent 8dd4049 commit 27efa6f

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- atuin.sh
1717
- btop
1818
- deno.com
19+
- pkgx.sh
1920
- smallstep.com
2021
- starship.rs
2122
baseImage:
@@ -40,6 +41,7 @@ jobs:
4041
- atuin.sh
4142
- btop
4243
- deno.com
44+
- pkgx.sh
4345
- smallstep.com
4446
- starship.rs
4547
steps:

src/pkgx.sh/devcontainer-feature.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "pkgx.sh",
3+
"id": "pkgx.sh",
4+
"version": "1.0.0",
5+
"description": "Install \"pkgx\" binary",
6+
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/pkgx.sh",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"default": "latest",
11+
"proposals": [
12+
"latest"
13+
],
14+
"description": "Version of \"pkgx\" to install."
15+
}
16+
}
17+
}

src/pkgx.sh/install.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -o errexit
3+
set -o pipefail
4+
set -o noclobber
5+
set -o nounset
6+
set -o allexport
7+
readonly name="pkgx"
8+
apt_get_cleanup() {
9+
apt-get clean
10+
rm -rf /var/lib/apt/lists/*
11+
}
12+
apt_get_update() {
13+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
14+
echo "Running apt-get update..."
15+
apt-get update -y
16+
fi
17+
}
18+
apt_get_checkinstall() {
19+
if ! dpkg -s "$@" >/dev/null 2>&1; then
20+
apt_get_update
21+
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@"
22+
fi
23+
}
24+
check_curl_installed() {
25+
declare -a requiredAptPackagesMissing=()
26+
if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then
27+
requiredAptPackagesMissing+=('ca-certificates')
28+
fi
29+
if ! command -v curl >/dev/null 2>&1; then
30+
requiredAptPackagesMissing+=('curl')
31+
fi
32+
declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]}
33+
if [ $requiredAptPackagesMissingCount -gt 0 ]; then
34+
apt_get_checkinstall "${requiredAptPackagesMissing[@]}"
35+
apt_get_cleanup
36+
fi
37+
}
38+
echo_banner() {
39+
local text="$1"
40+
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
41+
}
42+
install() {
43+
check_curl_installed
44+
apt_get_update
45+
export DENO_INSTALL="/usr/local"
46+
curl -fsSL https://pkgx.sh | sh
47+
apt_get_cleanup
48+
}
49+
echo_banner "devcontainer.community"
50+
echo "Installing $name..."
51+
install "$@"
52+
echo "(*) Done!"

test/pkgx.sh/pkgx.sh-debian.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
4+
set -e
5+
6+
# Optional: Import test library bundled with the devcontainer CLI
7+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
8+
# Provides the 'check' and 'reportResults' commands.
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
13+
# check <LABEL> <cmd> [args...]
14+
check "execute command" bash -c "pkgx --version | grep 'pkgx'"
15+
16+
# Report results
17+
# If any of the checks above exited with a non-zero exit code, the test will fail.
18+
reportResults

test/pkgx.sh/scenarios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"pkgx.sh-debian": {
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
4+
"features": {
5+
"pkgx.sh": {
6+
}
7+
}
8+
}
9+
}

test/pkgx.sh/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
4+
set -e
5+
6+
# Optional: Import test library bundled with the devcontainer CLI
7+
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
8+
# Provides the 'check' and 'reportResults' commands.
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
13+
# check <LABEL> <cmd> [args...]
14+
check "execute command" bash -c "pkgx --version | grep 'pkgx'"
15+
16+
# Report results
17+
# If any of the checks above exited with a non-zero exit code, the test will fail.
18+
reportResults

0 commit comments

Comments
 (0)