Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Last active March 28, 2018 17:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucaTNT/f946bf38a6a5c62b3fbc to your computer and use it in GitHub Desktop.
Save LucaTNT/f946bf38a6a5c62b3fbc to your computer and use it in GitHub Desktop.
Automatic iOS firmware downloader
#!/bin/bash
# lookForNewiOS.sh
# Author: Luca Zorzi (@LucaTNT)
# Version: 0.2 (2014/11/20)
# License: BSD
# -----------------------------
# This scripts uses icj.me's API to check if there are new iOS releases for
# the iOS devices specified in the MODELS array. You can put any number of devices,
# as long as they are in an array (space separated, enclosed in brackets).
# If a new release is available, it gets download into the DESTINATION_FOLDER, respecting
# SPEED_LIMIT for each download: so if say you set SPEED_LIMIT to 1M and you want to download
# firwares for 5 devices, you will end up using (up to) 5 megabyte/s of bandwidth.
# The download will be handled in background by wget. You will be told wget's PID and log file.
# I suggest that you put this script in your crontab to execute it automatically at night.
# If no new versions of iOS are found and older versions of iOS are still present in the
# destination folder, they will be deleted.
MODELS=(iPhone5,2 iPhone5,4 iPhone7,2 iPad4,2 iPad5,4)
DESTINATION_FOLDER="/var/www/iOS/"
SPEED_LIMIT="500k"
pushd $DESTINATION_FOLDER > /dev/null
function downloadFirmware
{
wget -b --limit=$SPEED_LIMIT $1
}
for model in ${MODELS[@]}
do
URL="`wget -q -O - http://api.ios.icj.me/v2/$model/latest/url`"
FILENAME=${URL##*/}
if [ ! -f $FILENAME ]
then
echo "New iOS release available for device $model"
echo "Starting download from $URL"
downloadFirmware $URL
else
echo "No new iOS release for device $model"
if [ `ls $model* | wc -l` -gt 1 ]
then
echo "Found older firmware version(s) for $model, I'm deleting them."
OLD_VERSION="`ls $model* | grep -v $FILENAME`"
rm -f $OLD_VERSION
fi
fi
echo "----------------------------------------------------------------"
done
# Delete old wget-log files
find . -name wget-log\* -mtime +1 -exec rm {} \;
popd > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment