Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# Check a list of serial numbers for eligibility in the 2015 MacBook Pro battery replacement recall
# Returns only eligible serial numbers
# The text file must be formatted with Unix (LF) line breaks
#
# Usage: mbpserialcheck.sh /path/to/inputfile.txt
#
# To output directly to a CSV file: mbpserialcheck.sh /path/to/inputfile.txt > /path/to/outputfile.csv
#
# Written by Neil Martin https://soundmacguy.wordpress.com
#
# With thanks to Nick Tong for his original Jamf EA which gave me the inspiration for this script. https://www.jamf.com/jamf-nation/discussions/32400/battery-recall-for-15-mid-2015-mbp
#
# 2019-06-21
#
# 2019-06-30 revised to read file directly and avoid problems with filenames containing spaces - thanks to Ben Goodstein.
#
# Edit the variable below to the filename of your text file containing a list of serial numbers to check
file=$1
# Do not edit below this line
# Verify the file exists
if [[ ! -e "$file" ]]; then
echo "Serial number list file not found or specified"
echo "Ensure that the filename and path specified are correct"
echo "Script usage: ./mbpserialcheck.sh /path/to/file.txt"
exit 1
fi
# Loop through the list and submit data to Apple
while read -r serial || [[ -n "$serial" ]]; do
guid=$(uuidgen | tr "[:upper:]" "[:lower:]")
postData="{\"serial\":$serial,\"GUID\":$guid}"
resp=$(curl -d "$postData" -H "Content-Type: application/json" -X POST "https://qualityprograms.apple.com/snlookup/062019" 2>&1)
if [[ "$resp" == *'"status":"E00"'* ]]; then
echo "$serial,eligible"
elif [[ "$resp" == *'"status":"E01"'* ]]; then
echo "$serial,ineligible"
elif [[ "$resp" == *'"status":"E99"'* ]]; then
echo "$serial,error please recheck"
elif [[ "$resp" == *'"status":"FE01"'* ]]; then
echo "$serial,empty serial"
elif [[ "$resp" == *'"status":"FE02"'* ]]; then
echo "$serial,invalid serial"
elif [[ "$resp" == *'"status":"FE03"'* ]]; then
echo "$serial,error please recheck"
else
echo "$serial,unknown result please recheck"
fi
done < "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment