Advertisement
wiredbrother

Install for Auto Update to Paper Servers

Jul 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. start(){
  4. echo "Starting Installation..."
  5. read -p "Press enter to continue"
  6. currentvercheck(){
  7.     if [ -f currentversion.txt ]; then
  8.         echo "currentversion exists..."
  9.         cd ../
  10.         echo "creating start..."
  11.         cat << 'EOF' > start.sh
  12. #!/bin/bash
  13.  
  14.     #Check for Updates
  15.     ../updatescript/updatething.sh
  16.  
  17.     #Start Server
  18.     java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}
  19.  
  20. EOF
  21.         chmod +x start.sh
  22.         echo "Installation Finished"
  23.     else
  24.         echo "creating currentversion..."
  25.         cat << 'EOF' > currentversion.txt
  26. 0
  27. EOF
  28.         currentvercheck
  29.     fi
  30. }
  31.  
  32. uthingcheck(){
  33.     if [ -f updatething.sh ]; then
  34.         echo "updatething exists..."
  35.         currentvercheck
  36.     else
  37.         echo "creating updatething..."
  38.         cat << 'EOF' > updatething.sh
  39. #!/bin/bash
  40.  
  41. cd updatescript/
  42. current=`cat currentversion.txt`
  43.  
  44. echo "Checking for Server Update..."
  45. new=`curl -s "https://papermc.io/api/v1/paper/1.14.4" | jq -r '.builds | .latest' 2>&1 | tee latestversion.txt`
  46. echo "Paper is on version $new"
  47.  
  48. startserver(){
  49.     exit
  50. }
  51.  
  52.         comparedemapples(){
  53.             if [ "${new}" -gt "${current}" ]; then
  54.                 echo "paper-$new.jar is a new update."
  55.                 echo "Updating to paper-$new.jar"
  56.                 wget -nv -nc --content-disposition https://papermc.io/api/v1/paper/1.14.4/$new/download
  57.                 file="paper-$new.jar"
  58.                 if [ -f "$file" ]; then
  59.                     echo "paper-$new.jar has been downloaded. Renaming some shit..."
  60.                     cp paper-$new.jar ../server.jar
  61.                     echo "$new" > currentversion.txt
  62.                     startserver
  63.                 else
  64.                     echo "Error 404: paper-$new.jar could not be found."
  65.                     read -p "Press enter to continue"
  66.                 fi
  67.             else
  68.                 echo "paper-$new.jar is already installed and running."
  69.                 echo "You good on your updates my dude."
  70.                 startserver
  71.             fi
  72.         }
  73.  
  74. comparedemapples
  75. EOF
  76.         chmod +x updatething.sh
  77.         uthingcheck
  78.     fi
  79. }
  80.  
  81. dircheck(){
  82.     if [ -d updatescript ]; then
  83.         echo "updatescript exists..."
  84.         cd updatescript
  85.         uthingcheck
  86.     else
  87.         echo "creating updatescript..."
  88.         mkdir updatescript
  89.         dircheck
  90.     fi
  91. }
  92.  
  93. dircheck
  94.  
  95. }
  96.  
  97. start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement