|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# ================================================================================ |
| 4 | +# You're not supposed to open this link directly |
| 5 | +# Please run the following command according to the app you use |
| 6 | +# -------- iSH -------- |
| 7 | +# wget -O - https://3ds.hacks.guide/assets/imset9.sh | sh |
| 8 | +# ------ a-Shell ------ |
| 9 | +# sh -c 'curl -sL -o imset9.sh https://3ds.hacks.guide/assets/imset9.sh && sh imset9.sh ; rm imset9.sh' |
| 10 | +# ================================================================================ |
| 11 | + |
| 12 | +OGPWD="$PWD" |
| 13 | +PLATFORM=$(uname) |
| 14 | +MACHINE=$(uname -m) |
| 15 | +RELEASE=$(uname -r) |
| 16 | +ENV=unknown |
| 17 | +if [ "$PLATFORM" = "Linux" ] && [ "$MACHINE" = "i686" ] && echo "$RELEASE" | grep -q -- '-ish$'; then |
| 18 | + ENV=ish |
| 19 | +fi |
| 20 | +if [ "$PLATFORM" = "Darwin" ] && echo "$MACHINE" | grep -q '^i\(Pod\|Phone\|Pad\)'; then |
| 21 | + ENV=ashell |
| 22 | +fi |
| 23 | + |
| 24 | +if [ "$ENV" = "unknown" ]; then |
| 25 | + echo "This is only for iSH or a-Shell on iOS/iPadOS." |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +case $ENV in |
| 30 | + "ish") |
| 31 | + command -v python3 >/dev/null || apk add python3 |
| 32 | + if ! command -v python3 >/dev/null; then |
| 33 | + echo "Failed to install python3, either try again or install manually." |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + ;; |
| 37 | + "ashell") |
| 38 | + true |
| 39 | + ;; |
| 40 | +esac |
| 41 | + |
| 42 | +case $ENV in |
| 43 | + "ish") |
| 44 | + MOUNT=$(mktemp -d) |
| 45 | + mount -t ios - "$MOUNT" |
| 46 | + sleep 1 |
| 47 | + cd "$MOUNT" |
| 48 | + ;; |
| 49 | + "ashell") |
| 50 | + if ! echo "$PWD" | grep -Fq "com.apple.filesystems.userfsd"; then |
| 51 | + pickFolder |
| 52 | + fi |
| 53 | + ;; |
| 54 | +esac |
| 55 | + |
| 56 | +if [ ! -f b9 ] || [ ! -f mset9.py ]; then |
| 57 | + echo "Downloading MSET9 files..." |
| 58 | + ZIP_API_URL="https://api.github.com/repos/hacks-guide/MSET9/releases/latest" |
| 59 | + case $ENV in |
| 60 | + "ish") |
| 61 | + # works...? |
| 62 | + #wget -O MSET9.zip $(wget -O - $ZIP_API_URL | grep -o '"https://github\.com/.\+/releases/download/.\+/.\+\.zip"' | tr -d '"') |
| 63 | + # probably better |
| 64 | + wget -O MSET9.zip $(wget -O - $ZIP_API_URL | python3 -c 'import json,sys;print(json.loads(sys.stdin.read())["assets"][0]["browser_download_url"])') |
| 65 | + ;; |
| 66 | + "ashell") |
| 67 | + # ashell have jq by default |
| 68 | + curl -sL -o MSET9.zip $(curl -sL $ZIP_API_URL | jq -r '.assets[0].browser_download_url') |
| 69 | + ;; |
| 70 | + esac |
| 71 | + python3 -m zipfile -e MSET9.zip . |
| 72 | + rm MSET9.zip |
| 73 | + if [ ! -f b9 ] || [ ! -f mset9.py ]; then |
| 74 | + echo "Unable to download MSET9 files automatically, please get them manually." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +fi |
| 78 | + |
| 79 | +clear |
| 80 | +case $ENV in |
| 81 | + "ish") |
| 82 | + # workaround for piped script |
| 83 | + python3 mset9.py </dev/tty |
| 84 | + ;; |
| 85 | + "ashell") |
| 86 | + # no permission to /dev/tty |
| 87 | + python3 mset9.py |
| 88 | + ;; |
| 89 | +esac |
| 90 | + |
| 91 | +case $ENV in |
| 92 | + "ish") |
| 93 | + cd "$OGPWD" |
| 94 | + umount "$MOUNT" |
| 95 | + rmdir "$MOUNT" |
| 96 | + ;; |
| 97 | + "ashell") |
| 98 | + true |
| 99 | + ;; |
| 100 | +esac |
0 commit comments