Skip to content

Instantly share code, notes, and snippets.

@neilmartin83
Last active July 24, 2019 18:53
Show Gist options
  • Save neilmartin83/9b6b2163edb71e2e6e578df54f0d599a to your computer and use it in GitHub Desktop.
Save neilmartin83/9b6b2163edb71e2e6e578df54f0d599a to your computer and use it in GitHub Desktop.
#!/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