func (x *cmdShell) Execute(args []string) error { shellType := x.Positional.ShellType if shellType == "classic" { if !classic.Enabled() { return fmt.Errorf(i18n.G(`Classic dimension disabled on this system. Use "sudo snappy enable-classic" to enable it.`)) } // we need to re-exec if we do not run as root if os.Getuid() != 0 { if err := reexecWithSudo(); err != nil { return err } } fmt.Println(i18n.G(`Entering classic dimension`)) fmt.Println(i18n.G(` The home directory is shared between snappy and the classic dimension. Run "exit" to leave the classic shell. `)) return classic.RunShell() } return fmt.Errorf(i18n.G("unsupported shell %v"), shellType) }
func (c *cmdChanges) Execute([]string) error { if c.Positional.Id != "" { return c.showChange(c.Positional.Id) } cli := Client() changes, err := cli.Changes(client.ChangesAll) if err != nil { return err } if len(changes) == 0 { return fmt.Errorf(i18n.G("no changes found")) } sort.Sort(changesByTime(changes)) w := tabWriter() fmt.Fprintf(w, i18n.G("ID\tStatus\tSpawn\tReady\tSummary\n")) for _, chg := range changes { spawnTime := chg.SpawnTime.UTC().Format(time.RFC3339) readyTime := chg.ReadyTime.UTC().Format(time.RFC3339) if chg.ReadyTime.IsZero() { readyTime = "-" } fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", chg.ID, chg.Status, spawnTime, readyTime, chg.Summary) } w.Flush() fmt.Fprintln(Stdout) return nil }
func (cmdList) Execute([]string) error { cli := Client() filter := client.SnapFilter{ Sources: []string{"local"}, } snaps, _, err := cli.FilterSnaps(filter) if err != nil { return err } if len(snaps) == 0 { return fmt.Errorf(i18n.G("no snaps found")) } sort.Sort(snapsByName(snaps)) w := tabWriter() defer w.Flush() fmt.Fprintln(w, i18n.G("Name\tVersion\tDeveloper")) for _, snap := range snaps { fmt.Fprintf(w, "%s\t%s\t%s\n", snap.Name, snap.Version, snap.Developer) } return nil }
func (inst *snapInstruction) update() (*state.Change, error) { flags := snappy.DoInstallGC if inst.LeaveOld { flags = 0 } state := inst.overlord.State() state.Lock() msg := fmt.Sprintf(i18n.G("Refresh %q snap"), inst.pkg) if inst.Channel != "stable" && inst.Channel != "" { msg = fmt.Sprintf(i18n.G("Refresh %q snap from %q channel"), inst.pkg, inst.Channel) } chg := state.NewChange("refresh-snap", msg) ts, err := snapstateUpdate(state, inst.pkg, inst.Channel, inst.userID, flags) if err == nil { chg.AddAll(ts) } state.Unlock() if err != nil { return nil, err } state.EnsureBefore(0) return chg, nil }
func outputHWAccessForPkgname(pkgname string, writePaths []string) { if len(writePaths) == 0 { // TRANSLATORS: the %s is a pkgname fmt.Printf(i18n.G("'%s:' is not allowed to access additional hardware\n"), pkgname) } else { // TRANSLATORS: the %s is a pkgname, the second a comma separated list of paths fmt.Printf(i18n.G("%s: %s\n"), pkgname, strings.Join(writePaths, ", ")) } }
func init() { _, err := parser.AddCommand("console", i18n.G("Run snappy console interface"), i18n.G("Run snappy console interface"), &cmdConsole{}) if err != nil { logger.Panicf("Unable to console: %v", err) } }
func init() { arg, err := parser.AddCommand("shell", i18n.G("Run snappy shell interface"), i18n.G("Run snappy shell interface"), &cmdShell{}) if err != nil { logger.Panicf("Unable to add shell command: %q", err) } addOptionDescription(arg, "shell-type", i18n.G("The type of shell you want")) }
func init() { arg, err := parser.AddCommand("remove", i18n.G("Remove a snapp part"), i18n.G("Remove a snapp part"), &cmdRemove{}) if err != nil { logger.Panicf("Unable to remove: %v", err) } addOptionDescription(arg, "no-gc", i18n.G("Do not clean up old versions of the package.")) }
func init() { arg, err := parser.AddCommand("hw-unassign", shortHWUnassignHelp, longHWUnassignHelp, &cmdHWUnassign{}) if err != nil { logger.Panicf("Unable to hwunassign: %v", err) } addOptionDescription(arg, "package name", i18n.G("Remove hardware from a specific installed package")) addOptionDescription(arg, "device path", i18n.G("The hardware device path (e.g. /dev/ttyUSB0)")) }
func init() { arg, err := parser.AddCommand("policygen", i18n.G("Generate the apparmor policy"), i18n.G("Generate the apparmor policy"), &cmdPolicygen{}) if err != nil { logger.Panicf("Unable to install: %v", err) } addOptionDescription(arg, "force", i18n.G("Force policy generation.")) addOptionDescription(arg, "package.yaml path", i18n.G("The path to the package.yaml used to generate the apparmor policy.")) }
func init() { _, err := parser.AddCommand("service", i18n.G("Query and modify snappy services"), i18n.G("Query and modify snappy services of locally-installed packages"), &cmdService{}) if err != nil { logger.Panicf("Unable to service: %v", err) } }
func init() { arg, err := parser.AddCommand("update", i18n.G("Update all installed parts"), i18n.G("Ensures system is running with latest parts"), &cmdUpdate{}) if err != nil { logger.Panicf("Unable to update: %v", err) } addOptionDescription(arg, "no-gc", i18n.G("Do not clean up old versions of the package.")) addOptionDescription(arg, "automatic-reboot", i18n.G("Reboot if necessary to be on the latest running system.")) }
func init() { arg, err := parser.AddCommand("rollback", shortRollbackHelp, longRollbackHelp, &cmdRollback{}) if err != nil { logger.Panicf("Unable to rollback: %v", err) } addOptionDescription(arg, "package name", i18n.G("The package to rollback ")) addOptionDescription(arg, "version", i18n.G("The version to rollback to")) }
func init() { arg, err := parser.AddCommand("config", shortConfigHelp, longConfigHelp, &cmdConfig{}) if err != nil { logger.Panicf("Unable to config: %v", err) } addOptionDescription(arg, "package name", i18n.G("Set configuration for a specific installed package")) addOptionDescription(arg, "config file", i18n.G("The configuration for the given file")) }
func init() { arg, err := parser.AddCommand("info", shortInfoHelp, longInfoHelp, &cmdInfo{}) if err != nil { logger.Panicf("Unable to info: %v", err) } addOptionDescription(arg, "verbose", i18n.G("Provides more detailed information")) addOptionDescription(arg, "include-remote", i18n.G("Include information about packages from the snappy store")) addOptionDescription(arg, "package name", i18n.G("Provide information about a specific installed package")) }
func init() { cmd, err := parser.AddCommand("search", i18n.G("Search for packages to install"), i18n.G("Query the store for available packages"), &cmdSearch{}) if err != nil { logger.Panicf("Unable to search: %v", err) } cmd.Aliases = append(cmd.Aliases, "se") addOptionDescription(cmd, "show-all", i18n.G("Show all available forks of a package")) }
func init() { cmd, err := parser.AddCommand("build", i18n.G("Builds a snap package"), longBuildHelp, &cmdBuild{}) if err != nil { logger.Panicf("Unable to build: %v", err) } cmd.Aliases = append(cmd.Aliases, "bu") addOptionDescription(cmd, "output", i18n.G("Specify an alternate output directory for the resulting package")) }
func (x *cmdDestroyClassic) doDisable() (err error) { if !classic.Enabled() { return fmt.Errorf(i18n.G("Classic dimension is not enabled.")) } if err := classic.Destroy(); err != nil { return err } fmt.Println(i18n.G(`Classic dimension destroyed on this snappy system.`)) return nil }
func init() { cmd, err := parser.AddCommand("list", shortListHelp, longListHelp, &cmdList{}) if err != nil { logger.Panicf("Unable to list: %v", err) } cmd.Aliases = append(cmd.Aliases, "li") addOptionDescription(cmd, "updates", i18n.G("Show available updates (requires network)")) addOptionDescription(cmd, "verbose", i18n.G("Show channel information and expand all fields")) }
func (x *cmdEnableClassic) doEnable() (err error) { if classic.Enabled() { return fmt.Errorf(i18n.G("Classic dimension is already enabled.")) } pbar := progress.NewTextProgress() if err := classic.Create(pbar); err != nil { return err } fmt.Println(i18n.G(`Classic dimension enabled on this snappy system. Use “snappy shell classic” to enter the classic dimension.`)) return nil }
func (x *cmdHWAssign) doHWAssign() error { if err := snappy.AddHWAccess(x.Positional.PackageName, x.Positional.DevicePath); err != nil { if err == snappy.ErrHWAccessAlreadyAdded { // TRANSLATORS: the first %s is a pkgname, the second %s is a path fmt.Printf(i18n.G("'%s' previously allowed access to '%s'. Skipping\n"), x.Positional.PackageName, x.Positional.DevicePath) return nil } return err } // TRANSLATORS: the first %s is a pkgname, the second %s is a path fmt.Printf(i18n.G("'%s' is now allowed to access '%s'\n"), x.Positional.PackageName, x.Positional.DevicePath) return nil }
func (x *cmdRollback) doRollback() error { pkg := x.Positional.PackageName version := x.Positional.Version if pkg == "" { return errNeedPackageName } nowVersion, err := snappy.Rollback(pkg, version, progress.MakeProgressBar()) if err != nil { return err } // TRANSLATORS: the first %s is a pkgname, the second %s is the new version fmt.Printf(i18n.G("Setting %s to version %s\n"), pkg, nowVersion) m := snappy.NewMetaRepository() installed, err := m.Installed() if err != nil { return err } parts := snappy.FindSnapsByNameAndVersion(pkg, nowVersion, installed) showVerboseList(parts, os.Stdout) return nil }
func (s *svcStatus) Execute(args []string) error { stati, err := s.doExecute(doStatus) if err != nil { return err } w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0) ws, _ := helpers.GetTermWinsize() rows := int(ws.Row) - 2 header := i18n.G("Snap\tService\tState") for i, status := range stati { // print a header every $rows rows if rows is bigger // than 10; otherwise, just the once. 10 is arbitrary, // but the thinking is that on the one hand you don't // want to be using up too much space with headers on // really small terminals and on the other rows might // actually be negative if you're not on a tty. if i%rows == 0 && (i == 0 || rows > 10) { fmt.Fprintln(w, header) } fmt.Fprintln(w, status) } w.Flush() return err }
func (x *cmdBuild) Execute(args []string) (err error) { if len(args) == 0 { args = []string{"."} } var snapPackage string if x.BuildSnapfs { snapPackage, err = snappy.BuildSnapfsSnap(args[0], x.Output) } else { snapPackage, err = snappy.BuildLegacySnap(args[0], x.Output) } if err != nil { return err } _, err = exec.LookPath(clickReview) if err != nil { fmt.Fprintf(os.Stderr, "Warning: could not review package (%s not available)\n", clickReview) } else { cmd := exec.Command(clickReview, snapPackage) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr // we ignore the error for now _ = cmd.Run() } // TRANSLATORS: the %s is a pkgname fmt.Printf(i18n.G("Generated '%s' snap\n"), snapPackage) return nil }
func printNoPrices(w *tabwriter.Writer, snaps []*client.Snap) { fmt.Fprintln(w, i18n.G("Name\tVersion\tSummary")) for _, snap := range snaps { fmt.Fprintf(w, "%s\t%s\t%s\n", snap.Name, snap.Version, snap.Summary) } }
func info() error { release := ubuntuCoreChannel() frameworks, _ := snappy.ActiveSnapIterByType(snappy.FullName, pkg.TypeFramework) apps, _ := snappy.ActiveSnapIterByType(snappy.FullName, pkg.TypeApp) // TRANSLATORS: the %s release string fmt.Printf(i18n.G("release: %s\n"), release) // TRANSLATORS: the %s an architecture string fmt.Printf(i18n.G("architecture: %s\n"), snappy.Architecture()) // TRANSLATORS: the %s is a comma separated list of framework names fmt.Printf(i18n.G("frameworks: %s\n"), strings.Join(frameworks, ", ")) //TRANSLATORS: the %s represents a list of installed appnames // (e.g. "apps: foo, bar, baz") fmt.Printf(i18n.G("apps: %s\n"), strings.Join(apps, ", ")) return nil }
func (x *cmdLogin) Execute(args []string) error { username := x.Positional.UserName fmt.Print(i18n.G("Password: "******"\n") if err != nil { return err } err = requestLoginWith2faRetry(username, string(password)) if err != nil { return err } fmt.Println(i18n.G("Login successful")) return nil }
func init() { _, err := parser.AddCommand("activate", i18n.G(`Activate a package`), i18n.G(`Activate a package that has previously been deactivated. If the package is already activated, do nothing.`), &cmdActivate{activate: true}) if err != nil { logger.Panicf("Unable to activate: %v", err) } _, err = parser.AddCommand("deactivate", i18n.G(`Deactivate a package`), i18n.G(`Deactivate a package. If the package is already deactivated, do nothing.`), &cmdActivate{activate: false}) if err != nil { logger.Panicf("Unable to deactivate: %v", err) } }
func init() { _, err := parser.AddCommand("enable-classic", i18n.G("Enable classic dimension."), i18n.G("Enable the ubuntu classic dimension."), &cmdEnableClassic{}) if err != nil { logger.Panicf("Unable to enable-classic: %v", err) } _, err = parser.AddCommand("destroy-classic", i18n.G("Destroy the classic dimension."), i18n.G("Destroy the ubuntu classic dimension."), &cmdDestroyClassic{}) if err != nil { logger.Panicf("Unable to destroy-classic: %v", err) } }
func info() error { rel := release.Get() release := fmt.Sprintf("%s/%s", rel.Flavor, rel.Series) frameworks, _ := snappy.ActiveSnapIterByType(snappy.FullName, snap.TypeFramework) apps, _ := snappy.ActiveSnapIterByType(snappy.FullName, snap.TypeApp) // TRANSLATORS: the %s release string fmt.Printf(i18n.G("release: %s\n"), release) // TRANSLATORS: the %s an architecture string fmt.Printf(i18n.G("architecture: %s\n"), arch.UbuntuArchitecture()) // TRANSLATORS: the %s is a comma separated list of framework names fmt.Printf(i18n.G("frameworks: %s\n"), strings.Join(frameworks, ", ")) //TRANSLATORS: the %s represents a list of installed appnames // (e.g. "apps: foo, bar, baz") fmt.Printf(i18n.G("apps: %s\n"), strings.Join(apps, ", ")) return nil }