Skip to content

Commit

Permalink
feat: add ability to skip sha1 verification in download macos cmd a…
Browse files Browse the repository at this point in the history
…s well as only download InstallAssistant.pkg with `--assistant` flag
  • Loading branch information
blacktop committed Feb 23, 2022
1 parent a6dec39 commit c42bd57
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/download_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ var gitCmd = &cobra.Command{
"file": destName,
}).Info("Downloading")
// download file
downloader := download.NewDownload(proxy, insecure, false, false, false, false)
downloader := download.NewDownload(proxy, insecure, false, false, false, false, false)
downloader.URL = tarURL
downloader.DestName = destName

Expand Down
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/download_ipsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ var ipswCmd = &cobra.Command{
"signed": i.Signed,
}).Info("Getting IPSW")

downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, Verbose)
downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, false, Verbose)
downloader.URL = i.URL
downloader.Sha1 = i.SHA1
downloader.DestName = destName
Expand Down
8 changes: 7 additions & 1 deletion cmd/ipsw/cmd/download_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ func init() {

macosCmd.Flags().BoolP("list", "l", false, "Show latest macOS installers")
macosCmd.Flags().StringP("work-dir", "w", "", "macOS installer creator working directory")
macosCmd.Flags().Bool("ignore", false, "Do NOT verify pkg digests")
macosCmd.Flags().BoolP("assistant", "a", false, "Only download the InstallAssistant.pkg")
// macosCmd.Flags().BoolP("kernel", "k", false, "Extract kernelcache from remote installer")
viper.BindPFlag("download.macos.list", macosCmd.Flags().Lookup("list"))
viper.BindPFlag("download.macos.work-dir", macosCmd.Flags().Lookup("work-dir"))
viper.BindPFlag("download.macos.ignore", macosCmd.Flags().Lookup("ignore"))
viper.BindPFlag("download.macos.assistant", macosCmd.Flags().Lookup("assistant"))
// viper.BindPFlag("download.macos.kernel", macosCmd.Flags().Lookup("kernel"))
}

Expand Down Expand Up @@ -85,6 +89,8 @@ var macosCmd = &cobra.Command{
// flags
showInstallers := viper.GetBool("download.macos.list")
workDir := viper.GetString("download.macos.work-dir")
ignoreSha1 := viper.GetBool("download.macos.ignore")
assistantOnly := viper.GetBool("download.macos.assistant")
// remoteKernel := viper.GetString("download.macos.kernel")

// verify args
Expand Down Expand Up @@ -153,7 +159,7 @@ var macosCmd = &cobra.Command{
}
}
if cont {
if err := prod.DownloadInstaller(workDir, proxy, insecure, skipAll, resumeAll, restartAll); err != nil {
if err := prod.DownloadInstaller(workDir, proxy, insecure, skipAll, resumeAll, restartAll, ignoreSha1, assistantOnly); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/download_ota.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ var otaDLCmd = &cobra.Command{
}
}
} else {
downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, Verbose)
downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, false, Verbose)
for _, o := range otas {
folder := filepath.Join(destPath, fmt.Sprintf("%s%s_OTAs", o.ProductSystemName, strings.TrimPrefix(o.OSVersion, "9.9.")))
os.MkdirAll(folder, os.ModePerm)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/download_wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var wikiCmd = &cobra.Command{
}

if cont {
downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, Verbose)
downloader := download.NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, false, Verbose)
for _, url := range filteredURLS {
destName := getDestName(url, removeCommas)
if _, err := os.Stat(destName); os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipsw/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var updateCmd = &cobra.Command{
}
}

