-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.sh
56 lines (52 loc) · 1.26 KB
/
header.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
#!/usr/bin/env bash
#set -euo pipefail
_get_machine_info() {
# right now we are only linux x64
export ARCH_x64="x86_64"
export ARCH_AMD="amd64"
export KERNEL="linux"
}
_get_machine_info
TSV=$(cat <<EOF
name location template source
yq mikefarah/yq yq_${KERNEL}_${ARCH_AMD} github
argocd cli/cli gh_\${ersion}_${KERNEL}_${ARCH_x64}.tar.gz github
sh mvdan/sh shfmt_\${version}_${KERNEL}_${ARCH_AMD} github
kubectl kubernetes/kubernetes kubernetes-client_\${version}_${KERNEL}_${ARCH_AMD} github
EOF
)
app_lookup_name_from_repo() {
local repo
repo=$1
app="$(echo "$TSV" | grep -P " $repo\b" | awk '{print $1}')"
if [ -z "$app" ]; then
echo "error: no app found for $repo" >&2
return 1
fi
echo "$app"
}
app_lookup() {
local name result type_of
name=$1
type_of=$2
case "$type_of" in
"source")
result="$(echo "$TSV" | grep -w "^$name" | awk '{print $4}')"
;;
"location")
result="$(echo "$TSV" | grep -w "^$name" | awk '{print $2}')"
;;
"template")
result="$(echo "$TSV" | grep -w "^$name" | awk '{print $3}')"
;;
*)
echo "error: no such column $type_of" >&2
return 1
;;
esac
if [ -z "$result" ]; then
echo "error: no $type_of found for $name" >&2
return 1
fi
echo "$result"
}