-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·208 lines (167 loc) · 5.33 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·208 lines (167 loc) · 5.33 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
if [ -z "${BASH_VERSION:-}" ]; then
exec /usr/bin/env bash "$0" "$@"
fi
set -euo pipefail
# --- Configuration ---
REPO="Wave-cli/wave-core"
API_URL="https://api.github.com/repos/${REPO}/releases/latest"
# Global variable for cleanup
tmp_dir=""
# --- Helper Functions ---
die() {
printf "\033[0;31mError: %s\033[0m\n" "$*" >&2
exit 1
}
have() {
command -v "$1" >/dev/null 2>&1
}
detect_platform() {
local os arch
have uname || die "uname is required to detect platform"
os=$(uname -s)
arch=$(uname -m)
case "${os}" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) die "Unsupported OS: ${os}" ;;
esac
case "${arch}" in
x86_64 | amd64) arch="amd64" ;;
arm64 | aarch64) arch="arm64" ;;
*) die "Unsupported architecture: ${arch}" ;;
esac
printf "%s %s" "${os}" "${arch}"
}
select_http_client() {
if have curl; then
fetch() { curl -fsSL "$1"; }
download() { curl -fsSL -o "$2" "$1"; }
elif have wget; then
fetch() { wget -qO- "$1"; }
download() { wget -qO "$2" "$1"; }
else
die "curl or wget is required"
fi
}
get_installed_path() {
if have wave; then
command -v wave
else
return 1
fi
}
do_uninstall() {
local binary_path
binary_path=$(get_installed_path) || {
echo "wave is not installed."
exit 0
}
echo "Found wave at ${binary_path}. Uninstalling..."
if [ -w "${binary_path}" ]; then
rm "${binary_path}"
else
echo "Requesting sudo to remove ${binary_path}..."
sudo rm "${binary_path}"
fi
echo "Successfully uninstalled wave."
exit 0
}
resolve_install_dir() {
if [ -n "${WAVE_INSTALL_DIR:-}" ]; then
echo "${WAVE_INSTALL_DIR}"
return
fi
if [ -t 0 ]; then
echo "------------------------------------------------" >&2
echo "Where would you like to install wave?" >&2
echo "1) Only for me (~/.local/bin)" >&2
echo "2) System-wide (/usr/local/bin) - Needs sudo" >&2
echo "------------------------------------------------" >&2
printf "Select [1-2, default 1]: " >&2
read -r choice
if [ "${choice}" = "2" ]; then
echo "/usr/local/bin"
return
fi
fi
if [ "$(uname -s)" = "Darwin" ]; then
echo "/usr/local/bin"
else
echo "${HOME}/.local/bin"
fi
}
# --- The New Banner ---
print_banner() {
printf "\033[0;36m"
cat <<'EOF'
██╗ ██╗ █████╗ ██╗ ██╗███████╗ ██████╗██╗ ██╗
██║ ██║██╔══██╗██║ ██║██╔════╝ ██╔════╝██║ ██║
██║ █╗ ██║███████║██║ ██║█████╗ ██║ ██║ ██║
██║███╗██║██╔══██║╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║
╚███╔███╔╝██║ ██║ ╚████╔╝ ███████╗ ╚██████╗███████╗██║
╚══╝╚══╝ ╚═╝ ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝╚══════╝╚═╝
EOF
printf "\033[0m\n"
}
# --- Main Logic ---
main() {
if [[ "${1:-}" == "--uninstall" ]]; then
do_uninstall
fi
print_banner
select_http_client
local platform os arch asset_name bin_name release_json latest_tag download_url install_dir
local archive_path extracted_bin
platform=$(detect_platform)
os=$(echo "${platform}" | cut -d' ' -f1)
arch=$(echo "${platform}" | cut -d' ' -f2)
asset_name="wave-${os}-${arch}.tar.gz"
bin_name="wave-${os}-${arch}"
echo "Checking for latest release..."
release_json=$(fetch "${API_URL}")
latest_tag=$(echo "${release_json}" | grep '"tag_name":' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/' | head -n 1)
download_url=$(echo "${release_json}" | grep -o "https://github.com/${REPO}/releases/download/[^\" ]*${asset_name}" | head -n 1)
if [ -z "${download_url}" ]; then
die "Could not find asset ${asset_name} in release ${latest_tag:-unknown}"
fi
install_dir=$(resolve_install_dir)
tmp_dir=$(mktemp -d)
trap 'if [ -n "${tmp_dir:-}" ]; then rm -rf "${tmp_dir}"; fi' EXIT
archive_path="${tmp_dir}/${asset_name}"
echo "Downloading wave ${latest_tag}..."
download "${download_url}" "${archive_path}"
echo "Extracting..."
tar -xzf "${archive_path}" -C "${tmp_dir}"
if [ -f "${tmp_dir}/${bin_name}" ]; then
extracted_bin="${tmp_dir}/${bin_name}"
elif [ -f "${tmp_dir}/wave" ]; then
# Backward compatibility for older archives.
extracted_bin="${tmp_dir}/wave"
else
die "Binary '${bin_name}' not found in archive."
fi
if [ ! -d "${install_dir}" ]; then
if [ -w "$(dirname "${install_dir}" 2>/dev/null || echo ".")" ]; then
mkdir -p "${install_dir}"
else
sudo mkdir -p "${install_dir}"
fi
fi
if [ -w "${install_dir}" ]; then
chmod +x "${extracted_bin}"
mv "${extracted_bin}" "${install_dir}/wave"
else
echo "Requesting sudo to install..."
sudo chmod +x "${extracted_bin}"
sudo mv "${extracted_bin}" "${install_dir}/wave"
fi
echo -e "\n\033[0;32m✓ wave ${latest_tag} installed to ${install_dir}/wave\033[0m"
case ":${PATH}:" in
*":${install_dir}:"*) ;;
*)
echo -e "\033[0;33mNote:\033[0m Add ${install_dir} to your PATH."
;;
esac
}
main "$@"