diff options
author | Héctor Orón Martínez <zumbi@debian.org> | 2018-01-09 19:12:07 +0100 |
---|---|---|
committer | Héctor Orón Martínez <zumbi@debian.org> | 2018-01-09 19:12:07 +0100 |
commit | 4808cb7058c548bf76476ec2f9618d784d76bdda (patch) | |
tree | 1dc1e8cc24171783fc8d9da306b1e92798960a15 /actions/apt_action.go |
New upstream version 1.0.0+git20171222.87b0d5e
Diffstat (limited to 'actions/apt_action.go')
-rw-r--r-- | actions/apt_action.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/actions/apt_action.go b/actions/apt_action.go new file mode 100644 index 0000000..681c069 --- /dev/null +++ b/actions/apt_action.go @@ -0,0 +1,61 @@ +/* +Apt Action + +Install packages and their dependencies to the target rootfs with 'apt'. + +Yaml syntax: + - action: apt + recommends: bool + packages: + - package1 + - package2 + +Mandatory properties: + +- packages -- list of packages to install + +Optional properties: + +- recommends -- boolean indicating if suggested packages will be installed +*/ +package actions + +import ( + "github.com/go-debos/debos" +) + +type AptAction struct { + debos.BaseAction `yaml:",inline"` + Recommends bool + Packages []string +} + +func (apt *AptAction) Run(context *debos.DebosContext) error { + apt.LogStart() + aptOptions := []string{"apt-get", "-y"} + + if !apt.Recommends { + aptOptions = append(aptOptions, "--no-install-recommends") + } + + aptOptions = append(aptOptions, "install") + aptOptions = append(aptOptions, apt.Packages...) + + c := debos.NewChrootCommandForContext(*context) + c.AddEnv("DEBIAN_FRONTEND=noninteractive") + + err := c.Run("apt", "apt-get", "update") + if err != nil { + return err + } + err = c.Run("apt", aptOptions...) + if err != nil { + return err + } + err = c.Run("apt", "apt-get", "clean") + if err != nil { + return err + } + + return nil +} |