Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of CLI + Cobra #69

Merged
merged 39 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1b7f188
Added new print module
Foxboron May 16, 2021
955c547
Added more fidelity to the logging methods
Foxboron May 16, 2021
0d249b2
Added bundle cli format
Foxboron May 16, 2021
7a4defc
Added deps
Foxboron May 16, 2021
431363f
Added list-files new WIP for commands
Foxboron May 16, 2021
62d653d
Added status new format
Foxboron May 16, 2021
2a53d52
Added list-bundles setup
Foxboron May 16, 2021
a05e6c8
Fixed commands with colors off
Foxboron May 16, 2021
bb78cf9
Remove previous logging, improve error bubling
Foxboron May 16, 2021
b82e17e
Return errors when generating bundles
Foxboron May 16, 2021
3568e9d
sbctl: Buble up errors from the "library"
Foxboron May 16, 2021
1508b29
Moved json out function
Foxboron May 17, 2021
23381e0
Added NotOK instead of "Error". Makes more sense semantically
Foxboron May 17, 2021
3d7f094
Added an iter function
Foxboron May 17, 2021
fb9b3c7
🤷
Foxboron May 17, 2021
30e16f5
Catch for unknown command
Foxboron May 17, 2021
70b00f3
Added new error
Foxboron May 18, 2021
d0022cb
Added BundleIter
Foxboron May 18, 2021
877ab49
Implement GetGUID
Foxboron May 18, 2021
adadb52
Give status the ability to display owner GUID
Foxboron May 18, 2021
3505f1b
New structure
Foxboron May 18, 2021
a5e0551
GUID package
Foxboron May 18, 2021
342ba34
Fixup
Foxboron May 18, 2021
235238c
Fixed lint issues
Foxboron May 18, 2021
f01453a
Change immutable error a little bit
Foxboron May 18, 2021
97435cc
More internal restructuring
Foxboron May 18, 2021
3454841
Moved create-keys top-level
Foxboron May 18, 2021
a318695
Moved generate-bundles top-level
Foxboron May 18, 2021
3f05d1d
Propegate errors better
Foxboron May 18, 2021
6dfc186
enroll changes
Foxboron May 19, 2021
b49ebbb
Added CanVerifyFiles
Foxboron May 19, 2021
8b4fc40
Added internal functions for checked paths, and CheckMSDos
Foxboron May 19, 2021
0d12167
Move verify to top-level
Foxboron May 19, 2021
fe514e1
Added errors to WriteFileDatabase
Foxboron May 19, 2021
6b0242c
Added print layout for key syncing
Foxboron May 19, 2021
57a1c93
Remove last of the log.* stuff
Foxboron May 19, 2021
ba0cee8
Make lint happy
Foxboron May 19, 2021
550b4e6
Move global flags to persistent
Foxboron May 22, 2021
ae1aec1
sbctl: Ensure all commands inherit stdout turning off
Foxboron May 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed lint issues
Signed-off-by: Morten Linderud <morten@linderud.pw>
  • Loading branch information
