Skip to content

Commit

Permalink
add a 'download latest firmware only' option (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj123 committed Jul 16, 2018
1 parent 4bbd2b0 commit cfd3e38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
14 changes: 10 additions & 4 deletions allthefirmwares.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/signal"
"path/filepath"
"sort"
"text/template"

"github.com/cheggaaa/pb"
Expand All @@ -25,15 +26,16 @@ 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
totalFirmwareCount, totalDeviceCount int
)

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")
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit cfd3e38

Please sign in to comment.