-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·209 lines (184 loc) · 5.56 KB
/
install.sh
File metadata and controls
executable file
·209 lines (184 loc) · 5.56 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
209
#!/bin/sh
# Copyright 2019-2025 the Deno authors. All rights reserved. MIT license.
# Copyright 2025 OpenStatus. All rights reserved. MIT license.
# Adopted from https://github.com/denoland/deno_install
set -e
if [ "$OS" = "Windows_NT" ]; then
target="Windows_x86_64.zip"
else
case $(uname -sm) in
"Darwin arm64") target="Darwin_arm64.tar.gz" ;;
"Darwin x86_64") target="Darwin_x86_64.tar.gz" ;;
"Linux x86_64") target="Linux_x86_64.tar.gz" ;;
"Linux aarch64") target="Linux_arm64.tar.gz" ;;
*) target="unknown" ;;
esac
fi
if [ "$target" = "unknown" ]; then
echo "Note: openstatus is not supported on this platform"
exit 0
fi
print_help_and_exit() {
echo "Setup script for installing openstatus
Options:
-y, --yes
Skip interactive prompts and accept defaults
--no-modify-path
Don't add openstatus to the PATH environment variable
-h, --help
Print help
"
echo "Note: openstatus was not installed"
exit 0
}
get_latest_version() {
curl --ssl-revoke-best-effort -s https://api.github.com/repos/openstatusHQ/cli/releases/latest | awk -F'"' '/"tag_name":/{print substr($4,1)}'
}
# Initialize variables
should_run_shell_setup=false
no_modify_path=false
# Simple arg parsing - look for help flag, otherwise
# ignore args starting with '-' and take the first
# positional arg as the deno version to install
for arg in "$@"; do
case "$arg" in
"-h")
print_help_and_exit
;;
"--help")
print_help_and_exit
;;
"-y")
should_run_shell_setup=true
;;
"--yes")
should_run_shell_setup=true
;;
"--no-modify-path")
no_modify_path=true
;;
"-"*) ;;
*)
if [ -z "$openstatus_version" ]; then
openstatus_version="$arg"
fi
;;
esac
done
if [ -z "$openstatus_version" ]; then
openstatus_version=$(get_latest_version)
fi
platform=$(echo "$target" | sed 's/\.\(tar\.gz\|zip\)$//')
echo "Installing openstatus ${openstatus_version} for ${platform}"
openstatus_uri="https://github.com/openstatusHQ/cli/releases/download/${openstatus_version}/cli_${target}"
openstatus_install="${OPENSTATUS_INSTALL:-$HOME/.openstatus}"
bin_dir="$openstatus_install/bin"
exe="$bin_dir/openstatus"
echo "Downloading openstatus from $openstatus_uri"
if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi
# Download and extract the archive
tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
if echo "$target" | grep -q "\.zip$"; then
# Windows zip file
curl --fail --location --progress-bar --output "$tmp_dir/openstatus.zip" "$openstatus_uri"
unzip -q "$tmp_dir/openstatus.zip" -d "$tmp_dir"
mv "$tmp_dir/openstatus.exe" "$exe"
else
# Unix tar.gz file
curl --fail --location --progress-bar --output "$tmp_dir/openstatus.tar.gz" "$openstatus_uri"
tar -xzf "$tmp_dir/openstatus.tar.gz" -C "$tmp_dir"
mv "$tmp_dir/openstatus" "$exe"
fi
chmod +x "$exe"
echo "openstatus was installed successfully to $exe"
run_shell_setup() {
local rc_files=""
local current_shell=""
# Try to detect the current shell more reliably
if [ -n "$SHELL" ]; then
current_shell=$(basename "$SHELL")
elif [ -n "$ZSH_VERSION" ]; then
current_shell="zsh"
elif [ -n "$BASH_VERSION" ]; then
current_shell="bash"
elif [ -n "$KSH_VERSION" ]; then
current_shell="ksh"
elif [ -n "$FISH_VERSION" ]; then
current_shell="fish"
else
current_shell="sh"
fi
# Determine which rc files to modify based on shell
case "$current_shell" in
zsh)
rc_files="$HOME/.zshrc"
;;
bash)
rc_files="$HOME/.bashrc"
# Add .bash_profile for login shells on macOS
if [ "$(uname -s)" = "Darwin" ]; then
rc_files="$rc_files $HOME/.bash_profile"
fi
;;
fish)
# Fish has a different way of setting PATH
mkdir -p "$HOME/.config/fish/conf.d"
echo "set -gx OPENSTATUS_INSTALL \"$openstatus_install\"" > "$HOME/.config/fish/conf.d/openstatus.fish"
echo "set -gx PATH \$OPENSTATUS_INSTALL/bin \$PATH" >> "$HOME/.config/fish/conf.d/openstatus.fish"
echo "Added openstatus to PATH in fish configuration"
return
;;
*)
# Default to .profile for other shells
rc_files="$HOME/.profile"
;;
esac
# Add setup line to each rc file
for rc_file in $rc_files; do
if [ ! -f "$rc_file" ]; then
touch "$rc_file"
fi
if ! grep -q "$openstatus_install/bin" "$rc_file"; then
echo "" >> "$rc_file"
echo "# openstatus setup" >> "$rc_file"
echo "export OPENSTATUS_INSTALL=\"$openstatus_install\"" >> "$rc_file"
echo "export PATH=\"\$OPENSTATUS_INSTALL/bin:\$PATH\"" >> "$rc_file"
echo "Added openstatus to PATH in $rc_file"
else
echo "openstatus already in PATH in $rc_file"
fi
done
echo "Restart your shell or run 'source $rc_file' to use openstatus"
}
# Add openstatus to PATH for non-Windows if needed
if [ "$OS" != "Windows_NT" ] && [ "$no_modify_path" = false ]; then
# If not automatic setup, but interactive is possible, ask user
if [ "$should_run_shell_setup" = false ] && [ -t 0 ]; then
echo ""
echo "Do you want to add openstatus to your PATH? [y/N]"
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
should_run_shell_setup=true
fi
fi
if [ "$should_run_shell_setup" = true ]; then
run_shell_setup
else
echo ""
echo "To manually add openstatus to your path:"
echo " export OPENSTATUS_INSTALL=\"$openstatus_install\""
echo " export PATH=\"\$OPENSTATUS_INSTALL/bin:\$PATH\""
echo ""
echo "To do this automatically in the future, run with -y or --yes"
fi
fi
if command -v openstatus >/dev/null; then
echo "Run 'openstatus --help' to get started"
else
echo "Run '$exe --help' to get started"
fi
echo
echo "Stuck? Join our Discord https://openstatus.dev/discord"