~whynothugo/sb-backup

711c4c7dfaf692560171aad18369651d256d433a — Hugo Osvaldo Barrera 6 months ago 644f9ed
Update to latest go-uefi
3 files changed, 22 insertions(+), 8 deletions(-)

M go.mod
M go.sum
M main.go
M go.mod => go.mod +2 -2
@@ 3,7 3,7 @@ module git.sr.ht/~whynothugo/sb-backup
go 1.16

require (
	github.com/foxboron/go-uefi v0.0.0-20210516000019-39e60f7f752f // indirect
	github.com/foxboron/sbctl v0.0.0-20210522162249-d7e4f3b603ec // indirect
	github.com/foxboron/go-uefi v0.0.0-20210516142507-9c8826a9394d // indirect
	github.com/foxboron/sbctl v0.0.0-20210522214850-7eb70e2ee94b // indirect
	golang.org/x/text v0.3.6 // indirect
)

M go.sum => go.sum +12 -0
@@ 18,12 18,18 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fatih/color v1.11.0 h1:l4iX0RqNnx/pU7rY2DB/I+znuYY0K3x6Ywac6EIr0PA=
github.com/fatih/color v1.11.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/foxboron/go-uefi v0.0.0-20210105211851-5faf8e43ee9b/go.mod h1:lP2qQFTFX3752ZHhqwp0U+A0d6oRHZEBn06+mMssM/g=
github.com/foxboron/go-uefi v0.0.0-20210516000019-39e60f7f752f h1:Dcv48nPs7dTkzP5EszjR76zZWKv4yyg/LSy0Xac8Nag=
github.com/foxboron/go-uefi v0.0.0-20210516000019-39e60f7f752f/go.mod h1:XNONgjPFFVVcYAMAXvW06XCHZqdaXeCGqeS7o19LbN0=
github.com/foxboron/go-uefi v0.0.0-20210516142507-9c8826a9394d h1:LU/3f+RnsNDzvAZuwKVyoL9fiwPlkrXcQj+LquXesNI=
github.com/foxboron/go-uefi v0.0.0-20210516142507-9c8826a9394d/go.mod h1:XNONgjPFFVVcYAMAXvW06XCHZqdaXeCGqeS7o19LbN0=
github.com/foxboron/pkcs7 v0.0.0-20200515184129-2907ba0539a4/go.mod h1:px0/6X5Ap1wlLCWQ1DmiBULqyLBpoiXpUm0Vce+ufSk=
github.com/foxboron/sbctl v0.0.0-20210522162249-d7e4f3b603ec h1:dImZ9GhfNUitgrYZ1ssMIl5c4Sj8tAqh9or+3eO51QI=
github.com/foxboron/sbctl v0.0.0-20210522162249-d7e4f3b603ec/go.mod h1:W+9tK4YWoVlof225+xUjPntfWolUmJ6kdFjuBOSNJmY=
github.com/foxboron/sbctl v0.0.0-20210522214850-7eb70e2ee94b h1:rDEPC/j9EQn/N1EufpnxHjH7SxaLvcku/oXrMfdAYlE=
github.com/foxboron/sbctl v0.0.0-20210522214850-7eb70e2ee94b/go.mod h1:zZH5PxarMArcbjeDUhnpbQDRlgToOay+HBgyue7enk4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=


@@ 57,6 63,10 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=


@@ 120,6 130,8 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201109165425-215b40eba54c h1:+B+zPA6081G5cEb2triOIJpcvSW4AYzmIyWAqMn2JAc=
golang.org/x/sys v0.0.0-20201109165425-215b40eba54c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

M main.go => main.go +8 -6
@@ 1,9 1,9 @@
package main

import (
	"bytes"
	"fmt"
	"io"
	"bytes"
	"os"
	"path"
	"strings"


@@ 48,24 48,26 @@ func GenerateBackupFilename(original string) string {
}

// Parse an efivar as a UTF-16 string.
func ParseUtf16Var(data []byte) (string, error) {
func ParseUtf16Var(data *bytes.Buffer) (string, error) {
	utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
	name, _, err := transform.Bytes(utf16.NewDecoder(), data)
	utf16Reader := transform.NewReader(data, utf16.NewDecoder())
	b, err := io.ReadAll(utf16Reader)

	if err != nil {
		return "", err
	}

	return string(bytes.Trim(name, "\x00")), nil
	return string(bytes.Trim(b, "\x00")), nil
}

// Return the boot entry which is currently booted.
func GetCurrentlyBootedEntry() (string, error) {
	entry, err := attributes.ReadEfivarsFile("/sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f")
	_, data, err := attributes.ReadEfivarsFile("/sys/firmware/efi/efivars/LoaderEntrySelected-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f")
	if err != nil {
		return "", err
	}

	name, err := ParseUtf16Var(entry.Data)
	name, err := ParseUtf16Var(data)
	if err != nil {
		return "", err
	}