forked from nodejs/docker-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
executable file
·72 lines (65 loc) · 1.88 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Utlity functions
# Get system architecture
#
# This is used to get the target architecture for docker image.
# For crossing building, we need a way to specify the target
# architecutre manually.
function get_arch() {
local arch
case $(uname -m) in
x86_64)
arch="amd64"
;;
ppc64le)
arch="ppc64le"
;;
s390x)
arch="s390x"
;;
aarch64)
arch="arm64"
;;
armv7l)
arch="arm32v7"
;;
*)
echo "$0 does not support architecture $arch ... aborting"
exit 1
;;
esac
echo "$arch"
}
# Get corresponding variants based on the architecture.
# All supported variants of each supported architecutre are listed in a
# file - 'architectures'. Its format is:
# <architecutre 1> <supported variant 1 >,<supported variant 2>...
# <architecutre 2> <supported variant 1 >,<supported variant 2>...
function get_variants() {
local arch
arch=$(get_arch)
local variants
variants=$(grep "^$arch" architectures | sed -E 's/'"$arch"'\s*//' | sed -E 's/,/ /g')
echo "$variants"
}
# Get supported architectures for a specific version and variant
#
# Get default supported architectures from 'architectures'. Then go to the version folder
# to see if there is a local architectures file. The local architectures will override the
# default architectures. This will give us some benefits:
# - a specific version may or may not support some architectures
# - if there is no specialization for a version, just don't provide local architectures
function get_supported_arches () {
local version
local variant
local arches
version="$1"; shift
variant="$1"; shift
# Get default supported arches
arches=$( grep "$variant" architectures 2>/dev/null | cut -d' ' -f1 )
# Get version specific supported architectures if there is specialized information
if [ -a "$version"/architectures ]; then
arches=$( grep "$variant" "$version"/architectures 2>/dev/null | cut -d' ' -f1 )
fi
echo "$arches"
}