[READ-ONLY] Mirror of https://github.com/openstatusHQ/cli. OpenStatus CLI
www.openstatus.dev
cli
cli-app
synthetic-monitoring
1#!/bin/sh
2# Copyright 2019-2025 the Deno authors. All rights reserved. MIT license.
3# Copyright 2025 OpenStatus. All rights reserved. MIT license.
4# Adopted from https://github.com/denoland/deno_install
5
6set -e
7
8if [ "$OS" = "Windows_NT" ]; then
9 target="Windows_x86_64.zip"
10else
11 case $(uname -sm) in
12 "Darwin arm64") target="Darwin_arm64.tar.gz" ;;
13 "Darwin x86_64") target="Darwin_x86_64.tar.gz" ;;
14 "Linux x86_64") target="Linux_x86_64.tar.gz" ;;
15 "Linux aarch64") target="Linux_arm64.tar.gz" ;;
16 *) target="unknown" ;;
17 esac
18fi
19
20if [ "$target" = "unknown" ]; then
21 echo "Note: openstatus is not supported on this platform"
22 exit 0
23fi
24
25print_help_and_exit() {
26 echo "Setup script for installing openstatus
27
28Options:
29 -y, --yes
30 Skip interactive prompts and accept defaults
31 --no-modify-path
32 Don't add openstatus to the PATH environment variable
33 -h, --help
34 Print help
35"
36 echo "Note: openstatus was not installed"
37 exit 0
38}
39
40get_latest_version() {
41 curl --ssl-revoke-best-effort -s https://api.github.com/repos/openstatusHQ/cli/releases/latest | awk -F'"' '/"tag_name":/{print substr($4,1)}'
42}
43
44# Initialize variables
45should_run_shell_setup=false
46no_modify_path=false
47
48# Simple arg parsing - look for help flag, otherwise
49# ignore args starting with '-' and take the first
50# positional arg as the deno version to install
51for arg in "$@"; do
52 case "$arg" in
53 "-h")
54 print_help_and_exit
55 ;;
56 "--help")
57 print_help_and_exit
58 ;;
59 "-y")
60 should_run_shell_setup=true
61 ;;
62 "--yes")
63 should_run_shell_setup=true
64 ;;
65 "--no-modify-path")
66 no_modify_path=true
67 ;;
68 "-"*) ;;
69 *)
70 if [ -z "$openstatus_version" ]; then
71 openstatus_version="$arg"
72 fi
73 ;;
74 esac
75done
76
77if [ -z "$openstatus_version" ]; then
78 openstatus_version=$(get_latest_version)
79fi
80
81platform=$(echo "$target" | sed 's/\.\(tar\.gz\|zip\)$//')
82echo "Installing openstatus ${openstatus_version} for ${platform}"
83
84openstatus_uri="https://github.com/openstatusHQ/cli/releases/download/${openstatus_version}/cli_${target}"
85openstatus_install="${OPENSTATUS_INSTALL:-$HOME/.openstatus}"
86bin_dir="$openstatus_install/bin"
87exe="$bin_dir/openstatus"
88
89echo "Downloading openstatus from $openstatus_uri"
90if [ ! -d "$bin_dir" ]; then
91 mkdir -p "$bin_dir"
92fi
93
94# Download and extract the archive
95tmp_dir=$(mktemp -d)
96trap "rm -rf $tmp_dir" EXIT
97
98if echo "$target" | grep -q "\.zip$"; then
99 # Windows zip file
100 curl --fail --location --progress-bar --output "$tmp_dir/openstatus.zip" "$openstatus_uri"
101 unzip -q "$tmp_dir/openstatus.zip" -d "$tmp_dir"
102 mv "$tmp_dir/openstatus.exe" "$exe"
103else
104 # Unix tar.gz file
105 curl --fail --location --progress-bar --output "$tmp_dir/openstatus.tar.gz" "$openstatus_uri"
106 tar -xzf "$tmp_dir/openstatus.tar.gz" -C "$tmp_dir"
107 mv "$tmp_dir/openstatus" "$exe"
108fi
109
110chmod +x "$exe"
111
112echo "openstatus was installed successfully to $exe"
113
114run_shell_setup() {
115 local rc_files=""
116 local current_shell=""
117
118 # Try to detect the current shell more reliably
119 if [ -n "$SHELL" ]; then
120 current_shell=$(basename "$SHELL")
121 elif [ -n "$ZSH_VERSION" ]; then
122 current_shell="zsh"
123 elif [ -n "$BASH_VERSION" ]; then
124 current_shell="bash"
125 elif [ -n "$KSH_VERSION" ]; then
126 current_shell="ksh"
127 elif [ -n "$FISH_VERSION" ]; then
128 current_shell="fish"
129 else
130 current_shell="sh"
131 fi
132
133 # Determine which rc files to modify based on shell
134 case "$current_shell" in
135 zsh)
136 rc_files="$HOME/.zshrc"
137 ;;
138 bash)
139 rc_files="$HOME/.bashrc"
140 # Add .bash_profile for login shells on macOS
141 if [ "$(uname -s)" = "Darwin" ]; then
142 rc_files="$rc_files $HOME/.bash_profile"
143 fi
144 ;;
145 fish)
146 # Fish has a different way of setting PATH
147 mkdir -p "$HOME/.config/fish/conf.d"
148 echo "set -gx OPENSTATUS_INSTALL \"$openstatus_install\"" > "$HOME/.config/fish/conf.d/openstatus.fish"
149 echo "set -gx PATH \$OPENSTATUS_INSTALL/bin \$PATH" >> "$HOME/.config/fish/conf.d/openstatus.fish"
150 echo "Added openstatus to PATH in fish configuration"
151 return
152 ;;
153 *)
154 # Default to .profile for other shells
155 rc_files="$HOME/.profile"
156 ;;
157 esac
158
159 # Add setup line to each rc file
160 for rc_file in $rc_files; do
161 if [ ! -f "$rc_file" ]; then
162 touch "$rc_file"
163 fi
164
165 if ! grep -q "$openstatus_install/bin" "$rc_file"; then
166 echo "" >> "$rc_file"
167 echo "# openstatus setup" >> "$rc_file"
168 echo "export OPENSTATUS_INSTALL=\"$openstatus_install\"" >> "$rc_file"
169 echo "export PATH=\"\$OPENSTATUS_INSTALL/bin:\$PATH\"" >> "$rc_file"
170 echo "Added openstatus to PATH in $rc_file"
171 else
172 echo "openstatus already in PATH in $rc_file"
173 fi
174 done
175
176 echo "Restart your shell or run 'source $rc_file' to use openstatus"
177}
178
179# Add openstatus to PATH for non-Windows if needed
180if [ "$OS" != "Windows_NT" ] && [ "$no_modify_path" = false ]; then
181 # If not automatic setup, but interactive is possible, ask user
182 if [ "$should_run_shell_setup" = false ] && [ -t 0 ]; then
183 echo ""
184 echo "Do you want to add openstatus to your PATH? [y/N]"
185 read -r answer
186 if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
187 should_run_shell_setup=true
188 fi
189 fi
190
191 if [ "$should_run_shell_setup" = true ]; then
192 run_shell_setup
193 else
194 echo ""
195 echo "To manually add openstatus to your path:"
196 echo " export OPENSTATUS_INSTALL=\"$openstatus_install\""
197 echo " export PATH=\"\$OPENSTATUS_INSTALL/bin:\$PATH\""
198 echo ""
199 echo "To do this automatically in the future, run with -y or --yes"
200 fi
201fi
202
203if command -v openstatus >/dev/null; then
204 echo "Run 'openstatus --help' to get started"
205else
206 echo "Run '$exe --help' to get started"
207fi
208echo
209echo "Stuck? Join our Discord https://openstatus.dev/discord"