-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
165 lines (140 loc) · 4.14 KB
/
install.sh
File metadata and controls
165 lines (140 loc) · 4.14 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
#!/usr/bin/env bash
# Cross-platform install script for marchat
# Supports Linux, macOS, Windows (via Git Bash/WSL), and Android (Termux)
set -e # Exit on any error
VERSION="v1.0.0"
# Detect OS and architecture
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
# Map uname output to Go arch naming
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
armv7l) ARCH="arm" ;;
i386|i686) ARCH="386" ;;
esac
# Handle Windows detection
if [[ "$OS" == *"msys"* ]] || [[ "$OS" == *"mingw"* ]] || [[ "$OS" == *"cygwin"* ]]; then
OS="windows"
fi
# Termux often reports kernel "Linux" (already correct). Some environments report "Android";
# release zips are named linux-$ARCH (static GOOS=linux), not android-$ARCH.
if [[ "$OS" == "android" && "$ARCH" == "arm64" ]]; then
OS="linux"
fi
# Construct GitHub release URL
URL="https://github.com/Cod-e-Codes/marchat/releases/download/$VERSION/marchat-$VERSION-$OS-$ARCH.zip"
# Create temporary directories
TEMP_DIR=$(mktemp -d)
ZIP_FILE="$TEMP_DIR/marchat.zip"
EXTRACT_DIR="$TEMP_DIR/extracted"
echo "[INFO] Detected OS: $OS"
echo "[INFO] Detected ARCH: $ARCH"
echo "[INFO] Download URL: $URL"
echo "[INFO] Temp directory: $TEMP_DIR"
# Check if curl is available
if ! command -v curl &> /dev/null; then
echo "[ERROR] Error: curl is required but not installed"
exit 1
fi
# Check if unzip is available
if ! command -v unzip &> /dev/null; then
echo "[ERROR] Error: unzip is required but not installed"
exit 1
fi
# Download the zip
echo "[INFO] Downloading marchat $VERSION..."
curl -L -o "$ZIP_FILE" "$URL"
if [ $? -ne 0 ]; then
echo "[ERROR] Download failed!"
exit 1
fi
# Extract zip
mkdir -p "$EXTRACT_DIR"
echo "[INFO] Extracting..."
unzip -q "$ZIP_FILE" -d "$EXTRACT_DIR"
# Determine install directory based on OS
INSTALL_DIR=""
CONFIG_DIR=""
USE_SUDO=""
case "$OS" in
linux|android)
# Check if we're in Termux (Android)
if [[ -n "$PREFIX" && "$PREFIX" == *"com.termux"* ]]; then
INSTALL_DIR="$PREFIX/bin"
CONFIG_DIR="$HOME/.config/marchat"
USE_SUDO=""
else
# Regular Linux
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="$HOME/.config/marchat"
USE_SUDO="sudo"
fi
;;
darwin)
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="$HOME/Library/Application Support/marchat"
USE_SUDO="sudo"
;;
windows)
# For Windows, install to user's local bin directory
INSTALL_DIR="$HOME/.local/bin"
CONFIG_DIR="$APPDATA/marchat"
USE_SUDO=""
;;
*)
echo "[ERROR] Unsupported OS: $OS"
exit 1
;;
esac
echo "[INFO] Installing to: $INSTALL_DIR"
echo "[INFO] Config directory: $CONFIG_DIR"
# Create install directory
if [[ -n "$USE_SUDO" ]]; then
$USE_SUDO mkdir -p "$INSTALL_DIR"
else
mkdir -p "$INSTALL_DIR"
fi
# Find the correct binary files
SERVER_BINARY=""
CLIENT_BINARY=""
for file in "$EXTRACT_DIR"/*; do
if [[ "$file" == *"marchat-server"* ]]; then
SERVER_BINARY="$file"
elif [[ "$file" == *"marchat-client"* ]]; then
CLIENT_BINARY="$file"
fi
done
if [[ -z "$SERVER_BINARY" ]] || [[ -z "$CLIENT_BINARY" ]]; then
echo "[ERROR] Error: Could not find marchat binaries in the downloaded archive"
echo "[INFO] Contents of extract directory:"
ls -la "$EXTRACT_DIR"
exit 1
fi
# Copy binaries
echo "[INFO] Copying binaries..."
if [[ -n "$USE_SUDO" ]]; then
$USE_SUDO cp "$SERVER_BINARY" "$INSTALL_DIR/marchat-server"
$USE_SUDO cp "$CLIENT_BINARY" "$INSTALL_DIR/marchat-client"
$USE_SUDO chmod +x "$INSTALL_DIR/marchat-server" "$INSTALL_DIR/marchat-client"
else
cp "$SERVER_BINARY" "$INSTALL_DIR/marchat-server"
cp "$CLIENT_BINARY" "$INSTALL_DIR/marchat-client"
chmod +x "$INSTALL_DIR/marchat-server" "$INSTALL_DIR/marchat-client"
fi
# Create config directory
mkdir -p "$CONFIG_DIR"
# Clean up temp directory
echo "[INFO] Cleaning up..."
rm -rf "$TEMP_DIR"
echo ""
echo "[OK] Installation complete!"
echo ""
echo "[INFO] Binaries installed to: $INSTALL_DIR"
echo "[INFO] Config directory: $CONFIG_DIR"
echo ""
echo "Quick start:"
echo " 1. Start server: marchat-server"
echo " 2. Connect client: marchat-client --username yourname"
echo ""
echo "For more information, visit: https://github.com/Cod-e-Codes/marchat"