-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcmd_download.go
53 lines (47 loc) · 1.16 KB
/
cmd_download.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"sort"
"strings"
"github.com/freemyipod/wInd3x/pkg/app"
"github.com/freemyipod/wInd3x/pkg/cache"
"github.com/golang/glog"
"github.com/spf13/cobra"
)
var downloadBits = map[string]cache.PayloadKind{
"wtf": cache.PayloadKindWTFUpstream,
"bootloader": cache.PayloadKindBootloaderUpstream,
"retailos": cache.PayloadKindRetailOSUpstream,
"diags": cache.PayloadKindDiagsUpstream,
}
var downloadCmd = &cobra.Command{
Use: "download [kind] [output path]",
Short: "Download update files from Apple's CDN",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
app, err := app.New()
if err != nil {
return err
}
defer app.Close()
kind, ok := downloadBits[args[0]]
if !ok {
var opts []string
for k := range downloadBits {
opts = append(opts, k)
}
sort.Strings(opts)
return fmt.Errorf("invalid kind, must be one of: %s", strings.Join(opts, ", "))
}
by, err := cache.Get(app, kind)
if err != nil {
return err
}
if err := os.WriteFile(args[1], by, 0600); err != nil {
return err
}
glog.Infof("Wrote %s to %s", args[0], args[1])
return nil
},
}