-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
237 lines (200 loc) · 6.09 KB
/
install.sh
File metadata and controls
237 lines (200 loc) · 6.09 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/sh
# TStack Kit Installer
# One-command install: curl -fsSL https://raw.githubusercontent.com/desingh-rajan/tstack-kit/main/install.sh | sh
#
# No git required - downloads tarball directly from GitHub releases
set -e
TSTACK_VERSION="1.6.4"
TSTACK_RELEASE_URL="https://github.com/desingh-rajan/tstack-kit/archive/refs/tags/v${TSTACK_VERSION}.tar.gz"
TSTACK_INSTALL_DIR="$HOME/.tstack"
# Colors (only if terminal supports it)
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
NC=''
fi
info() {
printf "${BLUE}[info]${NC} %s\n" "$1"
}
success() {
printf "${GREEN}[ok]${NC} %s\n" "$1"
}
warn() {
printf "${YELLOW}[warn]${NC} %s\n" "$1"
}
error() {
printf "${RED}[error]${NC} %s\n" "$1"
exit 1
}
# Check for required commands
check_command() {
command -v "$1" >/dev/null 2>&1
}
# Download file using curl or wget
download() {
local url="$1"
local output="$2"
if check_command curl; then
curl -fsSL "$url" -o "$output"
elif check_command wget; then
wget -q "$url" -O "$output"
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Detect shell config file
get_shell_config() {
case "$SHELL" in
*/zsh)
echo "$HOME/.zshrc"
;;
*/bash)
if [ -f "$HOME/.bashrc" ]; then
echo "$HOME/.bashrc"
else
echo "$HOME/.bash_profile"
fi
;;
*/fish)
echo "$HOME/.config/fish/config.fish"
;;
*)
echo "$HOME/.profile"
;;
esac
}
# Add to PATH
add_to_path() {
local path_entry="$1"
local shell_config
shell_config=$(get_shell_config)
# Check if already in PATH
case ":$PATH:" in
*":$path_entry:"*)
return 0
;;
esac
# Add to shell config
if [ -f "$shell_config" ]; then
if ! grep -q "$path_entry" "$shell_config" 2>/dev/null; then
echo "" >> "$shell_config"
echo "# TStack CLI" >> "$shell_config"
echo "export PATH=\"$path_entry:\$PATH\"" >> "$shell_config"
success "Added $path_entry to $shell_config"
fi
fi
}
main() {
echo ""
printf "${GREEN}TStack Kit Installer v${TSTACK_VERSION}${NC}\n"
echo "======================================="
echo ""
# Check for curl or wget
if ! check_command curl && ! check_command wget; then
error "This installer requires curl or wget. Please install one of them."
fi
# Check for unzip (required by Deno installer)
if ! check_command unzip; then
warn "unzip not found (required for Deno installation)"
info "Please install unzip: apt install unzip (Debian/Ubuntu) or yum install unzip (RHEL/CentOS)"
error "Cannot proceed without unzip"
fi
# Step 1: Check/Install Deno
info "Checking for Deno..."
if check_command deno; then
DENO_VERSION=$(deno --version | head -n 1 | cut -d ' ' -f 2)
success "Deno $DENO_VERSION found"
else
info "Deno not found. Installing Deno..."
if check_command curl; then
curl -fsSL https://deno.land/install.sh | sh
else
wget -qO- https://deno.land/install.sh | sh
fi
# Add Deno to PATH for this session
export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
if check_command deno; then
success "Deno installed successfully"
else
error "Failed to install Deno. Please install manually: https://deno.land"
fi
fi
# Step 2: Check Deno version (need 2.0+)
DENO_MAJOR=$(deno --version | head -n 1 | cut -d ' ' -f 2 | cut -d '.' -f 1)
if [ "$DENO_MAJOR" -lt 2 ]; then
warn "TStack requires Deno 2.6.4+. You have Deno $DENO_MAJOR.x"
info "Upgrading Deno..."
deno upgrade --version 2.6.4
success "Deno upgraded to 2.6.4"
fi
# Step 3: Download TStack Kit (no git required!)
info "Downloading TStack Kit v${TSTACK_VERSION}..."
# Clean previous installation
if [ -d "$TSTACK_INSTALL_DIR" ]; then
info "Removing previous installation..."
rm -rf "$TSTACK_INSTALL_DIR"
fi
# Create install directory
mkdir -p "$TSTACK_INSTALL_DIR"
# Download and extract tarball
TEMP_TAR=$(mktemp)
download "$TSTACK_RELEASE_URL" "$TEMP_TAR"
# Extract to install directory (strip the version prefix from paths)
tar -xzf "$TEMP_TAR" -C "$TSTACK_INSTALL_DIR" --strip-components=1
rm -f "$TEMP_TAR"
success "Downloaded TStack Kit"
# Step 4: Install CLI globally
info "Installing tstack command..."
cd "$TSTACK_INSTALL_DIR/packages/cli"
# Cache dependencies first
deno cache mod.ts
# Create a wrapper script that includes the config
DENO_BIN="$HOME/.deno/bin"
mkdir -p "$DENO_BIN"
cat > "$DENO_BIN/tstack" << 'WRAPPER'
#!/bin/sh
exec deno run \
--allow-read \
--allow-write \
--allow-env \
--allow-run \
--allow-net \
--unstable-kv \
--config "$HOME/.tstack/packages/cli/deno.json" \
"$HOME/.tstack/packages/cli/mod.ts" "$@"
WRAPPER
chmod +x "$DENO_BIN/tstack"
success "CLI installed"
# Step 5: Add to PATH
add_to_path "$HOME/.deno/bin"
# Step 6: Verify installation
export PATH="$HOME/.deno/bin:$PATH"
if check_command tstack; then
success "tstack command available"
else
warn "tstack installed but may not be in PATH yet"
fi
echo ""
echo "======================================="
printf "${GREEN}Installation complete!${NC}\n"
echo ""
echo "Verify installation:"
echo " tstack --version"
echo ""
echo "If command not found, restart your terminal or run:"
echo " source $(get_shell_config)"
echo ""
echo "Create your first project:"
echo " tstack create workspace my-app"
echo ""
}
main "$@"