-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·193 lines (163 loc) Β· 5.74 KB
/
install.sh
File metadata and controls
executable file
Β·193 lines (163 loc) Β· 5.74 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
#!/bin/bash
# WebShell Install Script
# Automatically downloads and installs the appropriate WebShell binary for your platform
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
REPO="adaptive-scale/webshell"
VERSION=${1:-"latest"}
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="webshell"
echo -e "${BLUE}π WebShell Install Script${NC}"
echo -e "${BLUE}Repository: ${REPO}${NC}"
echo -e "${BLUE}Version: ${VERSION}${NC}"
echo ""
# Detect platform and architecture
detect_platform() {
local OS=""
local ARCH=""
case "$(uname -s)" in
Linux*) OS="linux";;
Darwin*) OS="darwin";;
CYGWIN*) OS="windows";;
MINGW*) OS="windows";;
MSYS*) OS="windows";;
*) echo -e "${RED}β Unsupported operating system${NC}" >&2; exit 1;;
esac
case "$(uname -m)" in
x86_64) ARCH="amd64";;
amd64) ARCH="amd64";;
arm64) ARCH="arm64";;
aarch64) ARCH="arm64";;
*) echo -e "${RED}β Unsupported architecture: $(uname -m)${NC}" >&2; exit 1;;
esac
echo -e "${GREEN}β
Detected: ${OS} ${ARCH}${NC}" >&2
echo "${OS}_${ARCH}"
}
# Download binary
download_binary() {
local platform=$1
local download_url=""
if [ "$VERSION" = "latest" ]; then
# Get latest release
local latest_tag=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
VERSION=$latest_tag
fi
# Remove 'v' prefix if present
VERSION=${VERSION#v}
local filename="webshell_${platform}"
if [ "$platform" = "windows_amd64" ]; then
filename="webshell.exe"
fi
download_url="https://github.com/${REPO}/releases/download/v${VERSION}/${filename}"
echo -e "${YELLOW}π₯ Downloading WebShell v${VERSION} for ${platform}...${NC}"
echo -e "${YELLOW}URL: ${download_url}${NC}"
# Download the binary
if curl -L -o "${filename}" "${download_url}"; then
echo -e "${GREEN}β
Download successful${NC}"
else
echo -e "${RED}β Download failed${NC}"
echo -e "${YELLOW}π‘ Make sure the release exists at: https://github.com/${REPO}/releases/tag/v${VERSION}${NC}"
exit 1
fi
echo "${filename}"
}
# Install binary
install_binary() {
local binary_file=$1
echo -e "${YELLOW}π§ Installing WebShell...${NC}"
# Make binary executable
chmod +x "${binary_file}"
# Check if we can write to /usr/local/bin
if [ -w "$INSTALL_DIR" ] || sudo -n true 2>/dev/null; then
# Install to system directory
if sudo mv "${binary_file}" "${INSTALL_DIR}/${BINARY_NAME}"; then
echo -e "${GREEN}β
Installed to ${INSTALL_DIR}/${BINARY_NAME}${NC}"
else
echo -e "${RED}β Failed to install to system directory${NC}"
exit 1
fi
else
# Install to user directory
local user_bin="$HOME/.local/bin"
mkdir -p "$user_bin"
mv "${binary_file}" "$user_bin/${BINARY_NAME}"
echo -e "${GREEN}β
Installed to ${user_bin}/${BINARY_NAME}${NC}"
echo -e "${YELLOW}π‘ Add ${user_bin} to your PATH if not already added${NC}"
echo -e "${YELLOW} Add this line to your shell profile (.bashrc, .zshrc, etc.):${NC}"
echo -e "${BLUE} export PATH=\"\$HOME/.local/bin:\$PATH\"${NC}"
fi
}
# Verify installation
verify_installation() {
echo -e "${YELLOW}π Verifying installation...${NC}"
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
local version=$("$BINARY_NAME" --version 2>/dev/null || echo "unknown version")
echo -e "${GREEN}β
WebShell installed successfully!${NC}"
echo -e "${GREEN} Version: ${version}${NC}"
echo -e "${GREEN} Location: $(which $BINARY_NAME)${NC}"
else
echo -e "${RED}β Installation verification failed${NC}"
echo -e "${YELLOW}π‘ Try adding the installation directory to your PATH${NC}"
exit 1
fi
}
# Show usage information
show_usage() {
echo -e "${BLUE}π Usage Information${NC}"
echo ""
echo -e "${GREEN}π Start WebShell:${NC}"
echo " $BINARY_NAME"
echo ""
echo -e "${GREEN}π Access Web Interface:${NC}"
echo " http://localhost:8080"
echo ""
echo -e "${GREEN}π₯οΈ Access Web Terminal:${NC}"
echo " http://localhost:8080/terminal"
echo ""
echo -e "${GREEN}π Documentation:${NC}"
echo " https://github.com/${REPO}"
echo ""
echo -e "${GREEN}π§ Custom Port:${NC}"
echo " PORT=3000 $BINARY_NAME"
}
# Main installation process
main() {
echo -e "${BLUE}π Detecting your platform...${NC}"
local platform=$(detect_platform)
echo -e "${BLUE}π¦ Downloading WebShell...${NC}"
local binary_file=$(download_binary "$platform")
echo -e "${BLUE}π§ Installing WebShell...${NC}"
install_binary "$binary_file"
echo -e "${BLUE}β
Verifying installation...${NC}"
verify_installation
echo ""
echo -e "${GREEN}π WebShell installation completed successfully!${NC}"
echo ""
show_usage
}
# Handle command line arguments
case "${1:-}" in
-h|--help)
echo "WebShell Install Script"
echo ""
echo "Usage: $0 [version]"
echo ""
echo "Arguments:"
echo " version Specific version to install (default: latest)"
echo ""
echo "Examples:"
echo " $0 # Install latest version"
echo " $0 v0.1.6 # Install specific version"
echo " $0 0.1.6 # Install specific version (without v prefix)"
exit 0
;;
*)
main
;;
esac