Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Configuration
- LOADER="https://dev.azure.com/EverestAPI/Everest/_apis/build/builds?api-version=7.0"
- BRANCH="stable"
- # Output
- RST="\033[0;00m"
- RED="\033[0;31m"
- RDB="\033[1;31m"
- # Required
- for pkg in curl jq unzip rsync mono; do
- if ! command -v "$pkg" > /dev/null; then
- printf "%b\n" "${RDB}error${RST}: package '${RED}$pkg${RST}' not found"
- exit 1
- fi
- done
- # Celeste
- if [ ! -f Celeste.exe ]; then
- printf "%b\n" "${RDB}error${RST}: executable '${RED}$(realpath Celeste.exe)${RST}' not found"
- exit 1
- fi
- # Everest
- if command -v nc > /dev/null; then
- if ! nc -z -w 10 "$(printf "%s" "$LOADER" |
- sed "s#https://##g" | cut -d / -f 1)" 443 > /dev/null 2>&1; then
- printf "%b\n" "${RDB}error${RST}: server '${RED}$LOADER${RST}' not available"
- exit 1
- fi
- fi
- # Setup
- CACHE=$(mktemp -d "${XDG_RUNTIME_DIR:-/tmp}/everest-XXXXXXXXX")
- trap "rm -rf '$CACHE'; exit 1" 1 2 3 6 15
- # Parse
- parse() {
- if [ "$(printf "%s" "$1" | sed "s#refs/heads/##g")" != "$BRANCH" ]; then
- return 1
- elif [ "$2" != completed ]; then
- return 1
- elif [ "$3" != succeeded ]; then
- return 1
- elif [ "$4" != manual ] && [ "$4" != individualCI ]; then
- return 1
- else
- return 0
- fi
- }
- # Process
- curl -sL "$LOADER" | jq -r '.value[] | .sourceBranch + " " + .status + " "
- + .result + " " + .reason + " " + (.id|tostring)' | while read -r json; do
- # Parse
- if parse $json; then
- # Setup
- EVEREST=$(printf "%s" "$LOADER" | cut -d \? -f 1)
- VERSION=$(printf "%s" "$json" | cut -d " " -f 5)
- ARCHIVE="$EVEREST/$VERSION/artifacts?artifactName=main&api-version=7.0&%24format=zip"
- # Download
- curl -sL "$ARCHIVE" -o "$CACHE/everest.zip"
- break
- fi
- done
- # Extract
- if [ -f "$CACHE/everest.zip" ]; then
- unzip "$CACHE/everest.zip" -d "$CACHE" > /dev/null 2>&1
- else
- rm -rf "$CACHE"
- printf "%b\n" "${RDB}error${RST}: archive '${RED}$CACHE/everest.zip${RST}' not found"
- exit 1
- fi
- # Replace
- if [ -d "$CACHE/main" ]; then
- rsync -aAX --checksum "$CACHE/main/" ./
- else
- rm -rf "$CACHE"
- printf "%b\n" "${RDB}error${RST}: directory '${RED}$CACHE/main${RST}' not found"
- exit 1
- fi
- # Destroy
- rm -rf "$CACHE"
- # Patch
- if [ -f MiniInstaller.exe ]; then
- mono MiniInstaller.exe
- else
- printf "%b\n" \
- "${RDB}error${RST}: executable '${RED}$(realpath MiniInstaller.exe)${RST}' not found"
- exit 1
- fi
- # Close
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement