Esempio n. 1
0
func (c *UpdateCommand) Execute(args []string) error {
	steps := utils.Steps{
		{
			"Downloading OS",
			func() error {
				if c.Version == "" {
					latest, err := utils.GetLatestOSVersion()
					if err != nil {
						return err
					}
					c.Version = latest
				}
				return utils.DownloadOS(c.Version)
			},
		},
	}

	return utils.Spin(steps)
}
Esempio n. 2
0
func (c *InstallCommand) Execute(args []string) error {
	utils.EnsureSudo()
	err := utils.CreateDir()
	if err != nil {
		return err
	}

	steps := utils.Steps{
		{
			"Building disk image",
			func() error {
				// clean up but ignore errors since it's possible things weren't installed
				utils.StopAgent()
				utils.RemoveAgent()
				utils.RemoveHost()
				utils.RemoveDir()

				err := utils.CreateDir()
				if err != nil {
					return err
				}

				return utils.CreateDisk(c.SSHKey, c.Disk)
			},
		},
		{
			"Downloading OS",
			func() error {
				if c.Version == "" {
					latest, err := utils.GetLatestOSVersion()
					if err != nil {
						return err
					}
					c.Version = latest
				}
				return utils.DownloadOS(c.Version)
			},
		},
		{
			"Writing configuration",
			func() error {
				uuid := uuid.NewV1().String()
				return utils.SaveConfig(utils.Config{
					Uuid:     uuid,
					CpuCount: c.Cpus,
					Memory:   c.Memory,
					Hostname: c.Hostname,
					DiskSize: c.Disk,
					Share:    c.Share,
				})
			},
		},
		{
			"Creating launchd agent",
			func() error {
				err := utils.AddSudoer()
				if err != nil {
					return err
				}

				return utils.CreateAgent()
			},
		},
	}

	return utils.Spin(steps)
}