@@ -3,20 +3,8 @@ package containerd
3
3
import (
4
4
"fmt"
5
5
"log/slog"
6
- "os"
7
- "os/exec"
8
6
)
9
7
10
- // UsesSystemd checks if the system is using systemd.
11
- func UsesSystemd () bool {
12
- cmd := nsenterCmd ("systemctl" , "list-units" , "|" , "grep" , "-q" , "containerd.service" )
13
- if err := cmd .Run (); err != nil {
14
- slog .Info ("Error with systemctl: %w\n " , "error" , err )
15
- return false
16
- }
17
- return true
18
- }
19
-
20
8
// InstallDbus checks if D-Bus service is installed and active. If not, installs D-Bus
21
9
// and starts the service.
22
10
// NOTE: this limits support to systems using systemctl to manage systemd.
@@ -31,18 +19,24 @@ func InstallDbus() error {
31
19
type pkgManager struct {
32
20
name string
33
21
check []string
22
+ update []string
34
23
install []string
35
24
}
36
25
37
26
managers := []pkgManager {
38
- {"apt-get" , []string {"which" , "apt-get" }, []string {"apt-get" , "update" , "--yes" , "&&" , "apt-get" , "install" , "--yes" , "dbus" }},
39
- {"dnf" , []string {"which" , "dnf" }, []string {"dnf" , "install" , "--yes" , "dbus" }},
40
- {"apk" , []string {"which" , "apk" }, []string {"apk" , "add" , "dbus" }},
41
- {"yum" , []string {"which" , "yum" }, []string {"yum" , "install" , "--yes" , "dbus" }},
27
+ {"apt-get" , []string {"which" , "apt-get" }, []string {"apt-get" , "update" , "--yes" }, [] string { "apt-get" , "install" , "--yes" , "dbus" }},
28
+ {"dnf" , []string {"which" , "dnf" }, []string {}, [] string { "dnf" , "install" , "--yes" , "dbus" }},
29
+ {"apk" , []string {"which" , "apk" }, []string {}, [] string { "apk" , "add" , "dbus" }},
30
+ {"yum" , []string {"which" , "yum" }, []string {}, [] string { "yum" , "install" , "--yes" , "dbus" }},
42
31
}
43
32
installed := false
44
33
for _ , mgr := range managers {
45
34
if err := nsenterCmd (mgr .check ... ).Run (); err == nil {
35
+ if len (mgr .update ) != 0 {
36
+ if err := nsenterCmd (mgr .update ... ).Run (); err != nil {
37
+ return fmt .Errorf ("failed to update package manager %s: %w" , mgr .name , err )
38
+ }
39
+ }
46
40
if err := nsenterCmd (mgr .install ... ).Run (); err != nil {
47
41
return fmt .Errorf ("failed to install D-Bus with %s: %w" , mgr .name , err )
48
42
}
@@ -63,8 +57,3 @@ func InstallDbus() error {
63
57
64
58
return nil
65
59
}
66
-
67
- func nsenterCmd (cmd ... string ) * exec.Cmd {
68
- return exec .Command ("nsenter" ,
69
- append ([]string {fmt .Sprintf ("-m/%s/proc/1/ns/mnt" , os .Getenv ("HOST_ROOT" )), "--" }, cmd ... )... ) // #nosec G204
70
- }
0 commit comments