downloader := download.NewDownload(proxy, insecure, false, false, false, Verbose)
downloader := download.NewDownload(proxy, insecure, false, false, false, false, Verbose)
fname := strings.Replace(path.Base(asset.DownloadURL), ",", "_", -1)
fname = filepath.Join(destPath, fname)
if _, err := os.Stat(fname); os.IsNotExist(err) {
Expand Down
1 change: 1 addition & 0 deletions internal/download/dev_portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ func (app *App) Download(url string) error {
app.config.SkipAll,
app.config.ResumeAll,
app.config.RestartAll,
false,
app.config.Verbose,
)
// use authenticated client
Expand Down
8 changes: 5 additions & 3 deletions internal/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Download struct {
skipAll bool
resumeAll bool
restartAll bool
ignoreSha1 bool
verbose bool

client *http.Client
Expand All @@ -62,14 +63,15 @@ type geoQuery struct {
}

// NewDownload creates a new downloader
func NewDownload(proxy string, insecure, skipAll, resumeAll, restartAll, verbose bool) *Download {
func NewDownload(proxy string, insecure, skipAll, resumeAll, restartAll, ignoreSha1, verbose bool) *Download {
return &Download{
// URL: url,
// Sha1: sha1,
resume: false,
skipAll: skipAll,
resumeAll: resumeAll,
restartAll: restartAll,
ignoreSha1: ignoreSha1,
verbose: verbose,
client: &http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -296,7 +298,7 @@ func (d *Download) Do() error {
dest.Sync()
dest.Close()

if len(d.Sha1) > 0 {
if len(d.Sha1) > 0 && !d.ignoreSha1 {
utils.Indent(log.Info, 2)("verifying sha1sum...")
if ok, _ := utils.Verify(d.Sha1, d.DestName+".download"); !ok {
// fileLock.Unlock()
Expand All @@ -321,7 +323,7 @@ func (d *Download) Do() error {
dest.Sync()
dest.Close()

if len(d.Sha1) > 0 {
if len(d.Sha1) > 0 && !d.ignoreSha1 {
utils.Indent(log.Info, 2)("verifying sha1sum...")
checksum, _ := hex.DecodeString(d.Sha1)

Expand Down
20 changes: 15 additions & 5 deletions internal/download/macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const (
sucatalogs17 = "https://swscan.apple.com/content/catalogs/others/index-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs18 = "https://swscan.apple.com/content/catalogs/others/index-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs19 = "https://swscan.apple.com/content/catalogs/others/index-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs20 = "https://swscan.apple.com/content/catalogs/others/index-11-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs21 = "https://swscan.apple.com/content/catalogs/others/index-12seed-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs20 = "https://swscan.apple.com/content/catalogs/others/index-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
sucatalogs21 = "https://swscan.apple.com/content/catalogs/others/index-12-10.16-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"
)

type seedCatalog struct {
Expand Down Expand Up @@ -309,17 +309,20 @@ func GetProductInfo() (ProductInfos, error) {
return prods, nil
}

func (i *ProductInfo) DownloadInstaller(workDir, proxy string, insecure, skipAll, resumeAll, restartAll bool) error {
func (i *ProductInfo) DownloadInstaller(workDir, proxy string, insecure, skipAll, resumeAll, restartAll, ignoreSha1, assistantOnly bool) error {

downloader := NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, true)
downloader := NewDownload(proxy, insecure, skipAll, resumeAll, restartAll, ignoreSha1, true)

folder := filepath.Join(workDir, i.Title)
folder := filepath.Join(workDir, fmt.Sprintf("%s_%s_%s", i.ProductID, i.Version, i.Build))

os.MkdirAll(folder, os.ModePerm)

log.Info("Downloading packages")
for _, pkg := range i.Product.Packages {
if len(pkg.URL) > 0 {
if assistantOnly && !strings.HasSuffix(pkg.URL, "InstallAssistant.pkg") {
continue
}
destName := getDestName(pkg.URL, false)
if _, err := os.Stat(filepath.Join(folder, destName)); os.IsNotExist(err) {
log.WithFields(log.Fields{
Expand All @@ -340,6 +343,9 @@ func (i *ProductInfo) DownloadInstaller(workDir, proxy string, insecure, skipAll
}

} else if len(pkg.MetadataURL) > 0 {
if assistantOnly && !strings.HasSuffix(pkg.MetadataURL, "InstallAssistant.pkg") {
continue
}
destName := getDestName(pkg.MetadataURL, false)
if _, err := os.Stat(filepath.Join(folder, destName)); os.IsNotExist(err) {
log.WithFields(log.Fields{
Expand All @@ -362,6 +368,10 @@ func (i *ProductInfo) DownloadInstaller(workDir, proxy string, insecure, skipAll
}
}

if assistantOnly {
return nil
}

volumeName := fmt.Sprintf("Install_macOS_%s-%s", i.Version, i.Build)
sparseDiskimagePath := filepath.Join(folder, volumeName+".sparseimage")

Expand Down
2 changes: 1 addition & 1 deletion internal/download/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Oss struct {
func (p *project) Download() error {

// proxy, insecure are null because we override the client below
downloader := NewDownload("", false, false, false, false, false)
downloader := NewDownload("", false, false, false, false, false, false)

destName := getDestName(p.URL, false)
if _, err := os.Stat(destName); os.IsNotExist(err) {
Expand Down

0 comments on commit c42bd57

Please sign in to comment.