summaryrefslogtreecommitdiffstats
path: root/tsssave
blob: cae16f79a89b65e7540123f4881fb5eb0e13ea6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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 >/dev/null; then
	printf "Please install yq\nhttps://github.com/mikefarah/yq\n"
	missingdep=1
fi

if ! command -v jq >/dev/null; then
	printf "Please install jq\nhttps://github.com/stedolan/jq\n"
	missingdep=1
fi

if ! command -v tsschecker >/dev/null; then
	printf "Please install tsschecker\nhttps://github.com/1Conan/tsschecker\n"
	missingdep=1
fi

if ! command -v pzb >/dev/null; 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}/${device}/${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" | sed 's/ /-/g')"
		if [ -e ${output}/${device}/${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 -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}/
		fi
	done
done