Advertisement
Guest User

Untitled

a guest
May 8th, 2022
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.41 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Configuration
  4. LOADER="https://dev.azure.com/EverestAPI/Everest/_apis/build/builds?api-version=7.0"
  5. BRANCH="stable"
  6.  
  7. # Output
  8. RST="\033[0;00m"
  9. RED="\033[0;31m"
  10. RDB="\033[1;31m"
  11.  
  12. # Required
  13. for pkg in curl jq unzip rsync mono; do
  14.   if ! command -v "$pkg" > /dev/null; then
  15.     printf "%b\n" "${RDB}error${RST}: package '${RED}$pkg${RST}' not found"
  16.     exit 1
  17.   fi
  18. done
  19.  
  20. # Celeste
  21. if [ ! -f Celeste.exe ]; then
  22.   printf "%b\n" "${RDB}error${RST}: executable '${RED}$(realpath Celeste.exe)${RST}' not found"
  23.   exit 1
  24. fi
  25.  
  26. # Everest
  27. if command -v nc > /dev/null; then
  28.   if ! nc -z -w 10 "$(printf "%s" "$LOADER" |
  29.    sed "s#https://##g" | cut -d / -f 1)" 443 > /dev/null 2>&1; then
  30.     printf "%b\n" "${RDB}error${RST}: server '${RED}$LOADER${RST}' not available"
  31.     exit 1
  32.   fi
  33. fi
  34.  
  35. # Setup
  36. CACHE=$(mktemp -d "${XDG_RUNTIME_DIR:-/tmp}/everest-XXXXXXXXX")
  37. trap "rm -rf '$CACHE'; exit 1" 1 2 3 6 15
  38.  
  39. # Parse
  40. parse() {
  41.   if [ "$(printf "%s" "$1" | sed "s#refs/heads/##g")" != "$BRANCH" ]; then
  42.     return 1
  43.   elif [ "$2" != completed ]; then
  44.     return 1
  45.   elif [ "$3" != succeeded ]; then
  46.     return 1
  47.   elif [ "$4" != manual ] && [ "$4" != individualCI ]; then
  48.     return 1
  49.   else
  50.     return 0
  51.   fi
  52. }
  53.  
  54. # Process
  55. curl -sL "$LOADER" | jq -r '.value[] | .sourceBranch + " " + .status + " "
  56.  + .result + " " + .reason + " " + (.id|tostring)' | while read -r json; do
  57.   # Parse
  58.   if parse $json; then
  59.     # Setup
  60.     EVEREST=$(printf "%s" "$LOADER" | cut -d \? -f 1)
  61.     VERSION=$(printf "%s" "$json" | cut -d " " -f 5)
  62.     ARCHIVE="$EVEREST/$VERSION/artifacts?artifactName=main&api-version=7.0&%24format=zip"
  63.  
  64.     # Download
  65.     curl -sL "$ARCHIVE" -o "$CACHE/everest.zip"
  66.     break
  67.   fi
  68. done
  69.  
  70. # Extract
  71. if [ -f "$CACHE/everest.zip" ]; then
  72.   unzip "$CACHE/everest.zip" -d "$CACHE" > /dev/null 2>&1
  73. else
  74.   rm -rf "$CACHE"
  75.   printf "%b\n" "${RDB}error${RST}: archive '${RED}$CACHE/everest.zip${RST}' not found"
  76.   exit 1
  77. fi
  78.  
  79. # Replace
  80. if [ -d "$CACHE/main" ]; then
  81.   rsync -aAX --checksum "$CACHE/main/" ./
  82. else
  83.   rm -rf "$CACHE"
  84.   printf "%b\n" "${RDB}error${RST}: directory '${RED}$CACHE/main${RST}' not found"
  85.   exit 1
  86. fi
  87.  
  88. # Destroy
  89. rm -rf "$CACHE"
  90.  
  91. # Patch
  92. if [ -f MiniInstaller.exe ]; then
  93.   mono MiniInstaller.exe
  94. else
  95.   printf "%b\n" \
  96.     "${RDB}error${RST}: executable '${RED}$(realpath MiniInstaller.exe)${RST}' not found"
  97.   exit 1
  98. fi
  99.  
  100. # Close
  101. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement