Last active
September 2, 2018 18:55
-
-
Save inoahdev/e48a5929621e8410333dfb1b13ecf07f to your computer and use it in GitHub Desktop.
tsschecker script but caches build-manifests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 8 ]; then | |
printf "Usage: model boardconfig version ecid save-folder print_message_on_failure_bool show_tsschecker_output use_notification\n" | |
exit 1 | |
fi | |
if [ ! -d "$5" ]; then | |
mkdir -p "$5" | |
fi | |
shsh_version_path=$(printf '%s/%s' "$5" $3) | |
shsh_ota_path=$(printf '%s/%s' "$shsh_version_path" "OTA") | |
tss_firmware_result=1 | |
tss_ota_result=1 | |
manifests_path=$(printf '%s/%s' "$5" "BuildManifests") | |
if [ ! -d "$manifests_path" ]; then | |
mkdir -p $manifests_path | |
fi | |
search=$(printf '%s_%s_' $1 $3) | |
manifests=($(ls "$manifests_path" | grep $search)) | |
manifests_count=${#manifests[@]} | |
if [ $manifests_count -eq 0 ]; then | |
if [ $7 = true ]; then | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 | |
else | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 &> /dev/null | |
fi | |
tss_firmware_result=$? | |
if [ -d /tmp/tsschecker ]; then | |
manifests=($(ls /tmp/tsschecker | grep $search)) | |
manifests_count=${#manifests[@]} | |
if [ $manifests_count -ne 0 ]; then | |
mkdir -p "$manifests_path" | |
for manifest in "${manifests[@]}"; do | |
cp $(printf '/tmp/tsschecker/%s' $manifest) "$manifests_path" | |
done | |
else | |
printf "Failed to get manifests. Apple's servers may be down or You are not connected to the internet. Aborting\n" | |
exit 1 | |
fi | |
else | |
printf "Failed to get manifests. Apple's servers may be down or You are not connected to the internet. Aborting\n" | |
exit 1 | |
fi | |
fi | |
function contains_element { | |
local e match="$1" | |
shift | |
for e; do [[ "$e" == "$match" ]] && return 0; done | |
return 1 | |
} | |
succeeded_build_numbers=() | |
version_and_builds_already_exist=true | |
for manifest in "${manifests[@]}"; do | |
manifest_path=$(printf '%s/%s' "$manifests_path" $manifest) | |
manifest_build_number=$(plutil -p "$manifest_path" | grep "BuildNumber") | |
build_number=$(echo ${manifest_build_number%\"*}) | |
build_number=$(echo ${build_number##*\"}) | |
shsh_version_path_with_build_number=$(printf '%s (%s)' "$shsh_version_path" $build_number) | |
shsh_firmware_path=$(printf '%s/%s' "$shsh_version_path_with_build_number" "Firmware") | |
shsh_ota_path=$(printf '%s/%s' "$shsh_version_path_with_build_number" "OTA") | |
if [[ $manifest == *ota ]]; then | |
if [ ! -d "$shsh_ota_path" ]; then | |
if [ $7 = true ]; then | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 -s --save-path "$5" -m "$manifest_path" -o | |
else | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 -s --save-path "$5" -m "$manifest_path" -o &> /dev/null | |
fi | |
tss_ota_result_temp=$? | |
if [ $tss_ota_result_temp -eq 0 ]; then | |
shsh_ota=($(ls "$5" | grep ".shsh2$")) | |
shsh_ota_count=${#shsh_ota[@]} | |
if [[ $shsh_ota_count -ne 0 ]]; then | |
if [ ! -d "$shsh_version_path_with_build_number" ]; then | |
mkdir -p "$shsh_version_path_with_build_number" | |
fi | |
shsh_ota_tmp_path=${shsh_ota[0]} | |
mkdir -p "$shsh_ota_path" | |
mv $(printf '%s/%s' "$5" $shsh_ota_tmp_path) "$shsh_ota_path" | |
if [ $tss_ota_result_temp -eq 0 ]; then | |
tss_ota_result=$tss_ota_result_temp | |
fi | |
contains_element $build_number $succeeded_build_numbers | |
if [ $? -ne 0 ]; then | |
succeeded_build_numbers+=($build_number) | |
fi | |
version_and_builds_already_exist=false | |
fi | |
fi | |
fi | |
else | |
if [ ! -d "$shsh_firmware_path" ]; then | |
if [ $7 = true ]; then | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 -s --save-path "$5" -m "$manifest_path" | |
else | |
tsschecker -d $1 --boardconfig $2 -i $3 -e $4 -s --save-path "$5" -m "$manifest_path" &> /dev/null | |
fi | |
tss_firmware_result_temp=$? | |
if [ $tss_firmware_result_temp -eq 0 ]; then | |
shsh_firmware=($(ls "$5" | grep ".shsh2$")) | |
shsh_firmware_count=${#shsh_firmware[@]} | |
if [[ $shsh_firmware_count -ne 0 ]]; then | |
if [ ! -d "$shsh_version_path_with_build_number" ]; then | |
mkdir -p "$shsh_version_path_with_build_number" | |
fi | |
mkdir -p "$shsh_firmware_path" | |
mv $(printf '%s/%s' "$5" ${shsh_firmware[0]}) "$shsh_firmware_path" | |
if [ $tss_firmware_result_temp -eq 0 ]; then | |
tss_firmware_result=$tss_firmware_result_temp | |
fi | |
contains_element $build_number $succeeded_build_numbers | |
if [ $? -ne 0 ]; then | |
succeeded_build_numbers+=($build_number) | |
fi | |
version_and_builds_already_exist=false | |
fi | |
fi | |
fi | |
fi | |
done | |
if [ $version_and_builds_already_exist = true ]; then | |
if [ $6 = true ]; then | |
printf 'Both Firmware & OTA SHSH for all builds being signed of iOS %s have already been saved\n' $3 | |
fi | |
exit 0 | |
fi | |
function to_string { | |
array=$2 | |
array_count=${#array[@]} | |
if [[ $array_count -eq 0 ]]; then | |
printf "" | |
fi | |
printf ${array[0]} | |
for (( i=1; i<$array_count; i++ )); do | |
printf '%s%s' "$1" ${array[$i]} | |
done | |
} | |
succeeded_build_numbers_string=$(to_string ', ' ${succeeded_build_numbers[@]}) | |
if [[ $tss_firmware_result -eq 0 ]]; then | |
if [[ $tss_ota_result -eq 0 ]]; then | |
message=$(printf 'Saved Firmware & OTA SHSH for iOS %s (Build(s): %s)' $3 "$succeeded_build_numbers_string") | |
if [ $8 = true ]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$message") | |
osascript -e "$notification" | |
else | |
printf 'Success! %s\n' "$message" | |
fi | |
else | |
message=$(printf 'Saved Firmware SHSH for iOS %s (Build(s): %s), but could not save OTA SHSH' $3 "$succeeded_build_numbers_string") | |
if [ $8 = true ]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$message") | |
osascript -e "$notification" | |
else | |
printf 'Partial Success! %s\n' "$message" | |
fi | |
rm -rf "$shsh_ota_path" | |
fi | |
else | |
if [[ $tss_ota_result -eq 0 ]]; then | |
if [ $8 = true ]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$message") | |
osascript -e "$notification" | |
else | |
printf 'Partial Success! Saved OTA SHSH for iOS %s (Build(s): %s), but could not save Firmware SHSH\n' $3 "$succeeded_build_numbers_string" | |
fi | |
rm -rf "$shsh_firmware_path" | |
else | |
if [[ $6 = true ]]; then | |
message=$(printf 'Both Firmware & OTA SHSH for iOS %s are NOT being signed' $3) | |
if [ $8 = true ]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$message") | |
osascript -e "$notification" | |
else | |
printf 'Failure! %s\n' "$message" | |
fi | |
fi | |
rm -rf "$shsh_firmware_path" | |
rm -rf "$shsh_ota_path" | |
rm -rf "$shsh_version_path" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment