forked from lhcb-org/lbpkr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_install.go
88 lines (77 loc) · 1.89 KB
/
cmd_install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"regexp"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func lbpkr_make_cmd_install() *commander.Command {
cmd := &commander.Command{
Run: lbpkr_run_cmd_install,
UsageLine: "install [options] <rpmname> [<version> [<release>]]",
Short: "install a RPM from the yum repository",
Long: `
install installs a RPM from the yum repository.
ex:
$ lbpkr install LHCb
`,
Flag: *flag.NewFlagSet("lbpkr-install", flag.ExitOnError),
}
add_default_options(cmd)
cmd.Flag.Bool("force", false, "force RPM installation (by-passing any check)")
return cmd
}
func lbpkr_run_cmd_install(cmd *commander.Command, args []string) error {
var err error
siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
cfgtype := cmd.Flag.Lookup("type").Value.Get().(string)
debug := cmd.Flag.Lookup("v").Value.Get().(bool)
force := cmd.Flag.Lookup("force").Value.Get().(bool)
rpmname := ""
version := ""
release := ""
switch len(args) {
case 0:
cmd.Usage()
return fmt.Errorf("lbpkr: invalid number of arguments (got=%d)", len(args))
case 1:
rpmname = args[0]
case 2:
rpmname = args[0]
version = args[1]
case 3:
rpmname = args[0]
version = args[1]
release = args[2]
default:
return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1|2|3. got=%d (%v)",
len(args),
args,
)
}
re := regexp.MustCompile(`(.*)-([\d\.]+)-(\d)$`).FindAllStringSubmatch(rpmname, -1)
if len(re) == 1 {
m := re[0]
switch len(m) {
case 2:
rpmname = m[1]
case 3:
rpmname = m[1]
version = m[2]
case 4:
rpmname = m[1]
version = m[2]
release = m[3]
}
}
cfg := NewConfig(cfgtype, siteroot)
ctx, err := New(cfg, debug)
if err != nil {
return err
}
defer ctx.Close()
ctx.msg.Infof("installing RPM %s %s %s\n", rpmname, version, release)
update := false
err = ctx.InstallRPM(rpmname, version, release, force, update)
return err
}