mirror of
https://github.com/hairyhenderson/go-onerng.git
synced 2025-07-07 10:55:44 -05:00
a bunch of updates, including verify function
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
26
cmd/image.go
26
cmd/image.go
@ -3,6 +3,9 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/hairyhenderson/go-onerng"
|
||||
"github.com/spf13/cobra"
|
||||
@ -10,17 +13,34 @@ import (
|
||||
|
||||
// imageCmd represents the image command
|
||||
func imageCmd(ctx context.Context) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
var imgOut string
|
||||
cmd := &cobra.Command{
|
||||
Use: "image",
|
||||
Short: "Dump the OneRNG's firmware image",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o := onerng.OneRNG{Path: opts.Device}
|
||||
err := o.Init(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "init failed before image extraction")
|
||||
}
|
||||
image, err := o.Image(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%q\n", image)
|
||||
return nil
|
||||
var out *os.File
|
||||
if imgOut == "-" {
|
||||
out = os.Stdout
|
||||
} else {
|
||||
out, err = os.OpenFile(imgOut, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
n, err := out.Write(image)
|
||||
fmt.Fprintf(os.Stderr, "Wrote %db to %s\n", n, imgOut)
|
||||
return err
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(&imgOut, "out", "o", "onerng.img", "output file for image (use - for stdout)")
|
||||
return cmd
|
||||
}
|
||||
|
Reference in New Issue
Block a user