Skip to content

Commit

Permalink
Fix build failure, add disable validation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Nov 11, 2024
1 parent acafa41 commit 9051ebd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/dd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"bufio"
"bytes"
"errors"
"io"
"io/fs"
Expand Down
28 changes: 27 additions & 1 deletion app/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package app

import "strconv"
import (
"os"
"strconv"
)

type ConfigurationFlags struct {
UseSystemDd bool
DisableValidation bool
}

func ParseCLIFlags() ([]string, ConfigurationFlags) {
args := []string{}
config := ConfigurationFlags{}
if len(os.Args) == 0 {
return args, config
}
for _, arg := range os.Args[1:] {
if arg == "--use-system-dd" {
config.UseSystemDd = true
} else if arg == "--disable-validation" {
config.DisableValidation = true
} else {
args = append(args, arg)
}
}
return args, config
}

func BytesToString(bytes int, binaryPowers bool) string {
i := ""
Expand Down
29 changes: 18 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,32 @@ func main() {
log.SetFlags(0)
log.SetOutput(os.Stderr)
log.SetPrefix("[flash] ")
if len(os.Args) < 4 {
println("Invalid usage: imprint flash <file> <destination> (--use-system-dd)")
args, flags := app.ParseCLIFlags()
if len(args) < 4 {
println("Invalid usage: imprint flash <file> <destination> (--use-system-dd) (--disable-validation)")
os.Exit(1)
}
log.Println("Phase 1/3: Unmounting disk.")
if err := app.UnmountDevice(os.Args[3]); err != nil {
totalPhases := "3"
if flags.DisableValidation {
totalPhases = "2"
}
log.Println("Phase 1/" + totalPhases + ": Unmounting disk.")
if err := app.UnmountDevice(args[1]); err != nil {
log.Println(err)
if !strings.HasSuffix(os.Args[3], "debug.iso") {
if !strings.HasSuffix(args[1], "debug.iso") {
os.Exit(1)
}
}
log.Println("Phase 2/3: Writing ISO to disk.")
if len(os.Args) > 4 && os.Args[4] == "--use-system-dd" {
app.RunDd(os.Args[2], os.Args[3])
log.Println("Phase 2/" + totalPhases + ": Writing ISO to disk.")
if flags.UseSystemDd {
app.RunDd(args[0], args[1])
} else {
app.FlashFileToBlockDevice(os.Args[2], os.Args[3])
app.FlashFileToBlockDevice(args[0], args[1])
}
if flags.DisableValidation {
log.Println("Phase 3/" + totalPhases + ": Validating written image on disk.")
app.ValidateBlockDeviceContent(args[0], args[1])
}
log.Println("Phase 3/3: Validating written image on disk.")
app.ValidateBlockDeviceContent(os.Args[2], os.Args[3])
return
}
debug := false
Expand Down

0 comments on commit 9051ebd

Please sign in to comment.