Foxboron committed May 30, 2021
commit 235238c987ea0d1c1ae3f251057b8d62669b33b9
2 changes: 1 addition & 1 deletion cmd/sbctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func JsonOut(v interface{}) error {
if err != nil {
return fmt.Errorf("could not marshal json: %w", err)
}
fmt.Fprintf(os.Stdout, string(b))
fmt.Fprint(os.Stdout, string(b))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/sbctl/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var statusCmd = &cobra.Command{
func RunStatus(cmd *cobra.Command, args []string) error {
ret := map[string]interface{}{}
if _, err := os.Stat("/sys/firmware/efi/efivars"); os.IsNotExist(err) {
return fmt.Errorf("system is not booted with UEFI!")
return fmt.Errorf("system is not booted with UEFI")
}
u, err := sbctl.GetGUID()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func SignFile(key, cert, file, output, checksum string) error {

// Check file exists before we do anything
if _, err := os.Stat(file); os.IsNotExist(err) {
return fmt.Errorf("%s does not exist!", file)
return fmt.Errorf("%s does not exist", file)
}

// Let's check if we have signed it already AND the original file hasn't changed
Expand All @@ -183,10 +183,10 @@ func SignFile(key, cert, file, output, checksum string) error {
return fmt.Errorf("couldn't access %s", key)
}

logging.Ok("signing %s", file)
logging.Ok("Signing %s", file)
_, err = exec.Command("sbsign", "--key", key, "--cert", cert, "--output", output, file).Output()
if err != nil {
return fmt.Errorf("Failed signing file: %w", err)
return fmt.Errorf("failed signing file: %w", err)
}
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ var (
NotOkSym = "✘"
WarnSym = "‼"
UnkwnSym = "⁇"
ErrSym = "⁇"
)
var (
OkSymText = "[+]"
NotOkSymText = "[-]"
WarnSymText = "[!]"
UnkwnSymText = "[?]"
ErrSymText = "[?]"
)

var (
ok string
notok string
err string
warn string
unkwn string
)
Expand Down Expand Up @@ -109,14 +106,12 @@ func init() {
if ok := os.Getenv("EFIBOOTCTL_UNICODE"); ok == "0" {
OkSym = OkSymText
NotOkSym = NotOkSymText
ErrSym = ErrSymText
WarnSym = WarnSymText
UnkwnSym = UnkwnSymText
}

ok = color.New(color.FgGreen, color.Bold).Sprintf(OkSym)
notok = color.New(color.FgRed, color.Bold).Sprintf(NotOkSym)
err = color.New(color.FgRed, color.Bold).Sprintf(ErrSym)
warn = color.New(color.FgYellow, color.Bold).Sprintf(WarnSym)
unkwn = color.New(color.FgRed, color.Bold).Sprintf(UnkwnSym)
PrintOn()
Expand Down
16 changes: 8 additions & 8 deletions sbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func Sign(file, output string, enroll bool) error {

files, err := ReadFileDatabase(DBPath)
if err != nil {
return fmt.Errorf("Couldn't open database: %s", DBPath)
return fmt.Errorf("couldn't open database: %s", DBPath)
}
if entry, ok := files[file]; ok {
err = SignFile(DBKey, DBCert, entry.File, entry.OutputFile, entry.Checksum)
Expand Down Expand Up @@ -224,14 +224,14 @@ var efivarFSFiles = []string{
"/sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f",
}

var ErrImmutable = errors.New("You need to chattr -i files in efivarfs")
var ErrImmutable = errors.New("you need to chattr -i files in efivarfs")

func SyncKeys() error {
errImmuable := false
for _, file := range efivarFSFiles {
b, err := IsImmutable(file)
if err != nil {
return fmt.Errorf("Couldn't read file: %s", file)
return fmt.Errorf("couldn't read file: %s", file)
}
if !b {
logging.Warn("File is immutable: %s", file)
Expand All @@ -243,7 +243,7 @@ func SyncKeys() error {
}
synced := SBKeySync(KeysPath)
if !synced {
return errors.New("Couldn't sync keys")
return errors.New("couldn't sync keys")
} else {
logging.Ok("Synced keys!")
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func CreateBundle(bundle Bundle) error {
logging.Warn(err.Error())
}
if !out {
return fmt.Errorf("failed to generate bundle %s!", bundle.Output)
return fmt.Errorf("failed to generate bundle %s", bundle.Output)
}

return nil
Expand All @@ -311,7 +311,7 @@ func GenerateAllBundles(sign bool) error {
logging.Println("Generating EFI bundles....")
bundles, err := ReadBundleDatabase(BundleDBPath)
if err != nil {
return fmt.Errorf("Couldn't open database: %s", BundleDBPath)
return fmt.Errorf("couldn't open database: %s", BundleDBPath)
}
out_create := true
out_sign := true
Expand All @@ -332,11 +332,11 @@ func GenerateAllBundles(sign bool) error {
}

if !out_create {
return errors.New("Error generating EFI bundles")
return errors.New("error generating EFI bundles")
}

if !out_sign {
return errors.New("Error signing EFI bundles")
return errors.New("error signing EFI bundles")
}

return nil
Expand Down