Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9b7c5539a
|
||
|
|
236165bec8
|
||
|
|
4cb0403e08
|
||
|
|
0318a9759b
|
||
|
|
1a93d5d9f3
|
||
|
|
5dc944cf21
|
||
|
|
77a85a4f84
|
||
|
|
43d1ddfeb8
|
||
|
|
db20c70d86
|
@@ -4,8 +4,42 @@ import (
|
|||||||
`io/fs`
|
`io/fs`
|
||||||
`os`
|
`os`
|
||||||
`strings`
|
`strings`
|
||||||
|
|
||||||
|
`honnef.co/go/augeas`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
NewAuger returns an auger.Aug.
|
||||||
|
|
||||||
|
See:
|
||||||
|
https://pkg.go.dev/honnef.co/go/augeas#readme-examples
|
||||||
|
https://pkg.go.dev/honnef.co/go/augeas#New
|
||||||
|
for the `root` and `loadPath` parameters
|
||||||
|
(and, by extension, the `flags` paraemter; note that the `flags`
|
||||||
|
is an auger.AugFlags, not an augeas.Flag!).
|
||||||
|
|
||||||
|
`flags` may be nil.
|
||||||
|
*/
|
||||||
|
func NewAuger(root, loadPath string, flags *AugFlags) (aug *Aug, err error) {
|
||||||
|
|
||||||
|
aug = new(Aug)
|
||||||
|
|
||||||
|
if aug.aug, err = augeas.New(root, loadPath, flags.Eval()); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAugerFromAugeas returns a wrapped auger.Aug from a (honnef.co/go/augeas).Augeas.
|
||||||
|
func NewAugerFromAugeas(orig augeas.Augeas) (aug *Aug) {
|
||||||
|
|
||||||
|
aug = new(Aug)
|
||||||
|
aug.aug = orig
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
AugpathToFspath returns the filesystem path from an Augeas path.
|
AugpathToFspath returns the filesystem path from an Augeas path.
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import (
|
|||||||
// Eval returns an evaluated set of flags.
|
// Eval returns an evaluated set of flags.
|
||||||
func (a *AugFlags) Eval() (augFlags augeas.Flag) {
|
func (a *AugFlags) Eval() (augFlags augeas.Flag) {
|
||||||
|
|
||||||
|
if a == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
augFlags = augeas.None
|
augFlags = augeas.None
|
||||||
|
|
||||||
if a.Backup != nil && *a.Backup {
|
if a.Backup != nil && *a.Backup {
|
||||||
|
|||||||
24
auger/funcs_test.go
Normal file
24
auger/funcs_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package auger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
`honnef.co/go/augeas`
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewAuger(t *testing.T) {
|
||||||
|
|
||||||
|
var aug *Aug
|
||||||
|
var augUnder augeas.Augeas
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if aug, err = NewAuger("/", "", nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
augUnder = aug.aug
|
||||||
|
|
||||||
|
aug = NewAugerFromAugeas(augUnder)
|
||||||
|
|
||||||
|
_ = aug
|
||||||
|
}
|
||||||
5
cryptparse/doc.go
Normal file
5
cryptparse/doc.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/*
|
||||||
|
CRYPTPARSE HAS MOVED.
|
||||||
|
|
||||||
|
It is now its own module: r00t2.io/cryptparse
|
||||||
|
*/
|
||||||
@@ -17,6 +17,34 @@ import (
|
|||||||
`r00t2.io/sysutils/paths`
|
`r00t2.io/sysutils/paths`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
DefEnv operates like Python's .get() method on dicts (maps);
|
||||||
|
if the environment variable specified by key does not exist/is not specified,
|
||||||
|
then the value specified by fallback will be returned instead
|
||||||
|
otherwise key's value is returned.
|
||||||
|
*/
|
||||||
|
func DefEnv(key, fallback string) (value string) {
|
||||||
|
|
||||||
|
var exists bool
|
||||||
|
|
||||||
|
if value, exists = os.LookupEnv(key); !exists {
|
||||||
|
value = fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefEnvBlank is like DefEnv but will ADDITIONALLY/ALSO apply fallback if key is *defined/exists but is an empty string*.
|
||||||
|
func DefEnvBlank(key, fallback string) (value string) {
|
||||||
|
|
||||||
|
value = DefEnv(key, fallback)
|
||||||
|
if value == "" {
|
||||||
|
value = fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetEnvMap returns a map of all environment variables. All values are strings.
|
// GetEnvMap returns a map of all environment variables. All values are strings.
|
||||||
func GetEnvMap() (envVars map[string]string) {
|
func GetEnvMap() (envVars map[string]string) {
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package envs
|
package envs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
15
go.mod
15
go.mod
@@ -1,18 +1,15 @@
|
|||||||
module r00t2.io/sysutils
|
module r00t2.io/sysutils
|
||||||
|
|
||||||
go 1.21
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/g0rbe/go-chattr v1.0.1
|
github.com/g0rbe/go-chattr v1.0.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
golang.org/x/sys v0.19.0
|
golang.org/x/sys v0.26.0
|
||||||
r00t2.io/goutils v1.6.0
|
honnef.co/go/augeas v0.0.0-20161110001225-ca62e35ed6b8
|
||||||
)
|
r00t2.io/goutils v1.7.0
|
||||||
|
r00t2.io/sysutils v1.8.1
|
||||||
require (
|
|
||||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
|
||||||
github.com/godbus/dbus v4.1.0+incompatible // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pending https://github.com/g0rbe/go-chattr/pull/3
|
// Pending https://github.com/g0rbe/go-chattr/pull/3
|
||||||
|
|||||||
24
go.sum
24
go.sum
@@ -1,22 +1,18 @@
|
|||||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
|
|
||||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||||
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/johnnybubonic/go-chattr v0.0.0-20240126141003-459f46177b13 h1:tgEbuE4bNVjaCWWIB1u9lDzGqH/ZdBTg33+4vNW2rjg=
|
github.com/johnnybubonic/go-chattr v0.0.0-20240126141003-459f46177b13 h1:tgEbuE4bNVjaCWWIB1u9lDzGqH/ZdBTg33+4vNW2rjg=
|
||||||
github.com/johnnybubonic/go-chattr v0.0.0-20240126141003-459f46177b13/go.mod h1:yQc6VPJfpDDC1g+W2t47+yYmzBNioax/GLiyJ25/IOs=
|
github.com/johnnybubonic/go-chattr v0.0.0-20240126141003-459f46177b13/go.mod h1:yQc6VPJfpDDC1g+W2t47+yYmzBNioax/GLiyJ25/IOs=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
r00t2.io/goutils v1.4.0 h1:/x/etLpMFv3+j1aPtT7KK2G0uOk+gQkGvXIYBCdjn3E=
|
honnef.co/go/augeas v0.0.0-20161110001225-ca62e35ed6b8 h1:FW42yWB1sGClqswyHIB68wo0+oPrav1IuQ+Tdy8Qp8E=
|
||||||
r00t2.io/goutils v1.4.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
honnef.co/go/augeas v0.0.0-20161110001225-ca62e35ed6b8/go.mod h1:44w9OfBSQ9l3o59rc2w3AnABtE44bmtNnRMNC7z+oKE=
|
||||||
r00t2.io/goutils v1.5.0 h1:haVk+wUK1BAk8f4UFGjy3ov3DwGMauZAOv/XYdb9isQ=
|
r00t2.io/goutils v1.7.0 h1:iQluWlkOyBwOKaK94D5QSnSMYpGKtMb/5WjefmdfHgI=
|
||||||
r00t2.io/goutils v1.5.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
r00t2.io/goutils v1.7.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
||||||
r00t2.io/goutils v1.6.0 h1:oBC6PgBv0y/fdHeCmWgORHpBiU8uWw7IfFQJX5rIuzY=
|
|
||||||
r00t2.io/goutils v1.6.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
|
||||||
r00t2.io/sysutils v1.1.1/go.mod h1:Wlfi1rrJpoKBOjWiYM9rw2FaiZqraD6VpXyiHgoDo/o=
|
r00t2.io/sysutils v1.1.1/go.mod h1:Wlfi1rrJpoKBOjWiYM9rw2FaiZqraD6VpXyiHgoDo/o=
|
||||||
|
r00t2.io/sysutils v1.7.0 h1:zk5IbcbZvq11FoXI/fLvcgyq36lBhPDY6fvC9CunfWE=
|
||||||
|
r00t2.io/sysutils v1.7.0/go.mod h1:Sk/7riJp9fteeW9STkdQ/k22huL1J6r05n6wLh5byHY=
|
||||||
|
|||||||
Reference in New Issue
Block a user