func (x *cmdUpdate) doUpdate() error { // FIXME: handle (more?) args flags := snappy.DoInstallGC if x.DisableGC { flags = 0 } var err error var updates []snappy.Part if x.Positional.PackageName != "" { updates, err = snappy.Update(x.Positional.PackageName, flags, progress.MakeProgressBar()) } else { updates, err = snappy.UpdateAll(flags, progress.MakeProgressBar()) } if err != nil { return err } if len(updates) > 0 { showVerboseList(updates, os.Stdout) } if x.AutoReboot { installed, err := snappy.ListInstalled() if err != nil { return err } var rebootTriggers []string for _, part := range installed { if part.NeedsReboot() { rebootTriggers = append(rebootTriggers, part.Name()) } } if len(rebootTriggers) != 0 { // TRANSLATORS: the %s shows a comma separated list // of package names fmt.Printf(i18n.G("Rebooting to satisfy updates for %s\n"), strings.Join(rebootTriggers, ", ")) cmd := exec.Command(shutdownCmd, shutdownTimeout, "-r", shutdownMsg) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("failed to auto reboot: %s", out) } } } 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 *svcBase) doExecute(cmd int) ([]string, error) { actor, err := snappy.FindServices(s.Args.Snap, s.Args.Service, progress.MakeProgressBar()) if err != nil { return nil, err } switch cmd { case doStatus: return actor.Status() case doLogs: return actor.Loglines() case doStart: return nil, actor.Start() case doStop: return nil, actor.Stop() case doRestart: return nil, actor.Restart() case doEnable: return nil, actor.Enable() case doDisable: return nil, actor.Disable() default: panic("can't happen") } }
func (x *cmdSet) doSet() (err error) { pkgname, args, err := parseSetPropertyCmdline(x.args...) if err != nil { return err } return snappy.SetProperty(pkgname, progress.MakeProgressBar(), args...) }
// GadgetConfig checks for a gadget snap and if found applies the configuration // set there to the system func gadgetConfig() error { gadget, err := getGadget() if err != nil || gadget == nil { return err } partMap, err := newPartMap() if err != nil { return err } pb := progress.MakeProgressBar() for _, pkgName := range gadget.Gadget.Software.BuiltIn { part, ok := partMap[pkgName] if !ok { return errNoSnapToActivate } snap, ok := part.(*SnapPart) if !ok { return errNoSnapToActivate } if err := snap.activate(false, pb); err != nil { logger.Noticef("failed to acitvate %s: %s", FullName(part), err) } } for pkgName, conf := range gadget.Config { snap, ok := partMap[pkgName] if !ok { // We want to error early as this is a disparity and gadget snap // packaging error. return errNoSnapToConfig } configData, err := wrapConfig(pkgName, conf) if err != nil { return err } overlord := newOverlord() if _, err := overlord.Configure(snap.(*SnapPart), configData); err != nil { return err } } return nil }
func (x *cmdRemove) doRemove(args []string) error { flags := snappy.DoRemoveGC if x.DisableGC { flags = 0 } for _, part := range args { // TRANSLATORS: the %s is a pkgname fmt.Printf(i18n.G("Removing %s\n"), part) if err := snappy.Remove(part, flags, progress.MakeProgressBar()); err != nil { return err } } return nil }
func (x *cmdPurge) doPurge(args []string) error { var flags snappy.PurgeFlags if x.Installed { flags = snappy.DoPurgeActive } for _, part := range args { // TRANSLATORS: the %s is a pkgname fmt.Printf(i18n.G("Purging %s\n"), part) if err := snappy.Purge(part, flags, progress.MakeProgressBar()); err != nil { return err } } return nil }
// enableInstalledSnaps activates the installed preinstalled snaps // on the first boot func enableInstalledSnaps() error { all, err := (&Overlord{}).Installed() if err != nil { return nil } activator := getActivator() pb := progress.MakeProgressBar() for _, sn := range all { logger.Noticef("Acitvating %s", FullName(sn.Info())) if err := activator.SetActive(sn, true, pb); err != nil { // we don't want this to fail for now logger.Noticef("failed to activate %s: %s", FullName(sn.Info()), err) } } return nil }
// GadgetConfig checks for a gadget snap and if found applies the configuration // set there to the system func gadgetConfig() error { gadget, err := getGadget() if err != nil || gadget == nil { return err } snapMap, err := newSnapMap() if err != nil { return err } pb := progress.MakeProgressBar() for _, pkgName := range gadget.Legacy.Gadget.Software.BuiltIn { snap, ok := snapMap[pkgName] if !ok { return errNoSnapToActivate } if err := ActivateSnap(snap, pb); err != nil { logger.Noticef("failed to activate %s: %s", fmt.Sprintf("%s.%s", snap.Name(), snap.Developer()), err) } } for pkgName, conf := range gadget.Legacy.Config { snap, ok := snapMap[pkgName] if !ok { // We want to error early as this is a disparity and gadget snap // packaging error. return errNoSnapToConfig } configData, err := wrapConfig(pkgName, conf) if err != nil { return err } overlord := newOverlord() if _, err := overlord.Configure(snap, configData); err != nil { return err } } return nil }
// enableSystemSnaps activates the installed kernel/os/gadget snaps // on the first boot func enableSystemSnaps() error { repo := NewMetaLocalRepository() all, err := repo.All() if err != nil { return nil } pb := progress.MakeProgressBar() for _, part := range all { switch part.Type() { case snap.TypeGadget, snap.TypeKernel, snap.TypeOS: logger.Noticef("Acitvating %s", FullName(part)) if err := part.SetActive(true, pb); err != nil { // we don't want this to fail for now logger.Noticef("failed to acitvate %s: %s", FullName(part), err) } } } return nil }
func (x *cmdInstall) doInstall() error { pkgName := x.Positional.PackageName configFile := x.Positional.ConfigFile // FIXME patch goflags to allow for specific n required positional arguments if pkgName == "" { return errors.New(i18n.G("package name is required")) } flags := snappy.DoInstallGC if x.DisableGC { flags = 0 } if x.AllowUnauthenticated { flags |= snappy.AllowUnauthenticated } // TRANSLATORS: the %s is a pkgname fmt.Printf(i18n.G("Installing %s\n"), pkgName) realPkgName, err := snappy.Install(pkgName, flags, progress.MakeProgressBar()) if err != nil { return err } if configFile != "" { if _, err := configurePackage(realPkgName, configFile); err != nil { return err } } // call show versions afterwards installed, err := snappy.ListInstalled() if err != nil { return err } showInstalledList(installed, os.Stdout) return nil }
func (x *cmdActivate) doActivate() error { return snappy.SetActive(x.Args.Snap, x.activate, progress.MakeProgressBar()) }