-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
104 lines (86 loc) · 2.32 KB
/
install.sh
File metadata and controls
104 lines (86 loc) · 2.32 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
#!/bin/bash
# Define paths
SERVER_BINARY="ASOServer"
SYSTEM_BINARY_DIR="/usr/local/sbin/"
SYSTEM_ETC_DIR="/etc/aso"
SYSTEM_LOG_DIR="/var/log/aso"
SYSTEMD_UNIT_FILE="/etc/systemd/system/aso-server.service"
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--go)
GO_PATH="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Use custom Go path if provided
if [[ -n "$GO_PATH" ]]; then
GO_COMMAND="$GO_PATH"
else
GO_COMMAND="go"
fi
# Check if Go is installed
if [[ -z $(command -v $GO_COMMAND) ]]; then
echo "Error: Go is not installed."
exit 1
fi
filePath="./$SERVER_BINARY"
# Check if the file exists and remove it if it does
[ -f "$filePath" ] && rm "$filePath"
# Build server binary
echo "Building server binary..."
$GO_COMMAND build -o $SERVER_BINARY
# Check if server binary exists in the current directory
if [ ! -f "$SERVER_BINARY" ]; then
echo "Error: Server binary '$SERVER_BINARY' not found in the current directory"
exit 1
fi
if systemctl is-active --quiet aso-server; then
echo -n "The ASO Server service is currently running. Do you want to stop it to update? (y/n): "
read -r choice
case "$choice" in
y|Y )
systemctl stop aso-server
;;
n|N )
echo "Skipping service stop. The service will not be updated."
exit 1
;;
* )
echo "Invalid choice. The service will not be updated."
exit 1
;;
esac
fi
# Create System directory's if it doesn't exist
mkdir -p "$SYSTEM_ETC_DIR"
mkdir -p "$SYSTEM_LOG_DIR"
# Copy the server binary to the system binary directory
cp -f "$SERVER_BINARY" "$SYSTEM_BINARY_DIR"
# Create a systemd unit file for the server service
cat <<EOF > "$SYSTEMD_UNIT_FILE"
[Unit]
Description=ASO Server
After=network.target
[Service]
Type=simple
ExecStart=$SYSTEM_BINARY_DIR$SERVER_BINARY --unix
WorkingDirectory=$SYSTEM_BINARY_DIR
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd to apply the changes
systemctl daemon-reload
# Start and enable the server service
systemctl start aso-server
systemctl enable aso-server
echo "ASO Server has been installed and configured as a service."