Skip to content

Commit

Permalink
chore: add initial pcc download functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Nov 7, 2024
1 parent 990583d commit db96f10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/ipsw/cmd/download/download_pcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ var pccCmd = &cobra.Command{
viper.BindPFlag("download.restart-all", cmd.Flags().Lookup("restart-all"))

// settings
// proxy := viper.GetString("download.proxy")
proxy := viper.GetString("download.proxy")
// insecure := viper.GetBool("download.insecure")
// skipAll := viper.GetBool("download.skip-all")
// resumeAll := viper.GetBool("download.resume-all")
// restartAll := viper.GetBool("download.restart-all")

releases, err := download.GetPCCReleases("")
releases, err := download.GetPCCReleases(proxy)
if err != nil {
return err
}
Expand Down Expand Up @@ -120,7 +120,7 @@ var pccCmd = &cobra.Command{
log.Warn("Exiting...")
return nil
}

log.Infof("Downloading PCC Release for %d", releases[choice].Index)
return releases[choice].Download(viper.GetString("download.pcc.output"))
}

Expand Down
28 changes: 26 additions & 2 deletions internal/download/pcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -107,8 +109,30 @@ func (r PCCRelease) String() string {
}

func (r PCCRelease) Download(output string) error {
log.Infof("Downloading PCC Release for %d", r.Index)
log.Warn("Download not implemented")
if err := os.MkdirAll(output, 0755); err != nil {
return fmt.Errorf("failed to create output directory: %v", err)
}
for _, asset := range r.GetAssets() {
assetURL := asset.GetUrl()
filePath := filepath.Join(output, strings.TrimPrefix(asset.GetType().String(), "ASSET_TYPE_"))
log.WithFields(log.Fields{
"digest": hex.EncodeToString(asset.Digest.GetValue()),
"variant": asset.GetVariant(),
}).Info("Downloading Asset")
downloader := NewDownload("", false, false, false, false, false, false)
downloader.URL = assetURL
downloader.DestName = filePath
if err := downloader.Do(); err != nil {
return err
}
}
dat, err := json.MarshalIndent(r.DarwinInit.AsMap(), "", " ")
if err != nil {
return fmt.Errorf("failed to marshal darwin-init.json: %v", err)
}
if err := os.WriteFile(filepath.Join(output, "darwin-init.json"), dat, 0644); err != nil {
return fmt.Errorf("failed to write darwin-init.json: %v", err)
}
return nil
}

Expand Down

0 comments on commit db96f10

Please sign in to comment.