Skip to content

Commit e758603

Browse files
committed
Add simple script for detecting the bashbrew architecture of a system
1 parent 2ed9d91 commit e758603

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/bashbrew-host-arch.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
found() {
5+
echo "$@"
6+
exit
7+
}
8+
9+
arch=
10+
if command -v apk > /dev/null && tryArch="$(apk --print-arch)"; then
11+
arch="$tryArch"
12+
elif command -v dpkg > /dev/null && tryArch="$(dpkg --print-architecture)"; then
13+
arch="${tryArch##*-}"
14+
elif command -v uname > /dev/null && tryArch="$(uname -m)"; then
15+
echo >&2 "warning: neither of 'dpkg' or 'apk' found, falling back to 'uname'"
16+
arch="$tryArch"
17+
18+
os="$(uname -o 2>/dev/null || :)"
19+
case "$os" in
20+
Cygwin | Msys)
21+
# TODO support non-amd64 Windows
22+
found 'windows-amd64'
23+
;;
24+
esac
25+
fi
26+
27+
case "$arch" in
28+
amd64 | x86_64) found 'amd64' ;;
29+
arm64 | aarch64) found 'arm64v8' ;;
30+
armel) found 'arm32v5' ;;
31+
armv7) found 'arm32v7' ;;
32+
i[3456]86 | x86) found 'i386' ;;
33+
mips64el) found 'mips64le' ;; # TODO "uname -m" is just "mips64" (which is also "apk --print-arch" on big-endian MIPS) so we ought to disambiguate that somehow
34+
ppc64el | ppc64le) found 'ppc64le' ;;
35+
riscv64) found 'riscv64' ;;
36+
s390x) found 's390x' ;;
37+
38+
armhf)
39+
if [ -s /etc/os-release ] && id="$(grep -Em1 '^ID=[^[:space:]]+$' /etc/os-release)"; then
40+
eval "$id"
41+
case "${ID:-}" in
42+
alpine | raspbian) found 'arm32v6' ;;
43+
*) found 'arm32v7' ;;
44+
esac
45+
else
46+
echo >&2 "warning: '$arch' is ambiguous (and '/etc/os-release' is missing 'ID=xxx'), assuming 'arm32v6' for safety"
47+
found 'arm32v6'
48+
fi
49+
;;
50+
51+
*)
52+
echo >&2 "error: unknown architecture: '$arch'"
53+
exit 1
54+
;;
55+
esac

0 commit comments

Comments
 (0)