Created
July 21, 2018 06:18
-
-
Save inoahdev/e497a8c35fedcbf56ddd87584c97844c to your computer and use it in GitHub Desktop.
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 show_message_on_fail show_tsschecker_output use_notification\n" | |
exit 1 | |
fi | |
model=$1 | |
boardconfig=$2 | |
version=$3 | |
ecid=$4 | |
save_folder=$5 | |
show_message_on_fail=$6 | |
show_tsschecker_output=$7 | |
show_notification=$8 | |
shsh_ecid_path=$(printf '%s/%s' "$save_folder" $ecid) | |
if [[ ! -d "$shsh_ecid_path" ]]; then | |
mkdir -p "$shsh_ecid_path" | |
fi | |
shsh_firmware_path="$shsh_ecid_path/Firmware" | |
if [[ ! -d "$shsh_firmware_path" ]]; then | |
mkdir -p "$shsh_firmware_path" | |
fi | |
shsh_ota_path="$shsh_ecid_path/OTA" | |
if [[ ! -d "$shsh_ota_path" ]]; then | |
mkdir -p "$shsh_ota_path" | |
fi | |
shsh_firmwares_already_exist=false | |
shsh_firmwares_prev_list=($(ls "$shsh_firmware_path" | grep $version)) | |
if [[ "${#shsh_firmwares_prev_list[@]}" -ne 0 ]]; then | |
shsh_firmwares_prev_list=("$(ls "$shsh_firmware_path" | grep $version)") | |
else | |
shsh_firmwares_already_exist=true | |
fi | |
shsh_otas_already_exist=false | |
shsh_otas_prev_list=($(ls "$shsh_ota_path" | grep $version)) | |
if [[ "${#shsh_otas_prev_list[@]}" -ne 0 ]]; then | |
shsh_otas_prev_list=("$(ls "$shsh_ota_path" | grep $version)") | |
else | |
shsh_otas_already_exist=true | |
fi | |
tss_firmware_result=1 | |
tss_ota_result=1 | |
if [[ $show_tsschecker_output = true ]]; then | |
tsschecker_custom -d $model --boardconfig $boardconfig -i $version -e $ecid -s --save-to-cache | |
else | |
tsschecker_custom -d $model --boardconfig $boardconfig -i $version -e $ecid -s --save-to-cache &> /dev/null | |
fi | |
tss_firmware_result=$? | |
if [[ $show_tsschecker_output = true ]]; then | |
tsschecker_custom -d $model --boardconfig $boardconfig -i $version -e $ecid -o -s --save-to-cache | |
else | |
tsschecker_custom -d $model --boardconfig $boardconfig -i $version -e $ecid -o -s --save-to-cache &> /dev/null | |
fi | |
tss_ota_result=$? | |
shsh_firmwares_new_list=("$(ls "$shsh_firmware_path" | grep $version)") | |
shsh_otas_new_list=("$(ls "$shsh_ota_path" | grep $version)") | |
shsh_firmwares_added=("${shsh_firmwares_new_list[@]/$shsh_firmwares_prev_list}") | |
shsh_otas_added=("${shsh_otas_new_list[@]/$shsh_otas_prev_list}") | |
function print_build { | |
echo $1 | cut -d '(' -f 2 | cut -d ')' -f 1 | |
} | |
function get_builds { | |
local array=("$@") | |
local result=() | |
for version in "${array[@]}" | |
do | |
local build=$(print_build "$version") | |
result+=($build) | |
done | |
echo "${result[@]}" | |
} | |
shsh_firmware_builds_added=($(get_builds "${shsh_firmwares_added[@]}")) | |
shsh_ota_builds_added=($(get_builds "${shsh_otas_added[@]}")) | |
function error_message { | |
if [[ $show_message_on_fail = true ]]; then | |
if [[ $show_notification = true ]]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$1") | |
osascript -e "$notification" | |
else | |
printf "$1\n" | |
fi | |
fi | |
exit 0 | |
} | |
if [[ ${#shsh_firmware_builds_added[@]} -eq 0 && ${#shsh_firmwares_prev_list[@]} -eq 0 && | |
${#shsh_ota_builds_added[@]} -eq 0 && ${#shsh_otas_prev_list[@]} -eq 0 ]]; then | |
error_message "NO builds of iOS version $version are being signed" | |
elif [[ ${#shsh_firmware_builds_added[@]} -eq 0 && ${#shsh_firmwares_prev_list[@]} -ne 0 && | |
${#shsh_ota_builds_added[@]} -eq 0 && ${#shsh_otas_prev_list[@]} -eq 0 ]]; then | |
error_message "NO new firmware builds of iOS version $version are being signed" | |
elif [[ ${#shsh_ota_builds_added[@]} -eq 0 && ${#shsh_otas_prev_list[@]} -ne 0 && | |
${#shsh_firmware_builds_added[@]} -eq 0 && ${#shsh_firmwares_prev_list[@]} -eq 0 ]]; then | |
error_message "NO new ota builds of iOS version $version are being signed" | |
elif [[ ${#shsh_firmware_builds_added[@]} -eq 0 && ${#shsh_ota_builds_added[@]} -eq 0 ]]; then | |
error_message "NO new builds of iOS version $version are being signed" | |
fi | |
function has_object { | |
local array=("$2") | |
local object="$1" | |
for array_object in "${array[@]}" | |
do | |
if [[ "$array_object" == "$object" ]]; then | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
added_firmware_builds=() | |
added_otas_builds=() | |
added_both_builds=() | |
failed_firmware_builds=() | |
failed_ota_builds=() | |
for build in "${shsh_firmware_builds_added[@]}" | |
do | |
has_object $build "${shsh_ota_builds_added[@]}" | |
if [[ $? -eq 0 ]]; then | |
added_both_builds+=($build) | |
else | |
added_firmware_builds+=($build) | |
failed_ota_builds+=($build) | |
fi | |
done | |
for build in "${shsh_ota_builds_added[@]}" | |
do | |
has_object $build "${shsh_firmware_builds_added[@]}" | |
if [[ $? -ne 0 ]]; then | |
added_ota_builds+=($build) | |
failed_firmware_builds+=($build) | |
fi | |
done | |
message="Success! Saved SHSH for $version" | |
if [[ ${#added_both_builds[@]} -ne 0 ]]; then | |
message+=$(printf "%s %s" "\nBoth Firmware & OTA SHSH were saved for the following" 'build(s):\n') | |
message+="${added_both_builds[0]}" | |
for (( i=2; i<=${#added_both_builds[@]}; i++ )) | |
do | |
message+="\n$build" | |
done | |
fi | |
if [[ ${#added_firmware_builds[@]} -ne 0 ]]; then | |
if [[ ${#added_both_builds[@]} -ne 0 ]]; then | |
message+="\n" | |
fi | |
if [[ $shsh_otas_already_exist = true ]]; then | |
message+=$(printf "%s %s" "\nFirmware SHSH was saved, but no new builds for OTA SHSH were available" 'for the following build(s):\n') | |
else | |
message+=$(printf "%s %s" "\nFirmware SHSH was saved, but OTA SHSH was not available" 'for the following build(s):\n') | |
fi | |
message+="${added_firmware_builds[0]}" | |
for (( i=2; i<=${#added_firmware_builds[@]}; i++ )) | |
do | |
message+="\n$build" | |
done | |
fi | |
if [[ ${#added_ota_builds[@]} -ne 0 ]]; then | |
if [[ ${#added_both_builds[@]} -ne 0 || ${#added_firmware_builds[@]} -ne 0 ]]; then | |
message += "\n" | |
fi | |
if [[ $shsh_firmwares_already_exist = true ]]; then | |
message+=$(printf "%s, %s" "\nOTA SHSH was saved, but no new builds for Firmware SHSH were available" 'for the following builds:\n') | |
else | |
message+=$(printf "%s, %s" "\nOTA SHSH was saved, but Firmware SHSH was not available" 'for the following builds:\n') | |
fi | |
message+="${added_ota_builds[0]}" | |
for (( i=2; i<=${#added_ota_builds[@]}; i++ )) | |
do | |
message+="\n$build" | |
done | |
fi | |
message+="\n" | |
if [[ $show_notification = true ]]; then | |
notification=$(printf 'display notification \"%s\" with title "tsschecker"' "$message") | |
osascript -e "$notification" | |
else | |
printf "$message" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment