41 lines
768 B
Go
41 lines
768 B
Go
|
package pkg
|
||
|
|
||
|
import (
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
type Apt struct{}
|
||
|
|
||
|
func (d Apt) Name() string { return "apt-get" }
|
||
|
|
||
|
func (d Apt) Fetch() bool {
|
||
|
_, err := exec.Command(d.Name(), "update").Output()
|
||
|
return err == nil
|
||
|
}
|
||
|
|
||
|
func (d Apt) Upgrade() bool {
|
||
|
_, err := exec.Command(d.Name(), "upgrade").Output()
|
||
|
if err != nil {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
_, err = exec.Command(d.Name(), "dist-upgrade").Output()
|
||
|
if err != nil {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
exec.Command(d.Name(), "autoremove").Run()
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func (d Apt) Install(_pkg string) bool {
|
||
|
_, err := exec.Command(d.Name(), "install", _pkg).Output()
|
||
|
return err == nil
|
||
|
}
|
||
|
|
||
|
func (d Apt) Remove(_pkg string) bool {
|
||
|
_, err := exec.Command(d.Name(), "remove", _pkg).Output()
|
||
|
exec.Command(d.Name(), "autoremove").Run()
|
||
|
return err == nil
|
||
|
}
|