install_without_dependencies.sh 6.8 KB

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