diff --git a/dmg-wrapper/SheepIt-Run.sh b/dmg-wrapper/SheepIt-Run.sh index 3c3f63f..78a83c6 100755 --- a/dmg-wrapper/SheepIt-Run.sh +++ b/dmg-wrapper/SheepIt-Run.sh @@ -1,9 +1,83 @@ #!/bin/bash set -euo pipefail # Unofficial strict mode, see http://redsymbol.net/articles/unofficial-bash-strict-mode/ -cd "$(dirname "$(readlink -f "$0")")" +cd "${0%/*}" # see https://stackoverflow.com/questions/3349105/how-can-i-set-the-current-working-directory-to-the-directory-of-the-script-in-ba + +# This is bash on macOS, some stuff works different +BIN="" +APP="SheepIt" +LAUDIR="$HOME/Library/Application Support/SheepIt Launcher" +ARCH="$(uname -m)" +if [ "$ARCH" = "x86_64" ]; then + REPO="https://api.github.com/repos/adoptium/temurin11-binaries/releases" + JREDISTRO="OpenJDK11U-jre_x64_mac_hotspot" +elif [ "$ARCH" = "arm64" ]; then + REPO="https://api.github.com/repos/adoptium/temurin17-binaries/releases" + JREDISTRO="OpenJDK17U-jre_aarch64_mac_hotspot" +else + echo "What the fudge, what kind of Mac are you running ths under, PowerPC? Get outta here!" + exit 1 +fi +echo "NOTICE:" 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 + mkdir -p "$LAUDIR" + BIN="$LAUDIR/$APP" + JREVERSION="$LAUDIR/JRE-Version" + 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 | cut -d '"' -f 4 | head -n 1)" + if [ -z "$JRE_LATEST" ]; then + # Empty JRE_LATEST is a good indicator of a critical failure + echo "!!! Failed parsing JRE information! Aborting !!!" + echo "Possible causes and troubleshooting steps:" + echo "1. Check for internet connectivity \(Routes, DNS, Proxy\)" + echo "2. Github or the JRE repository may be down/unavailable." + echo " This might require a new version of the launcher from the SheepIt website: https://www.sheepit-renderfarm.com/" + echo "3. Open an issue on GitLab/Ask on the Discord if problems persists after 1. and 2." + exit 4 + elif [[ ! -f "$JREVERSION" || "$JRE_LATEST" != $(cat "$JREVERSION") ]]; then + 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 + 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)" + tar -xf "$LAUDIR/$JRE_LATEST" -C "$LAUDIR" + 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" + else + echo "No JRE updates detected" + fi +else + BIN="./$APP" +fi +JAR="$APP.jar" +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 + if [ -e "$LAUDIR/JOINBETA" ]; then + URL=https://www.sheepit-renderfarm.com/media/applet/client-beta.php + fi + 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="$LAUDIR/$JAR_LATEST" + if [ -z "$JAR_LATEST" ]; then + # Empty JAR_LATEST is a good indicator of a critical failure + echo "!!! Failed parsing $APP Jar information! Aborting !!!" + echo "Possible causes and troubleshooting steps:" + echo "1. Check for internet connectivity \(Routes, DNS, Proxy\)" + echo "2. Check the status of SheepIt via the SheepIt website: https://www.sheepit-renderfarm.com/" + echo "3. Open an issue on GitLab/Ask on the Discord if problems persists after 1. and 2." + exit 2 + elif [ ! -e "$JAR" ]; then + echo "Updates detected, updating $APP Jar to $JAR_LATEST" + rm -f "$LAUDIR/sheepit-client*.jar" || 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 + curl --connect-timeout 20 --retry 4 -# -L -o "$JAR" "$URL" + else + echo "No $APP Jar updates found" + fi +else + JAR="./$JAR" +fi + echo "=============================" echo "Loading and launching SheepIt" nohup "$BIN" -Xdock:icon=./$APP.png -Djna.nosys=true -jar "$JAR" &>/dev/null & disown diff --git a/dmg-wrapper/SheepIt.sh b/dmg-wrapper/SheepIt.sh new file mode 100755 index 0000000..af199c0 --- /dev/null +++ b/dmg-wrapper/SheepIt.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd "${0%/*}" +# see https://stackoverflow.com/questions/3349105/how-can-i-set-the-current-working-directory-to-the-directory-of-the-script-in-ba + +open -a Terminal.app ../Resources/client/SheepIt-Run.sh diff --git a/dmg-wrapper/SheepIt.tar.gz b/dmg-wrapper/SheepIt.tar.gz index 33151ed..012d939 100644 Binary files a/dmg-wrapper/SheepIt.tar.gz and b/dmg-wrapper/SheepIt.tar.gz differ diff --git a/dmg-wrapper/ci-build-dmg.sh b/dmg-wrapper/ci-build-dmg.sh index 94cf42c..437070c 100755 --- a/dmg-wrapper/ci-build-dmg.sh +++ b/dmg-wrapper/ci-build-dmg.sh @@ -13,6 +13,7 @@ FINAL="$APP-$ARCH.dmg" BASE="$(pwd)" BUILD="$BASE/build" +SH_DIR="$BUILD/SheepIt.app/Contents/MacOS" RES="$BUILD/SheepIt.app/Contents/Resources" CL="$RES/client" @@ -20,7 +21,7 @@ apt-get update apt-get install -y --no-install-recommends genisoimage # Add dependencies mkdir "$BUILD" -tar -axf "$APP.tar.gz" -C "$BUILD" # Extract base file structure + Platypus shell exec shim +tar -axf "$APP.tar.gz" -C "$BUILD" # Extract base file structure tar -axf "$BASE/$JRETAR" -C "$RES" # Extracts the JRE into Resources folder mkdir -p "$CL" @@ -28,6 +29,8 @@ cp ../sheepit-client-all.jar "$CL/$APP.jar" # Copy client artifact to be packag cp "$BASE/$APP-Run.sh" "$CL" cp "$BASE/$APP.png" "$CL" +mkdir -p "$SH_DIR" +cp "$BASE/$APP.sh" "$SH_DIR/$APP" # Shell exec shim cd "$CL" ln -s "$(find ../ -name java)" $APP # We symlink java to make the title appearing in the dock to read "SheepIt", not "java" cd "$BASE"