add deb packagetype source
This commit is contained in:
parent
9b82a2c4e2
commit
71b54c1660
@ -42,6 +42,14 @@ Read the state of an existing resource (URI) and generate a YAML representation
|
|||||||
|
|
||||||
![Import Resource](md-images/import-resource.gif)
|
![Import Resource](md-images/import-resource.gif)
|
||||||
|
|
||||||
|
## Importing resources from different sources
|
||||||
|
|
||||||
|
JX supports importing resources data from various source types, among these are filesystem directories, tar archive contents, containers, iptables chains, installed packages, etc.
|
||||||
|
|
||||||
|
Import system packages using the debian package type, and output the resource documents in JSON format.
|
||||||
|
|
||||||
|
`jx import --output json:// package://?type=deb`
|
||||||
|
|
||||||
Import the contents of a tar archive into a resource document.
|
Import the contents of a tar archive into a resource document.
|
||||||
|
|
||||||
`jx import ./test.tgz`
|
`jx import ./test.tgz`
|
||||||
|
@ -305,7 +305,7 @@ func (p *PackageType) NewReadPackagesCommand() (read *command.Command) {
|
|||||||
case PackageTypeApt:
|
case PackageTypeApt:
|
||||||
return NewAptReadPackagesCommand()
|
return NewAptReadPackagesCommand()
|
||||||
case PackageTypeDeb:
|
case PackageTypeDeb:
|
||||||
// return NewDebReadPackagesCommand()
|
return NewDebReadPackagesCommand()
|
||||||
case PackageTypeDnf:
|
case PackageTypeDnf:
|
||||||
// return NewDnfReadPackagesCommand()
|
// return NewDnfReadPackagesCommand()
|
||||||
case PackageTypeRpm:
|
case PackageTypeRpm:
|
||||||
@ -546,6 +546,7 @@ func NewAptReadPackagesCommand() *command.Command {
|
|||||||
p.Name = packageName
|
p.Name = packageName
|
||||||
p.State = "present"
|
p.State = "present"
|
||||||
p.Version = packageVersion
|
p.Version = packageVersion
|
||||||
|
p.PackageType = PackageTypeApt
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -627,6 +628,48 @@ func NewDebDeleteCommand() *command.Command {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewDebReadPackagesCommand() *command.Command {
|
||||||
|
c := command.NewCommand()
|
||||||
|
c.Path = "dpkg-query"
|
||||||
|
c.FailOnError = false
|
||||||
|
c.Split = false
|
||||||
|
c.Args = []command.CommandArg{
|
||||||
|
command.CommandArg("-W"),
|
||||||
|
command.CommandArg("-f"),
|
||||||
|
command.CommandArg("${binary:Package} ${Version} ${Status}\n"),
|
||||||
|
}
|
||||||
|
c.Env = []string{ "DEBIAN_FRONTEND=noninteractive" }
|
||||||
|
c.Extractor = func(out []byte, target any) error {
|
||||||
|
Packages := target.(*[]*Package)
|
||||||
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||||
|
lineIndex := 0
|
||||||
|
for _, line := range lines {
|
||||||
|
installedPackage := strings.Fields(strings.TrimSpace(line))
|
||||||
|
status := strings.Join(installedPackage[2:], " ")
|
||||||
|
if status == "install ok installed" {
|
||||||
|
if len(*Packages) <= lineIndex + 1 {
|
||||||
|
*Packages = append(*Packages, NewPackage())
|
||||||
|
}
|
||||||
|
p := (*Packages)[lineIndex]
|
||||||
|
packageNameFields := strings.Split(installedPackage[0], ":")
|
||||||
|
packageName := packageNameFields[0]
|
||||||
|
packageVersionFields := strings.Split(installedPackage[1], ":")
|
||||||
|
if len(packageVersionFields) > 1 {
|
||||||
|
p.Version = packageVersionFields[1]
|
||||||
|
} else {
|
||||||
|
p.Version = packageVersionFields[0]
|
||||||
|
}
|
||||||
|
p.Name = packageName
|
||||||
|
p.State = "present"
|
||||||
|
p.PackageType = PackageTypeDeb
|
||||||
|
lineIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
func NewDnfCreateCommand() *command.Command {
|
func NewDnfCreateCommand() *command.Command {
|
||||||
c := command.NewCommand()
|
c := command.NewCommand()
|
||||||
c.Path = "dnf"
|
c.Path = "dnf"
|
||||||
@ -706,7 +749,7 @@ func NewRpmCreateCommand() *command.Command {
|
|||||||
c.Split = false
|
c.Split = false
|
||||||
c.Args = []command.CommandArg{
|
c.Args = []command.CommandArg{
|
||||||
command.CommandArg("-i"),
|
command.CommandArg("-i"),
|
||||||
command.CommandArg("{{ .Name }}"),
|
command.CommandArg("{{ .Source }}"),
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@ -747,7 +790,7 @@ func NewRpmUpdateCommand() *command.Command {
|
|||||||
c.Path = "rpm"
|
c.Path = "rpm"
|
||||||
c.Args = []command.CommandArg{
|
c.Args = []command.CommandArg{
|
||||||
command.CommandArg("-i"),
|
command.CommandArg("-i"),
|
||||||
command.CommandArg("{{ .Name }}"),
|
command.CommandArg("{{ .Source }}"),
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ func NewPackage() *Package {
|
|||||||
func init() {
|
func init() {
|
||||||
SourceTypes.Register([]string{"package"}, func(u *url.URL) DocSource {
|
SourceTypes.Register([]string{"package"}, func(u *url.URL) DocSource {
|
||||||
p := NewPackage()
|
p := NewPackage()
|
||||||
|
p.PackageType = resource.PackageType(u.Query().Get("type"))
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user