From cfd3e38da0244bafb099ca084d55fe1c68cf7e62 Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Mon, 16 Jul 2018 18:19:22 +0100 Subject: [PATCH] add a 'download latest firmware only' option (fixes #3) --- README.md | 5 +++-- allthefirmwares.go | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ee24ab..dd13ca4 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,13 @@ Usage ``` $ ./allthefirmwares --help Usage of ./allthefirmwares: - -c just check the integrity of the currently downloaded files + -c just check the integrity of the currently downloaded files (if any) -d string the location to save/check IPSW files. - Can include templates e.g. {{.Identifier}} or {{.BuildID}} (default "./") + Can include templates e.g. {{.Identifier}} or {{.BuildID}} (default "./") -i string only download for the specified device + -l only download the latest firmware for the specified devices -r redownload the file if it fails verification (w/ -c) -s only download signed firmwares ``` diff --git a/allthefirmwares.go b/allthefirmwares.go index 2e6587e..333af77 100644 --- a/allthefirmwares.go +++ b/allthefirmwares.go @@ -14,6 +14,7 @@ import ( "os" "os/signal" "path/filepath" + "sort" "text/template" "github.com/cheggaaa/pb" @@ -25,8 +26,8 @@ var ( ipswClient = api.NewIPSWClient("https://api.ipsw.me/v4", nil) // flags - verifyIntegrity, reDownloadOnVerificationFailed, downloadSigned bool - downloadDirectoryTemplate, specifiedDevice string + verifyIntegrity, reDownloadOnVerificationFailed, downloadSigned, downloadLatest bool + downloadDirectoryTemplate, specifiedDevice string // counters downloadedSize, totalFirmwareSize uint64 @@ -34,6 +35,7 @@ var ( ) func init() { + flag.BoolVar(&downloadLatest, "l", false, "only download the latest firmware for the specified devices") flag.BoolVar(&verifyIntegrity, "c", false, "just check the integrity of the currently downloaded files (if any)") flag.BoolVar(&reDownloadOnVerificationFailed, "r", false, "redownload the file if it fails verification (w/ -c)") flag.BoolVar(&downloadSigned, "s", false, "only download signed firmwares") @@ -80,8 +82,12 @@ func main() { totalDeviceCount++ - for _, ipsw := range deviceInformation.Firmwares { - if downloadSigned && !ipsw.Signed { + sort.Slice(deviceInformation.Firmwares, func(i int, j int) bool { + return deviceInformation.Firmwares[i].UploadDate.Time.After(deviceInformation.Firmwares[j].UploadDate.Time) + }) + + for index, ipsw := range deviceInformation.Firmwares { + if (downloadSigned && !ipsw.Signed) || (index > 0 && downloadLatest) { continue }