Skip to content

Commit 8885076

Browse files
committed
bash: Write bootstrap.sh in POSIX sh to work with Alpine
Signed-off-by: Nathan Chancellor <[email protected]>
1 parent 79c13b2 commit 8885076

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

.shellcheckrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
disable=SC1090
22
disable=SC2030
33
disable=SC2031
4-
shell=bash

bash/bootstrap.sh

+38-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
set -euxo pipefail
3+
set -eux
44

55
tmp_dir=$(mktemp -d)
66

7-
curl -LSs https://github.com/nathanchance/env/tarball/main | tar -C "$tmp_dir" -xvzf - --strip-components=1
7+
is_available() {
8+
command -v "$1" >/dev/null 2>&1
9+
}
810

9-
"$tmp_dir"/python/root/"$(grep ^ID= /usr/lib/os-release | cut -d= -f2 | sed 's/"//g')".py "$@"
11+
if is_available curl; then
12+
dwnld_cmd="curl -LSs"
13+
elif is_available wget; then
14+
dwnld_cmd="wget -q -O-"
15+
else
16+
echo "[-] No suitable download command could be found!" >&2
17+
exit 1
18+
fi
19+
20+
$dwnld_cmd https://github.com/nathanchance/env/tarball/main | tar -C "$tmp_dir" -xvzf - --strip-components=1
21+
22+
python_root=$tmp_dir/python/root
23+
if [ ! -d "$python_root" ]; then
24+
echo "[-] $python_root could not be found, did download command fail?" >&2
25+
exit 1
26+
fi
27+
28+
for file in /etc/os-release /usr/lib/os-release; do
29+
# We don't care if this fails, we will fail on the next command
30+
if . $file >/dev/null 2>&1; then
31+
break
32+
fi
33+
done
34+
35+
if ! is_available python3; then
36+
if is_available apk; then
37+
apk add python3
38+
else
39+
echo "[-] No suitable command could be found to install python3" >&2
40+
fi
41+
fi
42+
43+
"$python_root"/"$ID".py "$@"

0 commit comments

Comments
 (0)