Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
grasscutters
GitHub Repository: grasscutters/grasscutter
Path: blob/development/scripts/install/install_without_dependencies.sh
3156 views
1
#!/usr/bin/env bash
2
3
# Grasscutter install script for GNU/Linux - Simpler version
4
# This installer doesn't ask you to install dependencies, you have to install them manually
5
# Made by TurtleIdiot and modified by syktyvkar (and then again modified by Blue)
6
7
# Stops the installer if any command has a non-zero exit status
8
set -e
9
10
# Checks for root
11
if [ $EUID != 0 ]; then
12
echo "Please run the installer as root (sudo)!"
13
exit
14
fi
15
16
is_command() {
17
# Checks if given command is available
18
local check_command="$1"
19
command -v "${check_command}" > /dev/null 2>&1
20
}
21
22
# IP validation
23
valid_ip() {
24
local ip=$1
25
local stat=1
26
27
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
28
OIFS=$IFS
29
IFS="."
30
ip=($ip)
31
IFS=$OIFS
32
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
33
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
34
stat=$?
35
fi
36
return $stat
37
}
38
echo "#################################"
39
echo ""
40
echo "This script will take for granted that you have all dependencies installed (mongodb, openjdk-17-jre/jre17-openjdk, wget, openssl, unzip, git, curl, base-devel), in fact, this script is recommended to update your current server installation, and it should run from the same folder as grasscutter.jar"
41
echo "#################################"
42
echo ""
43
echo "If you are using version > 2.8 of the client, make sure to use the patched metadata if you don't use Cultivation."
44
echo "Search for METADATA here: https://discord.gg/grasscutter."
45
echo ""
46
echo "#################################"
47
echo "You can find plugins here: https://discord.com/channels/965284035985305680/970830969919664218"
48
echo ""
49
echo "Grasscutter will be installed to script's running directory"
50
echo "Do you wish to proceed and install Grasscutter?"
51
select yn in "Yes" "No" ; do
52
case $yn in
53
Yes ) break;;
54
No )
55
echo "Aborting..."
56
exit;;
57
esac
58
done
59
60
if [ -d "./resources" ]
61
then
62
echo "It's recommended to remove resources folder"
63
echo "Remove resources folder?"
64
select yn in "Yes" "No" ; do
65
case $yn in
66
Yes )
67
rm -rf resources
68
break;;
69
No )
70
echo "Aborting..."
71
exit;;
72
esac
73
done
74
echo "You may need to remove data folder and config.json to apply some updates"
75
echo "#################################"
76
fi
77
78
79
80
# Allows choice between stable and dev branch
81
echo "Please select the branch you wish to install"
82
echo -e "!!NOTE!!: stable is the recommended branch.\nDo *NOT* use development unless you have a reason to and know what you're doing"
83
select branch in "stable" "development" ; do
84
case $branch in
85
stable )
86
break;;
87
development )
88
break;;
89
esac
90
done
91
92
echo -e "Using $branch branch for installing server \n"
93
94
# Prompt IP address for config.json and for generating new keystore.p12 file
95
echo "Please enter the IP address that will be used to connect to the server"
96
echo "This can be a local or a public IP address"
97
echo "This IP address will be used to generate SSL certificates, so it is important it is correct!"
98
99
while : ; do
100
read -p "Enter server IP: " SERVER_IP
101
if valid_ip $SERVER_IP; then
102
break;
103
else
104
echo "Invalid IP address. Try again."
105
fi
106
done
107
108
echo "Beginning Grasscutter installation..."
109
110
111
# Download resources
112
echo "Downloading Grasscutter BinOutputs..."
113
git clone --single-branch https://github.com/Koko-boya/Grasscutter_Resources.git Grasscutter-bins
114
mv ./Grasscutter-bins/Resources ./resources
115
rm -rf Grasscutter-bins # takes ~350M of drive space after moving BinOutputs... :sob:
116
117
# Download and build jar
118
echo "Downloading Grasscutter source code..."
119
git clone --single-branch -b $branch https://github.com/Grasscutters/Grasscutter.git Grasscutter-src #change this to download a fork
120
121
echo "Building grasscutter.jar..."
122
cd Grasscutter-src
123
chmod +x ./gradlew #just in case
124
./gradlew --no-daemon jar
125
mv $(find -name "grasscutter*.jar" -type f) ../grasscutter.jar
126
echo "Building grasscutter.jar done!"
127
cd ..
128
129
# Generate handbook/config
130
echo "Grasscutter will be started to generate data files"
131
java -jar grasscutter.jar -version
132
133
# Replaces "127.0.0.1" with given IP
134
echo "Replacing IP address in server config..."
135
sed -i "s/127.0.0.1/$SERVER_IP/g" config.json
136
# Generates new keystore.p12 with the server's IP address
137
# This is done to prevent a "Connection Timed Out" error from appearing
138
# after clicking to enter the door in the main menu/title screen
139
# This issue only exists when connecting to a server *other* than localhost
140
# since the default keystore.p12 has only been made for localhost
141
142
mkdir certs
143
cd certs
144
echo "Generating CA key and certificate pair..."
145
openssl req -x509 -nodes -days 25202 -newkey rsa:2048 -subj "/C=GB/ST=Essex/L=London/O=Grasscutters/OU=Grasscutters/CN=$SERVER_IP" -keyout CAkey.key -out CAcert.crt
146
147
echo "Generating SSL key and certificate pair..."
148
openssl genpkey -out ssl.key -algorithm rsa
149
150
# Creates a conf file in order to generate a csr
151
cat > csr.conf <<EOF
152
[ req ]
153
default_bits = 2048
154
prompt = no
155
default_md = sha256
156
req_extensions = req_ext
157
distinguished_name = dn
158
159
[ dn ]
160
C = GB
161
ST = Essex
162
L = London
163
O = Grasscutters
164
OU = Grasscutters
165
CN = $SERVER_IP
166
167
[ req_ext ]
168
subjectAltName = @alt_names
169
170
[ alt_names ]
171
IP.1 = $SERVER_IP
172
EOF
173
174
# Creates csr using key and conf
175
openssl req -new -key ssl.key -out ssl.csr -config csr.conf
176
177
# Creates conf to finalise creation of certificate
178
cat > cert.conf <<EOF
179
180
authorityKeyIdentifier=keyid,issuer
181
basicConstraints=CA:FALSE
182
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, keyAgreement, dataEncipherment
183
subjectAltName = @alt_names
184
185
[alt_names]
186
IP.1 = $SERVER_IP
187
188
EOF
189
190
# Creates SSL cert
191
openssl x509 -req -in ssl.csr -CA CAcert.crt -CAkey CAkey.key -CAcreateserial -out ssl.crt -days 25202 -sha256 -extfile cert.conf
192
193
echo "Generating keystore.p12 from key and certificate..."
194
openssl pkcs12 -export -out keystore.p12 -inkey ssl.key -in ssl.crt -certfile CAcert.crt -passout pass:123456
195
196
cd ../
197
mv ./certs/keystore.p12 ./keystore.p12
198
echo "Done!"
199
200
# Running scripts as sudo makes all Grasscutter files to be owned by root
201
# which may cause problems editing .jsons...
202
if [ $SUDO_USER ]; then
203
echo "Changing Grasscutter files owner to current user..."
204
chown -R $SUDO_USER:$SUDO_USER ./*
205
fi
206
207
echo "Removing unnecessary files..."
208
rm -rf ./certs ./Grasscutter-src
209
210
echo "All done!"
211
echo "-=-=-=-=-=--- !! IMPORTANT !! ---=-=-=-=-=-"
212
echo "Please make sure that ports 80, 443, 8888 and 22102 are OPEN (both tcp and udp)"
213
echo "In order to run the server, run the following command:"
214
echo " sudo java -jar grasscutter.jar"
215
echo "The GM Handbook of all supported languages will be generated automatically when you start the server for the first time."
216
echo "You must run it using sudo as port 443 is a privileged port"
217
echo "To play, use the IP you provided earlier ($SERVER_IP) via GrassClipper or Fiddler"
218
echo ""
219
220
exit
221
222