Compare commits
5 Commits
fad0eb755a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6c539bc29 | ||
|
|
5d7a257b1f | ||
|
|
94723719fe | ||
|
|
bee2165ddd | ||
|
|
d050d58e92 |
50
main.go
50
main.go
@@ -3,6 +3,7 @@ package Podman
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -49,6 +50,10 @@ func Setup(uid int) error {
|
|||||||
return fmt.Errorf("unable to set owner for %s: %w", rundir, err)
|
return fmt.Errorf("unable to set owner for %s: %w", rundir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// catatonit needs /var/tmp for the pause container
|
||||||
|
if err := os.MkdirAll("/var/tmp", 0o777); err != nil {
|
||||||
|
fmt.Errorf("unable to create '/var/tmp': %w", err)
|
||||||
|
}
|
||||||
err = os.Chmod("/var/tmp", 0o1777)
|
err = os.Chmod("/var/tmp", 0o1777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to set perms for /var/tmp: %w", err)
|
return fmt.Errorf("unable to set perms for /var/tmp: %w", err)
|
||||||
@@ -69,11 +74,34 @@ func Setup(uid int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to set perms for /dev/net/tun: %w", err)
|
return fmt.Errorf("unable to set perms for /dev/net/tun: %w", err)
|
||||||
}
|
}
|
||||||
|
if err := MakeWritable("/etc/containers/networks/"); err != nil {
|
||||||
|
return fmt.Errorf("unable to make writeable for /etc/containers/networks/: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll("/var/lib/containers/storage/volumes", 0o777); err != nil {
|
||||||
|
return fmt.Errorf("unable to create /var/lib/containers/storage/volumes: %w", err)
|
||||||
|
}
|
||||||
|
// podman default socket location is /run/podman/podman.sock
|
||||||
|
if err := os.MkdirAll("/run/podman/", 0o770); err != nil {
|
||||||
|
return fmt.Errorf("unable to create /run/podman/: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink("/proc/self/fd/0", "/dev/stdin"); err != nil && !errors.Is(err, fs.ErrExist) {
|
||||||
|
return fmt.Errorf("unable to make /dev/stdin symlink: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink("/proc/self/fd/1", "/dev/stdout"); err != nil && !errors.Is(err, fs.ErrExist) {
|
||||||
|
return fmt.Errorf("unable to make /dev/stdout symlink: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink("/proc/self/fd/2", "/dev/stderr"); err != nil && !errors.Is(err, fs.ErrExist) {
|
||||||
|
return fmt.Errorf("unable to make /dev/stderr symlink: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(args ...string) error {
|
func Run(command string, args ...string) error {
|
||||||
podman := exec.Command("/user/podman", args...)
|
if command == "" {
|
||||||
|
command = "/user/podman"
|
||||||
|
}
|
||||||
|
podman := exec.Command(command, args...)
|
||||||
podman.Env = append(os.Environ(), "TMPDIR=/tmp")
|
podman.Env = append(os.Environ(), "TMPDIR=/tmp")
|
||||||
podman.Stdin = os.Stdin
|
podman.Stdin = os.Stdin
|
||||||
podman.Stdout = os.Stdout
|
podman.Stdout = os.Stdout
|
||||||
@@ -95,8 +123,11 @@ func Run(args ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(args ...string) (chan os.Signal, *exec.Cmd, error) {
|
func Start(command string, args ...string) (chan os.Signal, *exec.Cmd, error) {
|
||||||
podman := exec.Command("/user/podman", args...)
|
if command == "" {
|
||||||
|
command = "/user/podman"
|
||||||
|
}
|
||||||
|
podman := exec.Command(command, args...)
|
||||||
podman.Env = append(os.Environ(), "TMPDIR=/tmp")
|
podman.Env = append(os.Environ(), "TMPDIR=/tmp")
|
||||||
podman.Stdin = os.Stdin
|
podman.Stdin = os.Stdin
|
||||||
podman.Stdout = os.Stdout
|
podman.Stdout = os.Stdout
|
||||||
@@ -117,6 +148,17 @@ func Start(args ...string) (chan os.Signal, *exec.Cmd, error) {
|
|||||||
return exit, podman, nil
|
return exit, podman, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Devices(devices ...string) []string {
|
||||||
|
devs := []string{}
|
||||||
|
for _, dev := range devices {
|
||||||
|
_, err := os.Stat("/dev/" + dev)
|
||||||
|
if err == nil {
|
||||||
|
devs = append(devs, "--device=/dev/"+dev)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return devs
|
||||||
|
}
|
||||||
|
|
||||||
func BindRO(src, dst string) string {
|
func BindRO(src, dst string) string {
|
||||||
return fmt.Sprintf(`--mount=type=bind,source=%s,destination=%s,ro=true`, src, dst)
|
return fmt.Sprintf(`--mount=type=bind,source=%s,destination=%s,ro=true`, src, dst)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if os.Getenv("GOKRAZY_FIRST_START") == "1" {
|
if os.Getenv("GOKRAZY_FIRST_START") == "1" {
|
||||||
subidContent, err := Podman.GetSubids("/etc/subgid")
|
subidContent, err := Podman.GetSubids("/etc/passwd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to generate /etc/subgid successfully, podman will probably not work: %s", err)
|
log.Printf("Unable to generate /etc/subgid successfully, podman will probably not work: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if os.Getenv("GOKRAZY_FIRST_START") == "1" {
|
if os.Getenv("GOKRAZY_FIRST_START") == "1" {
|
||||||
subidContent, err := Podman.GetSubids("/etc/subuid")
|
subidContent, err := Podman.GetSubids("/etc/passwd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to generate /etc/subuid successfully, podman will probably not work: %s", err)
|
log.Printf("Unable to generate /etc/subuid successfully, podman will probably not work: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"/user/podman", "system", "--log-level=debug", "service", "--time=0", "unix:///run/podman.sock",
|
"/user/podman", "system", "--log-level=debug", "service", "--time=0", "unix:///run/docker.sock",
|
||||||
}
|
}
|
||||||
err := syscall.Exec("/user/podman", args, os.Environ())
|
err := syscall.Exec("/user/podman", args, os.Environ())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user