]> git.cameronkatri.com Git - tsssave.git/commitdiff
Add tsssave
authorCameron Katri <me@cameronkatri.com>
Wed, 22 Sep 2021 01:54:22 +0000 (21:54 -0400)
committerCameron Katri <me@cameronkatri.com>
Wed, 22 Sep 2021 01:54:22 +0000 (21:54 -0400)
tsssave [new file with mode: 0755]

diff --git a/tsssave b/tsssave
new file mode 100755 (executable)
index 0000000..f7a00f4
--- /dev/null
+++ b/tsssave
@@ -0,0 +1,90 @@
+#!/bin/sh
+# 
+# Example config.yaml:
+#   output: /var/www/html/tss/
+#   devices:
+#     device1:
+#       deviceid: iPhone11,8
+#       board: n841ap
+#       ecid: ecidhere
+#       generator: genhere
+#       apnonce: apnonce
+#     device2:
+#       deviceid: iPhone12,1
+#       board: n104ap
+#       ecid: ecidhere
+#       generator: genhere
+#       apnonce: apnonce
+# 
+
+if ! command -v yq; then
+       printf "Please install yq\nhttps://github.com/mikefarah/yq\n"
+       missingdep=1
+fi
+
+if ! command -v jq; then
+       printf "Please install jq\nhttps://github.com/stedolan/jq\n"
+       missingdep=1
+fi
+
+if ! command -v tsschecker; then
+       printf "Please install tsschecker\nhttps://github.com/1Conan/tsschecker\n"
+       missingdep=1
+fi
+
+if ! command -v pzb; then
+       printf "Please install pzb\nhttps://github.com/tihmstar/partialZipBrowser\n"
+       missingdep=1
+fi
+
+[ ! -z "${missingdep}" ] && exit 1
+
+if [ -z "${1}" ]; then
+       printf "Usage: tsssave configfile\n"
+       exit 1
+fi
+
+config="$(realpath "${1}")"
+
+output="$(yq e ".output" ${config})"
+
+mkdir -p "${output}"
+cd "$(yq e '.temppath // "/tmp"' ${config})"
+
+for device in $(yq e '.devices | keys | .[]' ${config}); do
+       deviceid="$(yq e ".devices.${device}.deviceid" ${config})"
+       board="$(yq e ".devices.${device}.board" ${config})"
+       ecid="$(yq e ".devices.${device}.ecid" ${config})"
+       generator="$(yq e ".devices.${device}.generator" ${config})"
+       apnonce="$(yq e ".devices.${device}.apnonce" ${config})"
+       
+       # RELEASE VERSIONS
+       
+       for signed in $(curl -s https://api.ipsw.me/v4/device/${deviceid} | jq -re '.firmwares[] | select(.signed == true) | .buildid'); do
+               version="$(curl -s https://api.ipsw.me/v4/device/${deviceid} | jq -re ".firmwares[] | select(.buildid == \"${signed}\") | .version")"
+               if [ -e ${output}/${version}/$(printf "%d\n" ${ecid})_${deviceid}_$(printf "${board}\n" | tr '[A-Z]' '[a-z]')_*-${signed}_*.shsh2 ]; then
+                       printf "Skipping %s...\n" ${signed}
+               else
+                       printf "Saving %s...\n" ${signed}
+                       pzb "$(curl -s https://api.ipsw.me/v4/ipsw/${deviceid}/${signed} | jq -re '.url')" -g BuildManifest.plist -o BuildManifest-${board}-${signed}.plist
+                       mkdir -p ${output}/${device}/${version}/
+                       tsschecker -d "${deviceid}" -B "${board}" -m /tmp/BuildManifest-${board}-${signed}.plist -s -e "${ecid}" --generator "${generator}" \
+                               --apnonce "${apnonce}" --save-path ${output}/${device}/${version}/
+               fi
+       done
+       
+       # BETA VERSIONS
+       
+       for signed in $(curl -sL https://api.m1sta.xyz/betas/${deviceid} | jq -re '.[] | select(.signed == true) | .buildid'); do
+               version="$(curl -s https://api.m1sta.xyz/betas/${deviceid} | jq -re ".[] | select(.buildid == \"${signed}\") | .version")"
+               if [ -e ${output}/${version}/beta/$(printf "%d\n" ${ecid})_${deviceid}_$(printf "${board}\n" | tr '[A-Z]' '[a-z]')_*-${signed}_*.shsh2 ]; then
+                       printf "Skipping %s...\n" ${signed}
+               else
+                       printf "Saving %s...\n" ${signed}
+                       pzb "$(curl -sL https://api.m1sta.xyz/betas/${deviceid} | jq -re ".[] | select(.buildid == \"${signed}\") | .url")" -g BuildManifest.plist -o BuildManifest-${board}-${signed}.plist
+                       mkdir -p ${output}/${device}/${version}/
+                       tsschecker -d "${deviceid}" -B "${board}" -m /tmp/BuildManifest-${board}-${signed}.plist -s -e "${ecid}" --generator "${generator}" \
+                               --apnonce "${apnonce}" --save-path ${output}/${device}/${version}/beta/
+               fi
+       done
+done