-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·196 lines (159 loc) · 5.13 KB
/
install.sh
File metadata and controls
executable file
·196 lines (159 loc) · 5.13 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
set -e
# Stardust installer script
# Usage: curl -sSL https://raw.githubusercontent.com/nexlabstudio/stardust/dev/install.sh | bash
REPO="nexlabstudio/stardust"
INSTALL_DIR="${STARDUST_INSTALL_DIR:-/usr/local/bin}"
BINARY_NAME="stardust"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() {
printf "${BLUE}==>${NC} %s\n" "$1"
}
success() {
printf "${GREEN}==>${NC} %s\n" "$1"
}
warn() {
printf "${YELLOW}Warning:${NC} %s\n" "$1"
}
error() {
printf "${RED}Error:${NC} %s\n" "$1" >&2
exit 1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Darwin*) echo "darwin" ;;
Linux*) echo "linux" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x64" ;;
arm64|aarch64) echo "arm64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
# Get latest release version from GitHub
get_latest_version() {
local latest_url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl &> /dev/null; then
curl -sSL "$latest_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
elif command -v wget &> /dev/null; then
wget -qO- "$latest_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Download file
download() {
local url="$1"
local output="$2"
if command -v curl &> /dev/null; then
curl -sSL "$url" -o "$output"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "$output"
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Verify checksum
verify_checksum() {
local file="$1"
local checksums_file="$2"
local expected_name="$3"
if command -v sha256sum &> /dev/null; then
local actual=$(sha256sum "$file" | awk '{print $1}')
local expected=$(grep "$expected_name" "$checksums_file" | awk '{print $1}')
if [ "$actual" != "$expected" ]; then
error "Checksum verification failed!\nExpected: $expected\nActual: $actual"
fi
elif command -v shasum &> /dev/null; then
local actual=$(shasum -a 256 "$file" | awk '{print $1}')
local expected=$(grep "$expected_name" "$checksums_file" | awk '{print $1}')
if [ "$actual" != "$expected" ]; then
error "Checksum verification failed!\nExpected: $expected\nActual: $actual"
fi
else
warn "sha256sum/shasum not found, skipping checksum verification"
return
fi
success "Checksum verified"
}
main() {
local version="${1:-}"
local os=$(detect_os)
local arch=$(detect_arch)
info "Detected OS: $os, Architecture: $arch"
# Get version
if [ -z "$version" ]; then
info "Fetching latest version..."
version=$(get_latest_version)
fi
if [ -z "$version" ]; then
error "Could not determine version to install"
fi
info "Installing Stardust $version"
# Determine archive name and extension
local archive_name="stardust-${os}-${arch}"
local extension="tar.gz"
if [ "$os" = "windows" ]; then
extension="zip"
fi
local download_url="https://github.com/${REPO}/releases/download/${version}/${archive_name}.${extension}"
local checksums_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
# Create temp directory
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
local archive_path="${tmp_dir}/${archive_name}.${extension}"
local checksums_path="${tmp_dir}/checksums.txt"
# Download archive and checksums
info "Downloading ${archive_name}.${extension}..."
download "$download_url" "$archive_path"
info "Downloading checksums..."
download "$checksums_url" "$checksums_path"
# Verify checksum
info "Verifying checksum..."
verify_checksum "$archive_path" "$checksums_path" "${archive_name}.${extension}"
# Extract
info "Extracting..."
cd "$tmp_dir"
if [ "$os" = "windows" ]; then
unzip -q "$archive_path"
else
tar -xzf "$archive_path"
fi
# Install
info "Installing to ${INSTALL_DIR}..."
if [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR" 2>/dev/null || sudo mkdir -p "$INSTALL_DIR"
fi
if [ -w "$INSTALL_DIR" ]; then
mv "${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
else
sudo mv "${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
fi
success "Stardust $version installed successfully!"
echo ""
# Verify installation
if command -v stardust &> /dev/null; then
info "Installed version:"
stardust --version
else
warn "stardust is not in your PATH"
echo "Add ${INSTALL_DIR} to your PATH:"
echo ""
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
echo ""
fi
}
main "$@"