Path: blob/development/scripts/install/install_without_dependencies.sh
3156 views
#!/usr/bin/env bash12# Grasscutter install script for GNU/Linux - Simpler version3# This installer doesn't ask you to install dependencies, you have to install them manually4# Made by TurtleIdiot and modified by syktyvkar (and then again modified by Blue)56# Stops the installer if any command has a non-zero exit status7set -e89# Checks for root10if [ $EUID != 0 ]; then11echo "Please run the installer as root (sudo)!"12exit13fi1415is_command() {16# Checks if given command is available17local check_command="$1"18command -v "${check_command}" > /dev/null 2>&119}2021# IP validation22valid_ip() {23local ip=$124local stat=12526if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then27OIFS=$IFS28IFS="."29ip=($ip)30IFS=$OIFS31[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \32&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]33stat=$?34fi35return $stat36}37echo "#################################"38echo ""39echo "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"40echo "#################################"41echo ""42echo "If you are using version > 2.8 of the client, make sure to use the patched metadata if you don't use Cultivation."43echo "Search for METADATA here: https://discord.gg/grasscutter."44echo ""45echo "#################################"46echo "You can find plugins here: https://discord.com/channels/965284035985305680/970830969919664218"47echo ""48echo "Grasscutter will be installed to script's running directory"49echo "Do you wish to proceed and install Grasscutter?"50select yn in "Yes" "No" ; do51case $yn in52Yes ) break;;53No )54echo "Aborting..."55exit;;56esac57done5859if [ -d "./resources" ]60then61echo "It's recommended to remove resources folder"62echo "Remove resources folder?"63select yn in "Yes" "No" ; do64case $yn in65Yes )66rm -rf resources67break;;68No )69echo "Aborting..."70exit;;71esac72done73echo "You may need to remove data folder and config.json to apply some updates"74echo "#################################"75fi76777879# Allows choice between stable and dev branch80echo "Please select the branch you wish to install"81echo -e "!!NOTE!!: stable is the recommended branch.\nDo *NOT* use development unless you have a reason to and know what you're doing"82select branch in "stable" "development" ; do83case $branch in84stable )85break;;86development )87break;;88esac89done9091echo -e "Using $branch branch for installing server \n"9293# Prompt IP address for config.json and for generating new keystore.p12 file94echo "Please enter the IP address that will be used to connect to the server"95echo "This can be a local or a public IP address"96echo "This IP address will be used to generate SSL certificates, so it is important it is correct!"9798while : ; do99read -p "Enter server IP: " SERVER_IP100if valid_ip $SERVER_IP; then101break;102else103echo "Invalid IP address. Try again."104fi105done106107echo "Beginning Grasscutter installation..."108109110# Download resources111echo "Downloading Grasscutter BinOutputs..."112git clone --single-branch https://github.com/Koko-boya/Grasscutter_Resources.git Grasscutter-bins113mv ./Grasscutter-bins/Resources ./resources114rm -rf Grasscutter-bins # takes ~350M of drive space after moving BinOutputs... :sob:115116# Download and build jar117echo "Downloading Grasscutter source code..."118git clone --single-branch -b $branch https://github.com/Grasscutters/Grasscutter.git Grasscutter-src #change this to download a fork119120echo "Building grasscutter.jar..."121cd Grasscutter-src122chmod +x ./gradlew #just in case123./gradlew --no-daemon jar124mv $(find -name "grasscutter*.jar" -type f) ../grasscutter.jar125echo "Building grasscutter.jar done!"126cd ..127128# Generate handbook/config129echo "Grasscutter will be started to generate data files"130java -jar grasscutter.jar -version131132# Replaces "127.0.0.1" with given IP133echo "Replacing IP address in server config..."134sed -i "s/127.0.0.1/$SERVER_IP/g" config.json135# Generates new keystore.p12 with the server's IP address136# This is done to prevent a "Connection Timed Out" error from appearing137# after clicking to enter the door in the main menu/title screen138# This issue only exists when connecting to a server *other* than localhost139# since the default keystore.p12 has only been made for localhost140141mkdir certs142cd certs143echo "Generating CA key and certificate pair..."144openssl 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.crt145146echo "Generating SSL key and certificate pair..."147openssl genpkey -out ssl.key -algorithm rsa148149# Creates a conf file in order to generate a csr150cat > csr.conf <<EOF151[ req ]152default_bits = 2048153prompt = no154default_md = sha256155req_extensions = req_ext156distinguished_name = dn157158[ dn ]159C = GB160ST = Essex161L = London162O = Grasscutters163OU = Grasscutters164CN = $SERVER_IP165166[ req_ext ]167subjectAltName = @alt_names168169[ alt_names ]170IP.1 = $SERVER_IP171EOF172173# Creates csr using key and conf174openssl req -new -key ssl.key -out ssl.csr -config csr.conf175176# Creates conf to finalise creation of certificate177cat > cert.conf <<EOF178179authorityKeyIdentifier=keyid,issuer180basicConstraints=CA:FALSE181keyUsage = digitalSignature, nonRepudiation, keyEncipherment, keyAgreement, dataEncipherment182subjectAltName = @alt_names183184[alt_names]185IP.1 = $SERVER_IP186187EOF188189# Creates SSL cert190openssl x509 -req -in ssl.csr -CA CAcert.crt -CAkey CAkey.key -CAcreateserial -out ssl.crt -days 25202 -sha256 -extfile cert.conf191192echo "Generating keystore.p12 from key and certificate..."193openssl pkcs12 -export -out keystore.p12 -inkey ssl.key -in ssl.crt -certfile CAcert.crt -passout pass:123456194195cd ../196mv ./certs/keystore.p12 ./keystore.p12197echo "Done!"198199# Running scripts as sudo makes all Grasscutter files to be owned by root200# which may cause problems editing .jsons...201if [ $SUDO_USER ]; then202echo "Changing Grasscutter files owner to current user..."203chown -R $SUDO_USER:$SUDO_USER ./*204fi205206echo "Removing unnecessary files..."207rm -rf ./certs ./Grasscutter-src208209echo "All done!"210echo "-=-=-=-=-=--- !! IMPORTANT !! ---=-=-=-=-=-"211echo "Please make sure that ports 80, 443, 8888 and 22102 are OPEN (both tcp and udp)"212echo "In order to run the server, run the following command:"213echo " sudo java -jar grasscutter.jar"214echo "The GM Handbook of all supported languages will be generated automatically when you start the server for the first time."215echo "You must run it using sudo as port 443 is a privileged port"216echo "To play, use the IP you provided earlier ($SERVER_IP) via GrassClipper or Fiddler"217echo ""218219exit220221222