-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfpf
More file actions
executable file
·127 lines (113 loc) · 3.36 KB
/
fpf
File metadata and controls
executable file
·127 lines (113 loc) · 3.36 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -euo pipefail
resolve_script_path() {
local source_path="$1"
local source_dir=""
local link_target=""
while [[ -h "${source_path}" ]]; do
source_dir="$(cd -P "$(dirname "${source_path}")" && pwd)"
link_target="$(readlink "${source_path}")"
if [[ "${link_target}" == /* ]]; then
source_path="${link_target}"
else
source_path="${source_dir}/${link_target}"
fi
done
source_dir="$(cd -P "$(dirname "${source_path}")" && pwd)"
printf "%s/%s" "${source_dir}" "$(basename "${source_path}")"
}
main() {
local script_path=""
local script_dir=""
local uname_s=""
local uname_m=""
local goos=""
local goarch=""
local candidate=""
script_path="$(resolve_script_path "${BASH_SOURCE[0]}")"
script_dir="$(cd -P "$(dirname "${script_path}")" && pwd)"
if [[ "${FPF_SKIP_GO_BOOTSTRAP:-0}" == "1" ]]; then
case "${OSTYPE:-}" in
linux*)
uname_s="Linux"
;;
darwin*)
uname_s="Darwin"
;;
msys*|cygwin*|win32*)
uname_s="MINGW"
;;
*)
uname_s="$(uname -s 2>/dev/null || true)"
;;
esac
uname_m="$(uname -m 2>/dev/null || true)"
case "${uname_m}" in
*x86_64*|*amd64*)
uname_m="x86_64"
;;
*aarch64*|*arm64*)
uname_m="arm64"
;;
esac
else
uname_s="$(uname -s 2>/dev/null || true)"
uname_m="$(uname -m 2>/dev/null || true)"
fi
case "${uname_s}" in
Linux)
goos="linux"
;;
Darwin)
goos="darwin"
;;
MINGW*|MSYS*|CYGWIN*)
goos="windows"
;;
*)
printf "fpf: unsupported OS '%s'\n" "${uname_s}" >&2
exit 1
;;
esac
case "${uname_m}" in
x86_64|amd64)
goarch="amd64"
;;
arm64|aarch64)
goarch="arm64"
;;
*)
goarch=""
;;
esac
if [[ -n "${goarch}" ]]; then
candidate="${script_dir}/bin/fpf-go-${goos}-${goarch}"
if [[ "${goos}" == "windows" ]]; then
candidate="${candidate}.exe"
fi
if [[ -x "${candidate}" ]]; then
export FPF_PACKAGE_JSON="${script_dir}/package.json"
exec "${candidate}" "$@"
fi
fi
for goarch in amd64 arm64; do
candidate="${script_dir}/bin/fpf-go-${goos}-${goarch}"
if [[ "${goos}" == "windows" ]]; then
candidate="${candidate}.exe"
fi
if [[ -x "${candidate}" ]]; then
export FPF_PACKAGE_JSON="${script_dir}/package.json"
exec "${candidate}" "$@"
fi
done
printf "fpf: missing packaged Go binary for %s/%s\n" "${goos}" "${uname_m}" >&2
printf "fpf: expected one of:\n" >&2
printf " %s/bin/fpf-go-%s-amd64\n" "${script_dir}" "${goos}" >&2
printf " %s/bin/fpf-go-%s-arm64\n" "${script_dir}" "${goos}" >&2
if [[ "${goos}" == "windows" ]]; then
printf " (with .exe suffix on Windows binaries)\n" >&2
fi
printf "fpf: run 'bash scripts/build-go-binaries.sh' to build local binaries.\n" >&2
exit 1
}
main "$@"