DMG-CI-Build - Use regex

This commit is contained in:
DaCoolX
2023-08-16 12:31:49 +02:00
parent 63ecf6079a
commit f6b1a7a8cb

View File

@@ -11,22 +11,36 @@ LAUDIR="$HOME/Library/Application Support/SheepIt Launcher"
ARCH="$(uname -m)" ARCH="$(uname -m)"
if [ "$ARCH" = "x86_64" ]; then if [ "$ARCH" = "x86_64" ]; then
REPO="https://api.github.com/repos/adoptium/temurin11-binaries/releases" REPO="https://api.github.com/repos/adoptium/temurin11-binaries/releases"
JREDISTRO="OpenJDK11U-jre_x64_mac_hotspot" JRE_ARCH="x64"
elif [ "$ARCH" = "arm64" ]; then elif [ "$ARCH" = "arm64" ]; then
REPO="https://api.github.com/repos/adoptium/temurin17-binaries/releases" REPO="https://api.github.com/repos/adoptium/temurin17-binaries/releases"
JREDISTRO="OpenJDK17U-jre_aarch64_mac_hotspot" JRE_ARCH="aarch64"
else else
echo "What the fudge, what kind of Mac are you running ths under, PowerPC? Get outta here!" echo "What the fudge, what kind of Mac are you running this under, PowerPC? Get outta here!"
exit 1 exit 1
fi fi
echo "NOTICE:" echo "NOTICE:"
echo "Please only pin the first window - the launcher to the Dock" echo "Please only pin the first window - the launcher to the Dock"
if [ ! -e "./$APP" ]; then #If JRE exists in the dmg, don't download it if [ ! -e "./$APP" ]; then # If JRE exists in the dmg, don't download it
mkdir -p "$LAUDIR" mkdir -p "$LAUDIR"
BIN="$LAUDIR/$APP" BIN="$LAUDIR/$APP"
JREVERSION="$LAUDIR/JRE-Version" JREVERSION="$LAUDIR/JRE-Version"
echo "Checking for JRE updates" echo "Checking for JRE updates"
JRE_LATEST="$(curl --connect-timeout 20 --retry 4 --silent --show-error $REPO | grep $JREDISTRO | grep name | grep tar | grep -v json | grep -v txt | grep -v sig | cut -d '"' -f 4 | head -n 1)" # Let me explain this before it gets unexplainable/unmaintainable
# sed -nE
# -n aka --quiet for not printing our entire pattern space, more on that later
# -E aka --regexp-extended is self-explanatory, note, this ain't your luxurious PCRE, this is what we can work with:
# https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions
# 's|regexp|replacement|p'
# s is substitute mode, for more on that, consult `man sed(1)`
# | is our separator, sed in s mode is often used with / as a separator, we don't since we are working with URLs and paths
# regexp is the regex, I can't explain that here, read up on it or spare yourself the suffering
# replacement is in our case \1 which is the first capture group, the stuff in ()
# p instructs sed to print our match and since we used -n, only our match
# Using different types of quoted strings like ''"" after one another, it concatenates them
JRE_SED_PATTERN='s|.*\"(https.*OpenJDK.*jre.*'"$JRE_ARCH"'.*mac.*\.tar\.gz)\".*|\1|p'
JRE_URL="$(curl --connect-timeout 20 --retry 4 --silent --show-error $REPO | sed -nE "$JRE_SED_PATTERN" | head -n 1)"
JRE_LATEST="$(echo "$JRE_URL" | sed -nE 's|.*/(OpenJDK.*)$|\1|p')" # Separate filename after last slash
if [ -z "$JRE_LATEST" ]; then if [ -z "$JRE_LATEST" ]; then
# Empty JRE_LATEST is a good indicator of a critical failure # Empty JRE_LATEST is a good indicator of a critical failure
echo "!!! Failed parsing JRE information! Aborting !!!" echo "!!! Failed parsing JRE information! Aborting !!!"
@@ -40,7 +54,7 @@ if [ ! -e "./$APP" ]; then #If JRE exists in the dmg, don't download it
echo "Updates detected, updating JRE to $JRE_LATEST" echo "Updates detected, updating JRE to $JRE_LATEST"
rm -rf "$LAUDIR/jdk*" "$BIN" || true # The "|| true" is that we expect the command to fail (If there is nothing to remove), needed since we are running in strict mode rm -rf "$LAUDIR/jdk*" "$BIN" || true # The "|| true" is that we expect the command to fail (If there is nothing to remove), needed since we are running in strict mode
echo "$JRE_LATEST" > "$JREVERSION" echo "$JRE_LATEST" > "$JREVERSION"
curl --connect-timeout 20 --retry 4 -# -L -o "$LAUDIR/$JRE_LATEST" "$(curl --connect-timeout 20 --retry 4 -s $REPO | grep $JREDISTRO | grep browser_download_url | grep tar | grep -v json | grep -v txt | cut -d '"' -f 4 | head -n 1)" curl --connect-timeout 20 --retry 4 -# -L -o "$LAUDIR/$JRE_LATEST" "$JRE_URL"
tar -xf "$LAUDIR/$JRE_LATEST" -C "$LAUDIR" tar -xf "$LAUDIR/$JRE_LATEST" -C "$LAUDIR"
rm "$LAUDIR/$JRE_LATEST" rm "$LAUDIR/$JRE_LATEST"
ln -s "$(find "$LAUDIR" -name java)" "$LAUDIR/$APP" # We symlink java to make the title appearing in the dock to read "SheepIt", not "java" ln -s "$(find "$LAUDIR" -name java)" "$LAUDIR/$APP" # We symlink java to make the title appearing in the dock to read "SheepIt", not "java"
@@ -51,13 +65,13 @@ else
BIN="./$APP" BIN="./$APP"
fi fi
JAR="$APP.jar" JAR="$APP.jar"
if [ ! -e ./$JAR ]; then #If Jar exists in the dmg, don't download it if [ ! -e ./$JAR ]; then # If Jar exists in the dmg, don't download it
URL=https://www.sheepit-renderfarm.com/media/applet/client-latest.php URL=https://www.sheepit-renderfarm.com/media/applet/client-latest.php
if [ -e "$LAUDIR/JOINBETA" ]; then if [ -e "$LAUDIR/JOINBETA" ]; then
URL=https://www.sheepit-renderfarm.com/media/applet/client-beta.php URL=https://www.sheepit-renderfarm.com/media/applet/client-beta.php
fi fi
echo "Checking for $APP Jar updates" echo "Checking for $APP Jar updates"
JAR_LATEST="$(curl --connect-timeout 20 --retry 4 --silent --show-error --head $URL | grep -i content-disposition | cut -d '=' -f 2 | tr -ud '\r ')" JAR_LATEST="$(curl --connect-timeout 20 --retry 4 --silent --show-error --head $URL | sed -nE 's|.*(sheepit.*\.jar).*|\1|p')"
JAR="$LAUDIR/$JAR_LATEST" JAR="$LAUDIR/$JAR_LATEST"
if [ -z "$JAR_LATEST" ]; then if [ -z "$JAR_LATEST" ]; then
# Empty JAR_LATEST is a good indicator of a critical failure # Empty JAR_LATEST is a good indicator of a critical failure