add auto init for apx v2
This commit is contained in:
parent
0ca6c73408
commit
6e36f96357
@ -2,6 +2,10 @@ package alpine
|
|||||||
|
|
||||||
var PackageManager = "apx"
|
var PackageManager = "apx"
|
||||||
|
|
||||||
|
var ContainerSubsystem = "pikman-alpine"
|
||||||
|
|
||||||
|
var ApxSubsystem = "alpine"
|
||||||
|
|
||||||
var Commands = map[string]string{
|
var Commands = map[string]string{
|
||||||
"autoremove": "pikman-alpine autoremove",
|
"autoremove": "pikman-alpine autoremove",
|
||||||
"clean": "pikman-alpine clean",
|
"clean": "pikman-alpine clean",
|
||||||
|
@ -2,6 +2,10 @@ package arch
|
|||||||
|
|
||||||
var PackageManager = "apx"
|
var PackageManager = "apx"
|
||||||
|
|
||||||
|
var ContainerSubsystem = "pikman-arch-linux"
|
||||||
|
|
||||||
|
var ApxSubsystem = "arch-linux"
|
||||||
|
|
||||||
var Commands = map[string]string{
|
var Commands = map[string]string{
|
||||||
"autoremove": "pikman-arch-linux autoremove",
|
"autoremove": "pikman-arch-linux autoremove",
|
||||||
"clean": "pikman-arch-linux clean",
|
"clean": "pikman-arch-linux clean",
|
||||||
|
@ -33,6 +33,26 @@ var packageManagerMap = map[types.OSType]string{
|
|||||||
types.Flatpak: flatpak.PackageManager,
|
types.Flatpak: flatpak.PackageManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var containerSubsystemMap = map[types.OSType]string{
|
||||||
|
types.Arch: arch.ContainerSubsystem,
|
||||||
|
types.Fedora: fedora.ContainerSubsystem,
|
||||||
|
types.Alpine: alpine.ContainerSubsystem,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) ContainerSubsystem() string {
|
||||||
|
return containerSubsystemMap[c.OsType]
|
||||||
|
}
|
||||||
|
|
||||||
|
var apxSubsystemMap = map[types.OSType]string{
|
||||||
|
types.Arch: arch.ApxSubsystem,
|
||||||
|
types.Fedora: fedora.ApxSubsystem,
|
||||||
|
types.Alpine: alpine.ApxSubsystem,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) ApxSubsystem() string {
|
||||||
|
return apxSubsystemMap[c.OsType]
|
||||||
|
}
|
||||||
|
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Command string
|
Command string
|
||||||
OsType types.OSType
|
OsType types.OSType
|
||||||
@ -55,6 +75,53 @@ func (c *Command) processCommand() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.Command != "init" && c.ContainerName == "" {
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", "apx subsystems list | grep ^" + c.ContainerSubsystem() + "$")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error 1")
|
||||||
|
}
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
fmt.Println("Error 2")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error 3")
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
fmt.Println("Warning: Subsystem hasn't been pre-initialized, initializing...")
|
||||||
|
cmd_exec := exec.Command("/bin/bash", "-c", "apx subsystems new -n " + c.ContainerSubsystem() + " -s " + c.ApxSubsystem())
|
||||||
|
cmd_exec.Stdout = os.Stdout
|
||||||
|
if err := cmd_exec.Run(); err != nil {
|
||||||
|
fmt.Println("Apx Error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.Command != "init" && c.ContainerName != "" {
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", "apx subsystems list | grep ^" + c.ContainerName + "$")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error 1")
|
||||||
|
}
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
fmt.Println("Error 2")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error 3")
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
fmt.Println("Warning: Subsystem hasn't been pre-initialized, initializing...")
|
||||||
|
cmd_exec := exec.Command("/bin/bash", "-c", "apx subsystems new -n " + c.ContainerName + " -s " + c.ApxSubsystem())
|
||||||
|
cmd_exec.Stdout = os.Stdout
|
||||||
|
if err := cmd_exec.Run(); err != nil {
|
||||||
|
fmt.Println("Apx Error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.ContainerName != "" {
|
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.ContainerName != "" {
|
||||||
c.PackageName = append([]string{"--name " + c.ContainerName}, c.PackageName...)
|
c.PackageName = append([]string{"--name " + c.ContainerName}, c.PackageName...)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@ package fedora
|
|||||||
|
|
||||||
var PackageManager = "apx"
|
var PackageManager = "apx"
|
||||||
|
|
||||||
|
var ContainerSubsystem = "pikman-fedora-workstation"
|
||||||
|
|
||||||
|
var ApxSubsystem = "fedora-workstation"
|
||||||
|
|
||||||
var Commands = map[string]string{
|
var Commands = map[string]string{
|
||||||
"autoremove": "pikman-fedora-workstation autoremove",
|
"autoremove": "pikman-fedora-workstation autoremove",
|
||||||
"clean": "pikman-fedora-workstation clean",
|
"clean": "pikman-fedora-workstation clean",
|
||||||
|
Loading…
Reference in New Issue
Block a user