-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
142 lines (119 loc) · 4.12 KB
/
Copy pathinstall.sh
File metadata and controls
142 lines (119 loc) · 4.12 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
#!/bin/bash
# Simple vvctl installer - downloads and installs the latest release or a specific version
# Usage: ./install.sh [version]
# Usage: ./install.sh --preview (installs latest prerelease)
# Example: ./install.sh v1.2.3
set -e
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
REPO="ververica/vvctl"
TEMP_DIR=$(mktemp -d)
VERSION_ARG="$1"
PREVIEW_MODE=false
# Parse arguments
if [ "$1" = "--preview" ]; then
PREVIEW_MODE=true
VERSION_ARG=""
fi
# Detect platform and return the target triple used in releases
detect_platform() {
local target
case "$(uname -s)" in
Linux*)
case "$(uname -m)" in
x86_64|amd64) target="x86_64-unknown-linux-gnu";;
*) echo "Error: Unsupported Linux architecture $(uname -m)" >&2; exit 1;;
esac
;;
Darwin*)
case "$(uname -m)" in
arm64|aarch64) target="aarch64-apple-darwin";;
x86_64|amd64) target="x86_64-apple-darwin";;
*) echo "Error: Unsupported macOS architecture $(uname -m)" >&2; exit 1;;
esac
;;
*) echo "Error: Unsupported OS $(uname -s)" >&2; exit 1;;
esac
echo "$target"
}
# Get latest version and download
echo "Installing vvctl..."
PLATFORM=$(detect_platform)
if [ -n "$VERSION_ARG" ]; then
VERSION="$VERSION_ARG"
echo "Using specified version: ${VERSION}"
elif [ "$PREVIEW_MODE" = true ]; then
# Get latest prerelease by fetching all releases and finding the most recent one
echo "Fetching latest prerelease..."
VERSION=$(curl -s "https://api.github.com/repos/${REPO}/releases" | \
grep -E '"tag_name"|"prerelease"' | \
paste - - | \
grep 'true' | \
head -1 | \
sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: Failed to get latest prerelease version" >&2
exit 1
fi
echo "Using latest prerelease version: ${VERSION}"
else
VERSION=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: Failed to get latest version" >&2
exit 1
fi
echo "Using latest version: ${VERSION}"
fi
echo "Downloading vvctl ${VERSION} for ${PLATFORM}..."
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/vvctl-${VERSION}-${PLATFORM}.tar.gz"
if ! curl -L -o "${TEMP_DIR}/vvctl.tar.gz" "$DOWNLOAD_URL"; then
echo "Error: Failed to download vvctl from $DOWNLOAD_URL" >&2
exit 1
fi
# Verify the download
if [ ! -f "${TEMP_DIR}/vvctl.tar.gz" ] || [ ! -s "${TEMP_DIR}/vvctl.tar.gz" ]; then
echo "Error: Downloaded file is missing or empty" >&2
exit 1
fi
# Extract the binary
echo "Extracting vvctl..."
if ! tar -xzf "${TEMP_DIR}/vvctl.tar.gz" -C "${TEMP_DIR}"; then
echo "Error: Failed to extract vvctl" >&2
exit 1
fi
# Find and move the binary (it's in a subdirectory)
EXTRACTED_DIR="${TEMP_DIR}/vvctl-${VERSION}-${PLATFORM}"
if [ -f "${EXTRACTED_DIR}/vvctl" ]; then
mv "${EXTRACTED_DIR}/vvctl" "${TEMP_DIR}/vvctl"
else
echo "Error: Could not find vvctl binary in extracted archive" >&2
echo "Contents of ${TEMP_DIR}:" >&2
ls -la "${TEMP_DIR}" >&2
exit 1
fi
# Verify extraction
if [ ! -f "${TEMP_DIR}/vvctl" ] || [ ! -s "${TEMP_DIR}/vvctl" ]; then
echo "Error: Extracted binary is missing or empty" >&2
exit 1
fi
# Install
chmod +x "${TEMP_DIR}/vvctl"
mkdir -p "$INSTALL_DIR"
echo "Installing to ${INSTALL_DIR}/vvctl..."
cp "${TEMP_DIR}/vvctl" "${INSTALL_DIR}/vvctl"
# Cleanup
rm -rf "$TEMP_DIR"
echo "vvctl installed successfully!"
# Check if INSTALL_DIR is in PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "WARNING: ${INSTALL_DIR} is not in your PATH."
echo "Add it by appending the following line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
echo "Then restart your shell or run: source ~/.bashrc (or ~/.zshrc)"
;;
esac
echo "Run 'vvctl --help' to get started"