Esempio n. 1
0
File: api.go Progetto: alecu/snappy
func (inst *snapInstruction) update() interface{} {
	flags := snappy.DoInstallGC
	if inst.LeaveOld {
		flags = 0
	}

	_, err := snappy.Update(inst.pkg, flags, inst)
	return err
}
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
}