|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +repo="kdroidFilter/Nucleus" |
| 6 | +app_name="nucleusdemo" |
| 7 | + |
| 8 | +# Resolve latest version tag from GitHub |
| 9 | +echo "Checking latest version ..." |
| 10 | +version=$(curl -sI "https://github.com/${repo}/releases/latest" | grep -i '^location:' | sed 's/.*tag\///' | tr -d '\r\n') |
| 11 | + |
| 12 | +if [ -z "$version" ]; then |
| 13 | + echo "Failed to determine latest version." |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +# Strip leading 'v' for the filename (v1.1.1 -> 1.1.1) |
| 18 | +version_number="${version#v}" |
| 19 | +echo "Latest version: $version (${version_number})" |
| 20 | + |
| 21 | +arch=$(arch) |
| 22 | +if [[ "$arch" == "i386" ]]; then |
| 23 | + mac_zip_url="https://github.com/${repo}/releases/download/${version}/${app_name}-${version_number}-mac-x64.zip" |
| 24 | +elif [[ "$arch" == "arm64" ]]; then |
| 25 | + mac_zip_url="https://github.com/${repo}/releases/download/${version}/${app_name}-${version_number}-mac-arm64.zip" |
| 26 | +else |
| 27 | + echo "Unsupported CPU architecture: $arch" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +tmpdir="$(mktemp -d -t download)" |
| 32 | +tmpfile="$tmpdir/app.zip" |
| 33 | + |
| 34 | +cleanup() { |
| 35 | + cd "$HOME" || true |
| 36 | + if [ -e "$tmpfile" ]; then |
| 37 | + rm -f "$tmpfile" |
| 38 | + fi |
| 39 | + rmdir "$tmpdir" 2>/dev/null || true |
| 40 | +} |
| 41 | +trap cleanup EXIT |
| 42 | + |
| 43 | +echo "Downloading $app_name ..." |
| 44 | +curl -L --output "$tmpfile" --progress-bar "$mac_zip_url" |
| 45 | + |
| 46 | +if [ -w /Applications ]; then |
| 47 | + cd /Applications |
| 48 | +else |
| 49 | + if [ ! -d "$HOME/Applications" ]; then |
| 50 | + mkdir "$HOME/Applications" |
| 51 | + fi |
| 52 | + cd "$HOME/Applications" |
| 53 | +fi |
| 54 | + |
| 55 | +if [ -d "${app_name}.app" ]; then |
| 56 | + echo "App folder ${app_name}.app already exists, removing." |
| 57 | + rm -rf "${app_name}.app" |
| 58 | +fi |
| 59 | + |
| 60 | +echo "Extracting to $PWD ..." |
| 61 | +ditto -x -k "$tmpfile" . |
| 62 | + |
| 63 | +# Remove quarantine attribute |
| 64 | +if command -v xattr >/dev/null 2>&1; then |
| 65 | + xattr -r -d com.apple.quarantine "${app_name}.app" 2>/dev/null || true |
| 66 | +fi |
| 67 | + |
| 68 | +open "${app_name}.app" |
| 69 | + |
| 70 | +cleanup |
| 71 | +exit 0 |
0 commit comments