OscarXcore

ServerMaker.sh

Feb 13th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.72 KB | None | 0 0
  1. #!/bin/bash
  2. #title      :ServerMaker.sh
  3. #description    :Creates and starts a server for any CurseForge modpack
  4. #author     :Stapleton
  5. #date       :20190127
  6. #version    :0.5
  7. #usage      :./ServerMaker.sh <CurseForgeLink>
  8. #notes      :Needs Java 8 JRE to install and run the server
  9. #=======================================================
  10. packlink=$1
  11. cmpdlpackversion=${2:-latest}
  12. log=ServerMaker.log
  13. forgeprop=server.properties
  14. cmpdl="cmpdl-1.2.jar"
  15.  
  16. if [ -f ./$log  ]; then
  17.     rm $log
  18. fi
  19.  
  20. div======================================================
  21.  
  22. cmpdllink=https://github.com/Vazkii/CMPDL/releases/download/1.2/cmpdl-1.2.jar
  23.  
  24. xms=1G
  25. xmx=6G
  26. jar_args=nogui
  27. java_args="-server -d64 -Xms$xms -Xmx$xmx -XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M -Dfml.readTimeout=180"
  28.  
  29. /usr/bin/clear
  30.  
  31. _GetCMPDL() {
  32.     wget -q $cmpdllink &&
  33.     chmod +x ./$cmpdl
  34. }
  35.  
  36. _InstallModpack() {
  37.     /usr/bin/java -jar $cmpdl $packlink $cmpdlpackversion | tee -a $log | grep -e "Downloading [A-Za-z]" -e "Downloaded!"
  38.  
  39.     packdir=$(grep -e "Output Dir is " ./$log)
  40.     packdir=${packdir#"Output Dir is "}
  41.  
  42.     mv "$packdir"/minecraft/* .
  43.     mv "$packdir"/instance.cfg ./.instance.cfg
  44.     rm -rf "$packdir"
  45. }
  46.  
  47. _GetVars() {
  48.     forgeversion=$(grep notes ./.instance.cfg | cut -d= -f2 | cut -d" " -f9)
  49.     forgeversion=${forgeversion%"."}
  50.     packversion=$(grep name ./.instance.cfg | cut -d= -f2)
  51.     packversion=${packversion##*\ }
  52.     mcversion=$(grep IntendedVersion ./.instance.cfg | cut -d= -f2)
  53.  
  54.     forgelink=https://files.minecraftforge.net/maven/net/minecraftforge/forge/$mcversion-$forgeversion/forge-$mcversion-$forgeversion-installer.jar
  55.     forgeinstaller="forge-$mcversion-$forgeversion-installer.jar"
  56.     forge="forge-$mcversion-$forgeversion-universal.jar"
  57. }
  58.  
  59. _BannerInstall() {
  60.     echo $div
  61.     echo "Installing Modpack Server"
  62.     echo "Minecraft $mcversion"
  63.     echo "Modpack Version: $packversion"
  64.     echo "Using Forge: $forgeversion"
  65.     echo $div
  66.     echo ""
  67. }
  68.  
  69. _BannerStart() {
  70.     echo $div
  71.     echo "Starting Modpack Server"
  72.     echo "Minecraft $mcversion"
  73.     echo "Modpack Version: $packversion"
  74.     echo "Using Forge: $forgeversion"
  75.     echo $div
  76.     echo ""
  77. }
  78.  
  79. _GetForge() {
  80.     wget -q $forgelink &&
  81.     chmod +x ./$forgeinstaller
  82. }
  83.  
  84. _InstallForge() {
  85.     /usr/bin/java -jar $forgeinstaller --installServer
  86. }
  87.  
  88. _Setup() {
  89.     echo "eula=true" >> eula.txt
  90.     echo "allow-flight=true" >> $forgeprop
  91.     echo "server-ip=0.0.0.0" >> $forgeprop
  92. }
  93.  
  94. _Cleanup() {
  95.     rm -rf $forgeinstaller $forgeinstaller.log $cmpdl
  96. }
  97.  
  98. _StartServer() {
  99.     /usr/bin/java $java_args -jar $forge $jar_args
  100. }
  101.  
  102. Install() {
  103.     echo $div
  104.     echo "Downloading CMPDL from Github"
  105.     echo $div
  106.     _GetCMPDL >> $log &&
  107.     /usr/bin/clear
  108.  
  109.     echo $div
  110.     echo "Downloading Modpack from Curseforge via CMPDL"
  111.     echo $div
  112.     _InstallModpack &&
  113.     /usr/bin/clear
  114.  
  115.     _GetVars &&
  116.  
  117.     _BannerInstall &&
  118.     /usr/bin/clear
  119.  
  120.     echo $div  
  121.     echo "Downloading Forge $forgeversion"
  122.     echo $div
  123.     _GetForge >> $log &&
  124.     /usr/bin/clear
  125.  
  126.     echo $div
  127.     echo "Installing Forge $forgeversion Server"
  128.     echo $div
  129.     _InstallForge >> $log &&
  130.     /usr/bin/clear
  131.  
  132.     echo $div
  133.     echo "Setting up Modpack Server"
  134.     echo $div
  135.     _Setup &&
  136.     /usr/bin/clear
  137.  
  138.     echo $div
  139.     echo "Cleaning up installation files"
  140.     echo $div
  141.     _Cleanup &&
  142.     /usr/bin/clear
  143.  
  144.     echo $div
  145.     echo "Successfully installed Modpack Server"
  146.     echo "Minecraft $mcversion"
  147.     echo "Modpack Version: $packversion"
  148.     echo "Using Forge: $forgeversion"
  149.     echo $div
  150.     echo ""
  151. }
  152.  
  153. Start() {
  154.     _GetVars &&
  155.     _BannerStart &&
  156.     _StartServer
  157. }
  158.  
  159. if [ ! -f ./minecraft*.jar ]; then
  160.     if [ "$packlink" == '' ]; then
  161.         echo "No CurseForge Modpack link was supplied!"
  162.         exit
  163.     fi
  164.     Install
  165. else
  166.     Start
  167. fi
Advertisement
Add Comment
Please, Sign In to add comment