Skip to content

Commit fe484e5

Browse files
committed
add gameap-files installator
1 parent 2079522 commit fe484e5

1 file changed

Lines changed: 200 additions & 0 deletions

File tree

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/bin/bash
2+
set -e
3+
4+
GAMEAP_FILES_VERSION="1.0.0"
5+
INSTALL_DIR="/usr/local/bin"
6+
CONFIG_DIR="/etc/gameap-files"
7+
USERS_DIR="${CONFIG_DIR}/users.d"
8+
9+
# Default values
10+
DATA_DIR=""
11+
FTP_LISTEN_ADDR=":21"
12+
FTP_PASSIVE_PORT_MIN="30000"
13+
FTP_PASSIVE_PORT_MAX="30100"
14+
FTP_PUBLIC_HOST=""
15+
FTP_TLS_ENABLED="false"
16+
FTP_TLS_IMPLICIT_PORT=":990"
17+
SFTP_LISTEN_ADDR=":2222"
18+
19+
show_help() {
20+
cat << EOF
21+
GameAP Files Server Installation Script
22+
23+
Usage: $0 [OPTIONS]
24+
25+
Required:
26+
--data-dir=DIR Data directory for game servers
27+
28+
Optional:
29+
--ftp-listen-address=ADDR FTP listen address (default: :21)
30+
--ftp-passive-port-min=N FTP passive port range start (default: 30000)
31+
--ftp-passive-port-max=N FTP passive port range end (default: 30100)
32+
--ftp-public-host=HOST FTP public host for passive mode
33+
--ftp-tls-enabled=BOOL Enable FTP TLS (default: false)
34+
--ftp-tls-implicit-port=N FTP implicit TLS port (default: :990)
35+
--sftp-listen-address=ADDR SFTP listen address (default: :2222)
36+
--version=VERSION GameAP Files version to install (default: 1.0.0)
37+
--help Show this help message
38+
39+
Examples:
40+
$0 --data-dir=/home/servers
41+
$0 --data-dir=/home/servers --ftp-listen-address=0.0.0.0:21 --sftp-listen-address=0.0.0.0:2222
42+
$0 --data-dir=/home/servers --ftp-tls-enabled=true --ftp-public-host=example.com
43+
EOF
44+
}
45+
46+
# Parse command line arguments
47+
while [ $# -gt 0 ]; do
48+
case "$1" in
49+
--data-dir=*)
50+
DATA_DIR="${1#*=}"
51+
;;
52+
--ftp-listen-address=*)
53+
FTP_LISTEN_ADDR="${1#*=}"
54+
;;
55+
--ftp-passive-port-min=*)
56+
FTP_PASSIVE_PORT_MIN="${1#*=}"
57+
;;
58+
--ftp-passive-port-max=*)
59+
FTP_PASSIVE_PORT_MAX="${1#*=}"
60+
;;
61+
--ftp-public-host=*)
62+
FTP_PUBLIC_HOST="${1#*=}"
63+
;;
64+
--ftp-tls-enabled=*)
65+
FTP_TLS_ENABLED="${1#*=}"
66+
;;
67+
--ftp-tls-implicit-port=*)
68+
FTP_TLS_IMPLICIT_PORT="${1#*=}"
69+
;;
70+
--sftp-listen-address=*)
71+
SFTP_LISTEN_ADDR="${1#*=}"
72+
;;
73+
--version=*)
74+
GAMEAP_FILES_VERSION="${1#*=}"
75+
;;
76+
--help|-h)
77+
show_help
78+
exit 0
79+
;;
80+
*)
81+
echo "Unknown option: $1"
82+
echo "Use --help for usage information"
83+
exit 1
84+
;;
85+
esac
86+
shift
87+
done
88+
89+
# Validate required parameters
90+
if [ -z "$DATA_DIR" ]; then
91+
echo "Error: --data-dir is required"
92+
echo "Use --help for usage information"
93+
exit 1
94+
fi
95+
96+
echo "Installing gameap-files v${GAMEAP_FILES_VERSION}..."
97+
98+
# Detect OS and architecture
99+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
100+
ARCH=$(uname -m)
101+
case $ARCH in
102+
x86_64) ARCH="amd64" ;;
103+
aarch64|arm64) ARCH="arm64" ;;
104+
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
105+
esac
106+
107+
# Download binary
108+
DOWNLOAD_URL="https://packages.gameap.com/gameap-files/${GAMEAP_FILES_VERSION}/gameap-files-${OS}-${ARCH}"
109+
echo "Downloading from ${DOWNLOAD_URL}..."
110+
curl -fsSL -o /tmp/gameap-files "$DOWNLOAD_URL"
111+
chmod +x /tmp/gameap-files
112+
mv /tmp/gameap-files "${INSTALL_DIR}/gameap-files"
113+
114+
# Create directories
115+
mkdir -p "$CONFIG_DIR" "$USERS_DIR"
116+
117+
# Generate SSH host key if not exists
118+
if [ ! -f "${CONFIG_DIR}/ssh_host_ed25519_key" ]; then
119+
echo "Generating SSH host key..."
120+
"${INSTALL_DIR}/gameap-files" genkey -t ed25519 -o "${CONFIG_DIR}/ssh_host_ed25519_key"
121+
fi
122+
123+
# Create default config if not exists
124+
if [ ! -f "${CONFIG_DIR}/config.yaml" ]; then
125+
echo "Creating configuration..."
126+
cat > "${CONFIG_DIR}/config.yaml" << EOF
127+
server:
128+
name: "GameAP Files Server"
129+
data_dir: "${DATA_DIR}"
130+
131+
ftp:
132+
enabled: true
133+
listen_addr: "${FTP_LISTEN_ADDR}"
134+
passive_port_min: ${FTP_PASSIVE_PORT_MIN}
135+
passive_port_max: ${FTP_PASSIVE_PORT_MAX}
136+
public_host: "${FTP_PUBLIC_HOST}"
137+
idle_timeout: 300
138+
tls:
139+
enabled: ${FTP_TLS_ENABLED}
140+
cert_file: "/etc/gameap-files/tls/server.crt"
141+
key_file: "/etc/gameap-files/tls/server.key"
142+
implicit_port: "${FTP_TLS_IMPLICIT_PORT}"
143+
required: false
144+
145+
sftp:
146+
enabled: true
147+
listen_addr: "${SFTP_LISTEN_ADDR}"
148+
host_key_file: "/etc/gameap-files/ssh/host_ed25519_key"
149+
idle_timeout: 300
150+
151+
security:
152+
argon2:
153+
memory: 65536
154+
iterations: 3
155+
parallelism: 4
156+
salt_length: 16
157+
key_length: 32
158+
rate_limit:
159+
max_failures: 5
160+
window_duration: 15m
161+
block_duration: 30m
162+
163+
logging:
164+
level: "info"
165+
format: "json"
166+
output: "stdout"
167+
audit_log: ""
168+
169+
users:
170+
directory: "/etc/gameap-files/users.d"
171+
hot_reload: true
172+
EOF
173+
fi
174+
175+
# Install systemd service
176+
echo "Installing systemd service..."
177+
cat > /etc/systemd/system/gameap-files.service << 'EOF'
178+
[Unit]
179+
Description=GameAP Files Server
180+
After=network.target
181+
182+
[Service]
183+
Type=simple
184+
ExecStart=/usr/local/bin/gameap-files serve -c /etc/gameap-files/config.yaml
185+
Restart=always
186+
RestartSec=5
187+
StandardOutput=journal
188+
StandardError=journal
189+
190+
[Install]
191+
WantedBy=multi-user.target
192+
EOF
193+
194+
# Enable and start service
195+
systemctl daemon-reload
196+
systemctl enable gameap-files
197+
systemctl start gameap-files
198+
199+
echo "gameap-files installed successfully!"
200+
"${INSTALL_DIR}/gameap-files" --version

0 commit comments

Comments
 (0)