2016-09-05 02:17:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2016-10-05 16:04:16 +00:00
|
|
|
var version string
|
|
|
|
|
2016-09-13 01:06:24 +00:00
|
|
|
// PacmanConf describes the default pacman config file
|
|
|
|
const PacmanConf string = "/etc/pacman.conf"
|
2016-09-06 21:22:20 +00:00
|
|
|
|
2016-09-05 22:47:36 +00:00
|
|
|
// BuildDir is the root for package building
|
2016-09-06 21:22:20 +00:00
|
|
|
const BuildDir string = "/tmp/yaytmp/"
|
2016-09-05 22:47:36 +00:00
|
|
|
|
2016-09-18 01:32:13 +00:00
|
|
|
// SearchMode is search without numbers.
|
|
|
|
const SearchMode int = -1
|
|
|
|
|
|
|
|
func operation() (operation string, err error) {
|
|
|
|
if len(os.Args) < 2 {
|
2016-10-05 16:04:16 +00:00
|
|
|
return "noop", fmt.Errorf("No operation specified.")
|
2016-09-18 01:32:13 +00:00
|
|
|
}
|
|
|
|
for _, arg := range os.Args[1:] {
|
|
|
|
if arg[0] == '-' && arg[1] != '-' {
|
|
|
|
return arg, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "yogurt", nil
|
|
|
|
}
|
|
|
|
|
2016-10-02 20:50:23 +00:00
|
|
|
func packages() ([]string, error) {
|
2016-09-18 01:32:13 +00:00
|
|
|
var ps []string
|
|
|
|
for _, arg := range os.Args[1:] {
|
|
|
|
if arg[0] != '-' {
|
|
|
|
ps = append(ps, arg)
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 20:50:23 +00:00
|
|
|
return ps, nil
|
2016-09-18 01:32:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:04:16 +00:00
|
|
|
func flags() (fs []string, err error) {
|
2016-09-18 01:32:13 +00:00
|
|
|
for _, arg := range os.Args[1:] {
|
|
|
|
if arg[0] == '-' && arg[1] == '-' {
|
|
|
|
fs = append(fs, arg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-05 02:17:51 +00:00
|
|
|
func main() {
|
2016-09-09 13:55:16 +00:00
|
|
|
var err error
|
2016-09-13 01:06:24 +00:00
|
|
|
conf, err := readConfig(PacmanConf)
|
|
|
|
|
2016-09-18 01:32:13 +00:00
|
|
|
op, err := operation()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2016-10-02 20:50:23 +00:00
|
|
|
pkgs, _ := packages()
|
2016-09-18 01:32:13 +00:00
|
|
|
|
|
|
|
flag, _ := flags()
|
2016-09-10 23:02:53 +00:00
|
|
|
|
2016-09-18 01:32:13 +00:00
|
|
|
switch op {
|
2016-10-05 16:04:16 +00:00
|
|
|
case "-Qstats":
|
|
|
|
err = stats(&conf)
|
2016-09-18 01:32:13 +00:00
|
|
|
case "-Ss":
|
2016-10-02 20:50:23 +00:00
|
|
|
for _, pkg := range pkgs {
|
|
|
|
err = searchMode(pkg, &conf)
|
|
|
|
}
|
2016-09-18 01:32:13 +00:00
|
|
|
case "-S":
|
2016-10-02 20:50:23 +00:00
|
|
|
err = InstallPackage(pkgs, &conf, flag)
|
2016-10-02 16:23:55 +00:00
|
|
|
case "-Syu":
|
|
|
|
err = updateAndInstall(&conf, flag)
|
2016-09-18 01:32:13 +00:00
|
|
|
case "yogurt":
|
2016-10-02 20:50:23 +00:00
|
|
|
for _, pkg := range pkgs {
|
|
|
|
err = searchAndInstall(pkg, &conf, flag)
|
|
|
|
}
|
2016-09-18 01:32:13 +00:00
|
|
|
default:
|
2016-10-05 16:04:16 +00:00
|
|
|
err = passToPacman(op, pkgs, flag)
|
2016-09-09 13:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 09:10:04 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-09-05 02:17:51 +00:00
|
|
|
}
|