Merge pull request #4 from PikaOS-Linux/auto-init-apx2
add auto init for apx v2
This commit is contained in:
commit
2ef0ef6d82
@ -2,6 +2,10 @@ package alpine
|
||||
|
||||
var PackageManager = "apx"
|
||||
|
||||
var ContainerSubsystem = "pikman-alpine"
|
||||
|
||||
var ApxSubsystem = "alpine"
|
||||
|
||||
var Commands = map[string]string{
|
||||
"autoremove": "pikman-alpine autoremove",
|
||||
"clean": "pikman-alpine clean",
|
||||
|
@ -2,6 +2,10 @@ package arch
|
||||
|
||||
var PackageManager = "apx"
|
||||
|
||||
var ContainerSubsystem = "pikman-arch-linux"
|
||||
|
||||
var ApxSubsystem = "arch-linux"
|
||||
|
||||
var Commands = map[string]string{
|
||||
"autoremove": "pikman-arch-linux autoremove",
|
||||
"clean": "pikman-arch-linux clean",
|
||||
|
@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -33,6 +34,26 @@ var packageManagerMap = map[types.OSType]string{
|
||||
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 {
|
||||
Command string
|
||||
OsType types.OSType
|
||||
@ -55,6 +76,14 @@ func (c *Command) processCommand() error {
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.Command != "init" {
|
||||
err = c.initContainer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if c.OsType != types.Ubuntu && c.OsType != types.Flatpak && c.ContainerName != "" {
|
||||
c.PackageName = append([]string{"--name " + c.ContainerName}, c.PackageName...)
|
||||
}
|
||||
@ -103,3 +132,47 @@ func (c *Command) runUpgrades() error {
|
||||
|
||||
return updates.GetFlatpakUpdates(c.IsJSON)
|
||||
}
|
||||
|
||||
func (c *Command) initContainer() error {
|
||||
contName := c.ContainerName
|
||||
if contName == "" {
|
||||
contName = c.ContainerSubsystem()
|
||||
}
|
||||
|
||||
cmd := exec.Command("/bin/bash", "-c", "apx subsystems list -j")
|
||||
outb, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var out []apxSubs
|
||||
err = json.Unmarshal(outb, &out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isMatch := false
|
||||
for _, sub := range out {
|
||||
if sub.Name == contName {
|
||||
isMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !isMatch {
|
||||
fmt.Println("Warning: Subsystem hasn't been pre-initialized, initializing...")
|
||||
cmd_exec := exec.Command("/bin/bash", "-c", "apx subsystems new -n "+contName+" -s "+c.ApxSubsystem())
|
||||
cmd_exec.Stdout = os.Stdout
|
||||
cmd_exec.Stdin = os.Stdin
|
||||
cmd_exec.Stderr = os.Stderr
|
||||
if err := cmd_exec.Run(); err != nil {
|
||||
fmt.Println("Apx Error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type apxSubs struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,3 +1,9 @@
|
||||
pikman (1.25.0.0.3-99pika2.lunar) lunar; urgency=low
|
||||
|
||||
* APX container init if needed
|
||||
|
||||
-- Ward Nakchbandi <hotrod.master@hotmail.com> Sat, 10 Dec 2022 13:48:00 +0300
|
||||
|
||||
pikman (1.24.0.0.3-99pika2.lunar) lunar; urgency=low
|
||||
|
||||
* Nala -> apt until nala-rs is out
|
||||
|
@ -2,6 +2,10 @@ package fedora
|
||||
|
||||
var PackageManager = "apx"
|
||||
|
||||
var ContainerSubsystem = "pikman-fedora-workstation"
|
||||
|
||||
var ApxSubsystem = "fedora-workstation"
|
||||
|
||||
var Commands = map[string]string{
|
||||
"autoremove": "pikman-fedora-workstation autoremove",
|
||||
"clean": "pikman-fedora-workstation clean",
|
||||
|
Loading…
Reference in New Issue
Block a user