forked from Gml-Launcher/Gml.Backend.Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgml-installer-en.sh
188 lines (163 loc) · 4.78 KB
/
gml-installer-en.sh
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
#!/bin/sh
if [ "$(id -u)" -ne 0 ]
then
echo "The script needs to be run as root"
exit 1
fi
#!/bin/bash
set -eo pipefail
## Helper functions
# Check if required command is available
command_exists() {
command -v "$@" > /dev/null 2>&1
}
##
# A wrapper to protect from executing an incomplete script
main() {
# Check for git installation
if ! command_exists git
then
set +e
echo "[Git] Git not found. Attempting to install..."
apt-get install -y git
if [ $? -eq 0 ]
then
echo "[Git] Installation successful"
else
echo "[Git] Failed to install Git. Please install it manually."
exit 1
fi
else
echo "[Git] Installed"
fi
# Check for jq installation
if ! command_exists jq
then
set +e
echo "[jq] jq not found. Attempting to install..."
apt-get install -y jq
if [ $? -eq 0 ]
then
echo "[jq] Installation successful"
else
echo "[jq] Failed to install jq. Please install it manually."
exit 1
fi
else
echo "[jq] Installed"
fi
# Check for curl installation
if ! command_exists curl
then
set +e
echo "[Curl] Curl not found. Attempting to install..."
apt-get install -y curl
if [ $? -eq 0 ]
then
echo "[Curl] Installation successful"
else
echo "[Curl] Failed to install Curl. Please install it manually."
exit 1
fi
else
echo "[Curl] Installed"
fi
# Check for docker.io installation
if ! command_exists docker
then
set +e
echo "[Docker] Docker not found. Attempting to install..."
apt-get install -y docker.io
if [ $? -eq 0 ]
then
echo "[Docker] Installation successful"
else
echo "[Docker] Failed to install Docker. Please install it manually."
exit 1
fi
else
echo "[Docker] Installed"
fi
# Check for Docker Compose installation
if ! command_exists docker-compose
then
set +e
echo "[Docker-Compose] Docker Compose not found. Attempting to install..."
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.24.7/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
if [ $? -eq 0 ]
then
echo "[Docker-Compose] Installation successful"
else
echo "[Docker-Compose] Failed to install Docker Compose. Please install it manually."
exit 1
fi
else
echo "[Docker-Compose] Installed"
fi
# Ask user for ProjectName
while :
do
printf "Project name: "
read ProjectName
if [ -z "$ProjectName" ]
then
echo "[Error] Value cannot be empty. Please try again."
else
break
fi
done
# Ask user for ProjectDescription
echo "Project description: (press Enter to use Game project $ProjectName):"
read ProjectDescription
# Generate SecretKey
SecretKey=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')
# Ask user for ProjectVersion
echo "Enter ProjectVersion (press Enter to use 1.1.0):"
read ProjectVersion
ProjectVersion="${ProjectVersion:-1.1.0}"
# Clone repository
echo "Cloning repository..."
git clone --recursive https://github.com/GamerVII-NET/Gml.Backend.git "$ProjectName"
if [ $? -eq 0 ]
then
echo "Repository cloned successfully"
else
echo "[Error] Failed to clone repository. Please check your internet connection and repository availability. Also, make sure there's no $ProjectName folder in current directory"
exit 1
fi
# Get external IP address
EXTERNAL_IP=$(curl -s ifconfig.me)
# Change to project directory and create .env file
cd "$ProjectName"/src/Gml.Web.Client
# Create .env file
if [ ! -f .env ]; then
echo "NEXT_PUBLIC_BASE_URL=http://$EXTERNAL_IP:5000" > .env
echo "NEXT_PUBLIC_PREFIX_API=api" >> .env
echo "NEXT_PUBLIC_VERSION_API=v1" >> .env
fi
# Change to $ProjectName/src/Gml.Web.Api/src/Gml.Web.Api folder
cd "../../src/Gml.Web.Api/src/Gml.Web.Api/"
# Delete appsettings.Development.json
rm -f appsettings.Development.json
# Edit appsettings.json
if [ -f appsettings.json ]; then
jq ".ServerSettings.ProjectName = \"$ProjectName\" |
.ServerSettings.ProjectDescription = \"$ProjectDescription\" |
.ServerSettings.SecretKey = \"$SecretKey\" |
.ServerSettings.PolicyName = \"${ProjectName}Policy\" |
.ConnectionStrings.SQLite = \"Data Source=data.db\"" appsettings.json > temp.json && mv temp.json appsettings.json
fi
docker compose up -d
echo ==================================================
echo "\e[32mProject successfully installed:\e[0m"
echo "Admin panel: http://$EXTERNAL_IP:5003/"
echo " *Registration required"
echo "File management: http://$EXTERNAL_IP:5005/"
echo " Login: admin"
echo " Password: admin"
echo ==================================================
}
main