Skip to content

Commit

Permalink
add flag to redownload files on verification
Browse files Browse the repository at this point in the history
  • Loading branch information
cj123 committed Jul 29, 2014
1 parent e87bbf1 commit e7478d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Usage of :./download:
-c=false: just check the integrity of the currently downloaded files
-d="./": the location to save/check IPSW files
-i="": only download for the specified device
-r=false: redownload the file if it fails verification (w/ -c)
```
20 changes: 16 additions & 4 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ func DownloadIndividualFirmware(url string, filename string) (sha1sum string, er
}

// args!
var justCheck bool
var justCheck, redownloadIfBroken bool
var downloadDirectory, currentIPSW, onlyDevice string
var filesizeDownloaded, totalFirmwareSize int64
var totalFirmwareCount, totalDeviceCount, downloadCount int

func init() {
// parse the flags
flag.BoolVar(&justCheck, "c", false, "just check the integrity of the currently downloaded files")
flag.BoolVar(&redownloadIfBroken, "r", false, "redownload the file if it fails verification (w/ -c)")
flag.StringVar(&downloadDirectory, "d", "./", "the location to save/check IPSW files")
flag.StringVar(&onlyDevice, "i", "", "only download for the specified device")
flag.Parse()
Expand Down Expand Up @@ -254,9 +255,6 @@ func main() {
} else {
fmt.Println("✘")
}

size, _ := strconv.ParseInt(firmware.Size, 0, 0)
filesizeDownloaded += size
}

} else if _, err := os.Stat(filepath.Join(downloadDirectory, firmware.Filename)); !os.IsNotExist(err) && justCheck {
Expand All @@ -268,6 +266,20 @@ func main() {
fmt.Println("✔ ok")
} else {
fmt.Println("✘ bad")
if redownloadIfBroken {
fmt.Println("Redownloading...")
shasum, err := DownloadIndividualFirmware(firmware.URL, firmware.Filename)

if err != nil {
fmt.Println(err)
}

if shasum == firmware.SHA1 {
fmt.Println("✔")
} else {
fmt.Println("✘")
}
}
}

} else {
Expand Down

0 comments on commit e7478d5

Please sign in to comment.