Skip to content

Commit 86bc703

Browse files
committed
chore: add install script
1 parent 4f81e7d commit 86bc703

File tree

2 files changed

+99
-6
lines changed

2 files changed

+99
-6
lines changed

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ Sample configuration for different services:
7575
```
7676

7777
### Install instructions
78-
Grab or build the binary from the releases and move it to and executable location in your $PATH.
79-
8078
```bash
81-
git clone
82-
cargo build --release
83-
```
79+
curl -sSL https://raw.githubusercontent.com/kainlite/kube-forward/master/scripts/install.sh | sh
80+
81+
#### Manual Installation
82+
You can also download the binary directly from the releases page.
8483

85-
### Run
84+
### Usage
8685
To run it and be able to use your port-forwards, run:
8786
```bash
8887
❯ RUST_LOG=info kube-forward -c config.yaml

scripts/install.sh

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Define variables
5+
GITHUB_REPO="kainlite/kube-forward"
6+
BINARY_NAME="kube-forward"
7+
INSTALL_DIR="/usr/local/bin"
8+
9+
# Function to detect OS and architecture
10+
detect_platform() {
11+
local ARCH=$(uname -m)
12+
case $ARCH in
13+
x86_64)
14+
ARCH="amd64"
15+
;;
16+
aarch64)
17+
ARCH="arm64"
18+
;;
19+
*)
20+
echo "Unsupported architecture: $ARCH"
21+
exit 1
22+
;;
23+
esac
24+
25+
local OS=$(uname -s | tr '[:upper:]' '[:lower:]')
26+
case $OS in
27+
linux)
28+
;;
29+
darwin)
30+
;;
31+
*)
32+
echo "Unsupported operating system: $OS"
33+
exit 1
34+
;;
35+
esac
36+
37+
echo "${OS}_${ARCH}"
38+
}
39+
40+
# Function to get the latest release version
41+
get_latest_release() {
42+
curl --silent "https://api.github.com/repos/$GITHUB_REPO/releases/latest" |
43+
grep '"tag_name":' |
44+
sed -E 's/.*"([^"]+)".*/\1/'
45+
}
46+
47+
# Install the binary
48+
install_binary() {
49+
local PLATFORM=$1
50+
local VERSION=$2
51+
local TEMP_DIR=$(mktemp -d)
52+
local BINARY_URL="https://github.com/$GITHUB_REPO/releases/download/$VERSION/$BINARY_NAME-$PLATFORM"
53+
54+
echo "⬇️ Downloading $BINARY_NAME $VERSION for $PLATFORM..."
55+
curl -sL "$BINARY_URL" -o "$TEMP_DIR/$BINARY_NAME"
56+
chmod +x "$TEMP_DIR/$BINARY_NAME"
57+
58+
echo "📦 Installing to $INSTALL_DIR..."
59+
if [ -w "$INSTALL_DIR" ]; then
60+
mv "$TEMP_DIR/$BINARY_NAME" "$INSTALL_DIR/"
61+
else
62+
sudo mv "$TEMP_DIR/$BINARY_NAME" "$INSTALL_DIR/"
63+
fi
64+
65+
rm -rf "$TEMP_DIR"
66+
}
67+
68+
# Main installation process
69+
main() {
70+
if ! command -v curl >/dev/null; then
71+
echo "Error: curl is required for installation"
72+
exit 1
73+
}
74+
75+
local PLATFORM=$(detect_platform)
76+
local VERSION=$(get_latest_release)
77+
78+
if [ -z "$VERSION" ]; then
79+
echo "Error: Unable to determine latest version"
80+
exit 1
81+
}
82+
83+
install_binary "$PLATFORM" "$VERSION"
84+
85+
if command -v $BINARY_NAME >/dev/null; then
86+
echo "✅ Installation successful!"
87+
echo "🚀 Run '$BINARY_NAME --help' to get started"
88+
else
89+
echo "❌ Installation failed"
90+
exit 1
91+
fi
92+
}
93+
94+
main

0 commit comments

Comments
 (0)