Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·154 lines (138 loc) · 3.64 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·154 lines (138 loc) · 3.64 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh
set -eu
repo=goat-agent/goat
base=https://github.com/$repo/releases/latest/download
app_home="${HOME}/.goat"
bin_dir="${app_home}/bin"
env_file="${app_home}/env"
source_line='. "$HOME/.goat/env"'
purple=''
reset=''
if [ -t 1 ]; then
purple='\033[35m'
reset='\033[0m'
fi
printf "%bgoat%b installer\n" "$purple" "$reset"
need() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "missing required command: $1" >&2
exit 1
fi
}
need uname
need tar
need mktemp
need grep
need awk
if command -v curl >/dev/null 2>&1; then
fetch() {
curl -fsSL "$1" -o "$2"
}
elif command -v wget >/dev/null 2>&1; then
fetch() {
wget -qO "$2" "$1"
}
else
echo "missing required command: curl or wget" >&2
exit 1
fi
os=$(uname -s)
arch=$(uname -m)
case "$os:$arch" in
Linux:x86_64)
target=x86_64-unknown-linux-gnu
;;
Linux:aarch64|Linux:arm64)
target=aarch64-unknown-linux-gnu
;;
Darwin:x86_64)
target=x86_64-apple-darwin
;;
Darwin:arm64)
target=aarch64-apple-darwin
;;
*)
echo "unsupported platform: $os $arch" >&2
exit 1
;;
esac
if command -v sha256sum >/dev/null 2>&1; then
verify() {
expected=$(grep " $archive" "$tmp/SHA256SUMS" | awk '{print $1}')
actual=$(sha256sum "$tmp/$archive" | awk '{print $1}')
test -n "$expected" && test "$expected" = "$actual"
}
elif command -v shasum >/dev/null 2>&1; then
verify() {
expected=$(grep " $archive" "$tmp/SHA256SUMS" | awk '{print $1}')
actual=$(shasum -a 256 "$tmp/$archive" | awk '{print $1}')
test -n "$expected" && test "$expected" = "$actual"
}
else
echo "missing required command: sha256sum or shasum" >&2
exit 1
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
archive=goat-$target.tar.gz
fetch "$base/$archive" "$tmp/$archive"
fetch "$base/SHA256SUMS" "$tmp/SHA256SUMS"
if ! verify; then
echo "checksum verification failed for $archive" >&2
exit 1
fi
mkdir -p "$tmp/extract"
tar -xzf "$tmp/$archive" -C "$tmp/extract"
test -f "$tmp/extract/goat"
mkdir -p "$bin_dir"
cp "$tmp/extract/goat" "$bin_dir/goat"
chmod 755 "$bin_dir/goat"
cat > "$env_file" <<'ENV'
case ":${PATH}:" in
*:"$HOME/.goat/bin":*)
;;
*)
export PATH="$HOME/.goat/bin:$PATH"
;;
esac
ENV
add_source() {
dir=$(dirname "$1")
[ -d "$dir" ] || return 0
if [ -f "$1" ] && grep -qF "$source_line" "$1" 2>/dev/null; then
return 0
fi
printf '\n%s\n' "$source_line" >> "$1"
}
add_source_if_exists() {
[ -f "$1" ] || return 0
add_source "$1"
}
add_source "$HOME/.profile"
add_source "$HOME/.bashrc"
add_source "${ZDOTDIR:-$HOME}/.zshenv"
add_source_if_exists "$HOME/.bash_profile"
add_source_if_exists "$HOME/.bash_login"
fish_root="${XDG_CONFIG_HOME:-$HOME/.config}/fish"
if [ -d "$fish_root" ] || command -v fish >/dev/null 2>&1; then
mkdir -p "$fish_root/conf.d"
cat > "$fish_root/conf.d/goat.fish" <<'FISH'
if not contains "$HOME/.goat/bin" $PATH
set -gx PATH "$HOME/.goat/bin" $PATH
end
FISH
fi
printf "%bgoat%b installed to %s\n" "$purple" "$reset" "$bin_dir/goat"
case ":${PATH}:" in
*:"$bin_dir":*)
;;
*)
echo "Run this now, or open a new terminal, to start using goat:"
echo " $source_line"
;;
esac
if [ -e /usr/local/bin/goat ] || [ -e /usr/local/bin/goat-update ]; then
echo "An older system install was found. Remove it so it no longer shadows the new one:"
echo " sudo rm -f /usr/local/bin/goat /usr/local/bin/goat-update"
echo "(the current installer uses $bin_dir and never writes to system directories)"
fi