diff --git a/cmd/control/cli.go b/cmd/control/cli.go new file mode 100644 index 00000000..68f182c0 --- /dev/null +++ b/cmd/control/cli.go @@ -0,0 +1,66 @@ +package control + +import ( + "os" + + "github.com/codegangsta/cli" + "github.com/rancherio/os/config" +) + +func Main() { + app := cli.NewApp() + + app.Name = os.Args[0] + app.Usage = "Control and configure RancherOS" + app.Version = config.VERSION + app.Author = "Rancher Labs, Inc." + app.Email = "darren@rancher.com" + + app.Commands = []cli.Command{ + { + Name: "config", + ShortName: "c", + Usage: "configure settings", + Subcommands: configSubcommands(), + }, + { + Name: "module", + ShortName: "m", + Usage: "module settings", + Subcommands: []cli.Command{ + { + Name: "activate", + Usage: "turn on a module and possibly reboot", + }, + { + Name: "deactivate", + Usage: "turn off a module and possibly reboot", + }, + { + Name: "list", + Usage: "list modules and state", + }, + }, + }, + { + Name: "os", + Usage: "operating system upgrade/downgrade", + Subcommands: []cli.Command{ + { + Name: "list", + Usage: "list available RancherOS versions and state", + }, + { + Name: "update", + Usage: "download the latest new version of RancherOS", + }, + { + Name: "activate", + Usage: "switch to a new version of RancherOS and reboot", + }, + }, + }, + } + + app.Run(os.Args) +} diff --git a/cmd/control/config.go b/cmd/control/config.go new file mode 100644 index 00000000..1d50a797 --- /dev/null +++ b/cmd/control/config.go @@ -0,0 +1,71 @@ +package control + +import ( + "fmt" + "io/ioutil" + + log "github.com/Sirupsen/logrus" + + "github.com/codegangsta/cli" + "github.com/rancherio/os/config" + "github.com/rancherio/os/docker" +) + +func configSubcommands() []cli.Command { + return []cli.Command{ + { + Name: "get", + Usage: "get value", + }, + { + Name: "import", + Usage: "list values", + }, + { + Name: "export", + Usage: "dump full configuration", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "output, o", + Usage: "File to which to save", + }, + cli.BoolFlag{ + Name: "full", + Usage: "Include full configuration, not just writable fields", + }, + }, + Action: configSave, + }, + } +} + +func configSave(c *cli.Context) { + cfg, err := config.LoadConfig() + if err != nil { + log.Fatal(err) + } + + for _, c := range cfg.SystemContainers { + container := docker.NewContainer("", &c) + if container.Err != nil { + log.Fatalf("Failed to parse [%s] : %v", c.Cmd, container.Err) + } + } + + if !c.Bool("full") { + cfg.ClearReadOnly() + } + + content, err := cfg.Dump() + + output := c.String("output") + if output == "" { + fmt.Println(content) + } else { + err := ioutil.WriteFile(output, []byte(content), 0400) + if err != nil { + log.Fatal(err) + } + } + +}