yay/aur/aur.go

75 lines
1.5 KiB
Go
Raw Normal View History

2016-09-13 03:06:24 +02:00
package aur
import (
"fmt"
2016-10-17 00:02:48 +02:00
2016-11-30 18:55:56 +01:00
"github.com/jguer/yay/pacman"
2017-01-05 17:13:52 +01:00
"github.com/jguer/yay/util"
2016-09-13 03:06:24 +02:00
)
2016-11-30 18:55:56 +01:00
// Install sends system commands to make and install a package from pkgName
func Install(pkg string, flags []string) (err error) {
2016-11-30 18:55:56 +01:00
q, n, err := Info(pkg)
2016-09-13 03:06:24 +02:00
if err != nil {
2016-11-30 18:55:56 +01:00
return
2016-09-13 03:06:24 +02:00
}
2016-11-30 18:55:56 +01:00
if n == 0 {
return fmt.Errorf("Package %s does not exist", pkg)
}
q[0].Install(flags)
2016-11-30 18:55:56 +01:00
return err
2016-09-13 03:06:24 +02:00
}
2016-11-30 18:55:56 +01:00
// Upgrade tries to update every foreign package installed in the system
func Upgrade(flags []string) error {
2016-11-30 18:55:56 +01:00
fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m")
foreign, n, err := pacman.ForeignPackages()
if err != nil || n == 0 {
2016-09-13 03:06:24 +02:00
return err
}
keys := make([]string, len(foreign))
i := 0
for k := range foreign {
keys[i] = k
i++
}
2016-11-30 18:55:56 +01:00
q, _, err := MultiInfo(keys)
if err != nil {
return err
}
2016-11-30 18:55:56 +01:00
outdated := q[:0]
for _, res := range q {
if _, ok := foreign[res.Name]; ok {
2016-11-30 18:55:56 +01:00
// Leaving this here for now, warn about downgrades later
if res.LastModified > foreign[res.Name].Date {
fmt.Printf("\x1b[1m\x1b[32m==>\x1b[33;1m %s: \x1b[0m%s \x1b[33;1m-> \x1b[0m%s\n",
res.Name, foreign[res.Name].Version, res.Version)
outdated = append(outdated, res)
2016-11-30 18:55:56 +01:00
}
}
}
2016-09-13 03:06:24 +02:00
2016-11-30 18:55:56 +01:00
//If there are no outdated packages, don't prompt
if len(outdated) == 0 {
fmt.Println(" there is nothing to do")
return nil
}
2016-09-13 03:06:24 +02:00
2016-11-30 18:55:56 +01:00
// Install updated packages
2017-01-05 17:13:52 +01:00
if !util.ContinueTask("Proceed with upgrade?", "nN") {
return nil
2016-09-13 03:06:24 +02:00
}
2016-11-30 18:55:56 +01:00
for _, pkg := range outdated {
pkg.Install(flags)
2016-09-13 03:06:24 +02:00
}
2016-11-30 18:55:56 +01:00
return nil
2016-09-13 03:06:24 +02:00
}