Skip to content

Commit b6041a5

Browse files
chore: improve installation scripts
1 parent ba362e9 commit b6041a5

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

INSTALL.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Or with wget:
5353
wget -qO- https://raw.githubusercontent.com/speakeasy-api/openapi/main/scripts/install.sh | bash
5454
```
5555

56+
The script automatically detects if you have write permission to `/usr/local/bin`. If not, it installs to `~/.local/bin` instead. No sudo required!
57+
5658
### Windows (PowerShell)
5759

5860
```powershell
@@ -268,24 +270,24 @@ The PowerShell script automatically adds the installation directory to your PATH
268270

269271
### Permission Denied (Linux/macOS)
270272

271-
If you get permission errors when installing to `/usr/local/bin`:
273+
The installation script automatically detects if you have write permission to `/usr/local/bin` and falls back to `~/.local/bin` if needed. However, if you still encounter permission issues:
272274

273-
**Option 1:** Run with sudo (not recommended for the curl pipe method)
275+
**Option 1:** Explicitly set a user-writable directory
274276

275277
```bash
276-
# Download script first, review it, then run with sudo
277-
curl -fsSL https://raw.githubusercontent.com/speakeasy-api/openapi/main/scripts/install.sh -o install.sh
278-
chmod +x install.sh
279-
sudo ./install.sh
278+
OPENAPI_INSTALL_DIR=$HOME/.local/bin curl -fsSL https://raw.githubusercontent.com/speakeasy-api/openapi/main/scripts/install.sh | bash
280279
```
281280

282-
**Option 2:** Install to a user-writable directory
281+
**Option 2:** Run with sudo (download and review first)
283282

284283
```bash
285-
OPENAPI_INSTALL_DIR=$HOME/.local/bin curl -fsSL https://raw.githubusercontent.com/speakeasy-api/openapi/main/scripts/install.sh | bash
284+
# Download script first, review it, then run with sudo
285+
curl -fsSL https://raw.githubusercontent.com/speakeasy-api/openapi/main/scripts/install.sh -o install.sh
286+
chmod +x install.sh
287+
sudo ./install.sh
286288
```
287289

288-
Then ensure `$HOME/.local/bin` is in your PATH.
290+
If installed to `~/.local/bin`, ensure it's in your PATH (see [Command Not Found](#command-not-found-after-installation)).
289291

290292
### Windows Git Bash Issues
291293

scripts/install.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ set -e
1818

1919
# Configuration
2020
REPO="speakeasy-api/openapi"
21-
INSTALL_DIR="${OPENAPI_INSTALL_DIR:-/usr/local/bin}"
21+
DEFAULT_INSTALL_DIR="/usr/local/bin"
22+
USER_INSTALL_DIR="$HOME/.local/bin"
2223
VERSION="${OPENAPI_VERSION:-latest}"
2324
BINARY_NAME="openapi"
2425

@@ -88,13 +89,34 @@ get_latest_version() {
8889
echo "$version"
8990
}
9091

92+
# Determine installation directory
93+
get_install_dir() {
94+
# If user specified a directory, use it
95+
if [ -n "$OPENAPI_INSTALL_DIR" ]; then
96+
echo "$OPENAPI_INSTALL_DIR"
97+
return
98+
fi
99+
100+
# Try to use /usr/local/bin if we have write access
101+
if [ -w "$DEFAULT_INSTALL_DIR" ] || [ -w "$(dirname "$DEFAULT_INSTALL_DIR")" ]; then
102+
echo "$DEFAULT_INSTALL_DIR"
103+
return
104+
fi
105+
106+
# Fall back to user directory
107+
log_info "No write access to $DEFAULT_INSTALL_DIR, using $USER_INSTALL_DIR instead"
108+
echo "$USER_INSTALL_DIR"
109+
}
110+
91111
# Download and install
92112
install_cli() {
113+
local INSTALL_DIR=$(get_install_dir)
93114
local os=$(detect_os)
94115
local arch=$(detect_arch)
95116

96117
log_info "Detected OS: $os"
97118
log_info "Detected Architecture: $arch"
119+
log_info "Installation directory: $INSTALL_DIR"
98120

99121
# Get version
100122
if [ "$VERSION" = "latest" ]; then
@@ -191,7 +213,10 @@ install_cli() {
191213
if [ "$os" = "Windows" ]; then
192214
log_warn "Add $INSTALL_DIR to your PATH environment variable."
193215
else
194-
log_warn "Add $INSTALL_DIR to your PATH or run: export PATH=\"$INSTALL_DIR:\$PATH\""
216+
log_warn "Add $INSTALL_DIR to your PATH by adding this to your ~/.bashrc or ~/.zshrc:"
217+
log_warn " export PATH=\"\$PATH:$INSTALL_DIR\""
218+
log_warn ""
219+
log_warn "Then run: source ~/.bashrc # or source ~/.zshrc"
195220
fi
196221
fi
197222
}

0 commit comments

Comments
 (0)