Skip to content

Commit 121c535

Browse files
Refactor script to support version and install path
1 parent b8a1329 commit 121c535

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

src/shellcheck/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Install [ShellCheck](https://www.shellcheck.net), a static analysis tool for she
1010
}
1111
```
1212

13+
## Options
14+
15+
| Option ID | Description | Type | Default Value |
16+
|:--------------|:---------------------------------------------|:-------|:-----------------|
17+
| `version` | The ShellCheck version to install. | string | `os-provided` |
18+
| `installPath` | The path where ShellCheck will be installed. | string | `/usr/local/bin` |
19+
1320
## OS Support
1421

1522
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool.
23+
24+
`bash` is required to execute the `install.sh` script.

src/shellcheck/devcontainer-feature.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
"id": "shellcheck",
44
"version": "1.0.0",
55
"description": "Install ShellCheck, a static analysis tool for shell scripts.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"proposals": [
10+
"latest",
11+
"os-provided"
12+
],
13+
"default": "os-provided",
14+
"description": "Select or enter a ShellCheck version."
15+
}
16+
},
617
"installsAfter": [
718
"ghcr.io/devcontainers/features/common-utils"
819
]
920
}
10-

src/shellcheck/install.sh

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
set -e
44

5+
SHELLCHECK_VERSION="${VERSION:-"os-provided"}"
6+
INSTALL_PATH="${INSTALLPATH:-"/usr/local/bin"}"
7+
58
if [ "$(id -u)" -ne 0 ]; then
69
printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
710
exit 1
811
fi
912

10-
apt update --yes
11-
apt install --no-install-recommends --yes shellcheck
13+
14+
if [ "${SHELLCHECK_VERSION}" = "os-provided" ]; then
15+
apt update --yes
16+
apt install --no-install-recommends --yes shellcheck
17+
18+
exit 0
19+
fi
20+
21+
curl_installed=""
22+
23+
if ! type curl >/dev/null 2>&1; then
24+
apt update --yes
25+
apt install --no-install-recommends --yes curl ca-certificates
26+
27+
curl_installed="true"
28+
fi
29+
30+
if [ "${SHELLCHECK_VERSION}" = "latest" ]; then
31+
SHELLCHECK_VERSION=$(curl -s --head https://github.com/koalaman/shellcheck/releases/latest | sed -nr 's/location:.*\/v(.+)/\1/ip' | tr -d '\r')
32+
fi
33+
34+
machine="$(uname -m)"
35+
case "${machine}" in
36+
aarch64) arch="aarch64" ;;
37+
arm*) arch="armv6" ;;
38+
x86_64) arch="x86_64" ;;
39+
*)
40+
echo "Could not determine arch from machine hardware name '${machine}'" >&2
41+
exit 1
42+
;;
43+
esac
44+
45+
# https://github.com/koalaman/shellcheck/releases/download/v0.9.0/shellcheck-v0.9.0.linux.aarch64.tar.xz
46+
url="https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.${arch}.tar.xz"
47+
48+
curl -sSL "${url}" | tar --strip-components=1 -Jxvf - -C "${INSTALL_PATH}" "shellcheck-v${SHELLCHECK_VERSION}/shellcheck"
49+
50+
if [ -n "${curl_installed}" ]; then
51+
apt purge curl --autoremove --yes
52+
fi

0 commit comments

Comments
 (0)