Skip to content

Commit ee6313d

Browse files
committed
Add thv install script
Signed-off-by: Dan Barr <[email protected]>
1 parent 18e6b9a commit ee6313d

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"name": "Docusaurus",
33
"image": "mcr.microsoft.com/devcontainers/typescript-node:22-bookworm",
4-
"features": {},
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
6+
},
57
"forwardPorts": [3000],
6-
"postCreateCommand": "npm install",
8+
"containerEnv": {
9+
"CI": "true"
10+
},
11+
"postStartCommand": "bash scripts/install-thv.sh && npm install",
712
"customizations": {
813
"vscode": {
914
"extensions": [

scripts/install-thv.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# This script installs the ToolHive CLI (thv) in a portable way that works
6+
# across different environments (dev containers, CI/CD, Vercel, etc.).
7+
8+
set -euo pipefail
9+
10+
# Check if jq is installed
11+
if ! command -v jq >/dev/null 2>&1; then
12+
echo "Error: 'jq' is required but not installed. Please install jq and try again."
13+
exit 1
14+
fi
15+
16+
API_ENDPOINT="https://api.github.com/repos/stacklok/toolhive/releases/latest"
17+
18+
# Fetch release information
19+
RELEASE_JSON=$(curl -sf "$API_ENDPOINT" || {
20+
echo "Failed to fetch release information from GitHub API"
21+
exit 1
22+
})
23+
RELEASE_VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name // empty' | sed 's/^v//')
24+
RELEASE_TARBALL=$(echo "$RELEASE_JSON" | jq -r \
25+
--arg version "$RELEASE_VERSION" \
26+
'.assets[] | select(.name == "toolhive_" + $version + "_linux_amd64.tar.gz") | .browser_download_url // empty')
27+
28+
if [ -z "$RELEASE_TARBALL" ]; then
29+
echo "Failed to get release tarball URL for release: ${RELEASE_VERSION}"
30+
echo "Please check if the tag exists in the repository"
31+
exit 1
32+
fi
33+
34+
# Determine installation location based on write permissions
35+
if [[ -w "/usr/local/bin" ]]; then
36+
# Can write to /usr/local/bin (e.g., CI/CD environments like Vercel)
37+
INSTALL_DIR="/usr/local/bin"
38+
echo "Installing to /usr/local/bin"
39+
else
40+
# Use user-local directory (e.g., dev containers)
41+
INSTALL_DIR="$HOME/.local/bin"
42+
echo "Installing to ~/.local/bin"
43+
44+
# Create user bin directory if it doesn't exist
45+
mkdir -p "$INSTALL_DIR"
46+
47+
# Automatically add ~/.local/bin to PATH in shell profile files
48+
for profile in ~/.bashrc ~/.zshrc ~/.profile; do
49+
if [[ -f "$profile" ]]; then
50+
# Check if the PATH export already exists to avoid duplicates
51+
if ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' "$profile" 2>/dev/null; then
52+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$profile"
53+
echo "Added ~/.local/bin to PATH in $profile"
54+
fi
55+
fi
56+
done
57+
58+
# Also set PATH for current session
59+
export PATH="$HOME/.local/bin:$PATH"
60+
fi
61+
62+
# Download the release tarball and extract the binary
63+
echo "Downloading ToolHive CLI release $RELEASE_VERSION"
64+
curl -s -L "$RELEASE_TARBALL" -o /tmp/toolhive.tar.gz
65+
tar -xzf /tmp/toolhive.tar.gz -C /tmp thv
66+
chmod +x /tmp/thv
67+
cp /tmp/thv "$INSTALL_DIR/thv"
68+
rm -f /tmp/toolhive.tar.gz /tmp/thv
69+
70+
echo "ToolHive CLI (thv) installed successfully. Version: $RELEASE_VERSION"
71+
echo "The 'thv' command is now available in your PATH."

vercel.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://openapi.vercel.sh/vercel.json",
23
"redirects": [
34
{
45
"source": "/toolhive/quickstart",
@@ -10,5 +11,7 @@
1011
"destination": "/toolhive/tutorials/quickstart-k8s",
1112
"permanent": true
1213
}
13-
]
14+
],
15+
"installCommand": "dnf install -q -y jq && npm install",
16+
"buildCommand": "./scripts/install-thv.sh && npm run build"
1417
}

0 commit comments

Comments
 (0)