2018-11-07 10:35:04 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
2018-11-18 21:49:11 +00:00
|
|
|
"git.xdrm.io/go/nix-amer/internal/exec"
|
2018-11-07 10:35:04 +00:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
type aptGet struct{ exec exec.Executor }
|
|
|
|
|
|
|
|
func (d *aptGet) SetExecutor(_exec exec.Executor) {
|
|
|
|
d.exec = _exec
|
|
|
|
}
|
2018-11-07 10:35:04 +00:00
|
|
|
|
2018-11-11 00:10:30 +00:00
|
|
|
func (d aptGet) Name() string { return "apt-get" }
|
2018-11-07 10:35:04 +00:00
|
|
|
|
2018-11-11 00:10:30 +00:00
|
|
|
func (d aptGet) Fetch() error {
|
2018-11-11 20:38:16 +00:00
|
|
|
err := d.exec.Command(d.Name(), "update").Run()
|
2018-11-08 11:52:14 +00:00
|
|
|
return err
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 00:10:30 +00:00
|
|
|
func (d aptGet) Upgrade() error {
|
2018-11-11 20:38:16 +00:00
|
|
|
err := d.exec.Command(d.Name(), "upgrade").Run()
|
2018-11-07 10:35:04 +00:00
|
|
|
if err != nil {
|
2018-11-08 11:52:14 +00:00
|
|
|
return err
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
err = d.exec.Command(d.Name(), "dist-upgrade").Run()
|
2018-11-07 10:35:04 +00:00
|
|
|
if err != nil {
|
2018-11-08 11:52:14 +00:00
|
|
|
return err
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
d.exec.Command(d.Name(), "autoremove").Run()
|
2018-11-08 11:52:14 +00:00
|
|
|
return nil
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 00:10:30 +00:00
|
|
|
func (d aptGet) Install(_pkg string) error {
|
2018-11-11 20:38:16 +00:00
|
|
|
err := d.exec.Command(d.Name(), "install", _pkg).Run()
|
2018-11-08 11:52:14 +00:00
|
|
|
return err
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 00:10:30 +00:00
|
|
|
func (d aptGet) Remove(_pkg string) error {
|
2018-11-11 20:38:16 +00:00
|
|
|
err := d.exec.Command(d.Name(), "remove", _pkg).Run()
|
|
|
|
d.exec.Command(d.Name(), "autoremove").Run()
|
2018-11-08 11:52:14 +00:00
|
|
|
return err
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|