Пример #1
0
// uninstall
func uninstall(ccmd *cobra.Command, args []string) {

	//
	switch printutil.Prompt("Are you sure you want to uninstall nanobox (y/N)? ") {

	// don't uninstall by default
	default:
		fmt.Println("Nanobox has not been uninstalled!")
		return

	// if yes continue to uninstall
	case "Yes", "yes", "Y", "y":
		break
	}

	fmt.Println("Uninstalling nanobox... ")

	// do we need to do more here than just this?
	// - shutdown/destroy all vms?
	// - remove virtualbox/vagrant?
	// - probably need to remove nanobox binary

	//
	if err := os.RemoveAll(config.Root); err != nil {
		config.Fatal("[install] os.Remove() failed", err.Error())
	}

	fmt.Println("Nanobox has been successfully uninstalled!")
}
Пример #2
0
// execute
func execute(ccmd *cobra.Command, args []string) {

	// PreRun: boot

	//
	if len(args) == 0 {
		args = append(args, print.Prompt("Please specify a command you wish to exec: "))
	}

	//
	v := url.Values{}

	// if a container is found that matches args[0] then set that as a qparam, and
	// remove it from the argument list
	if isContainer(args) {
		v.Add("container", args[0])
		args = args[1:]
	}
	v.Add("cmd", strings.Join(args, " "))

	//
	fmt.Printf(stylish.Bullet("Executing command in nanobox..."))
	if err := server.Exec(v.Encode()); err != nil {
		config.Error("[commands/exec] server.Exec failed", err.Error())
	}

	// PostRun: halt
}
Пример #3
0
// Reauthenticate
func Reauthenticate() (string, string) {
	fmt.Println(`
It appears the Username or API token the CLI is trying to use does not match what
we have on record. To continue, please login to verify your account:
  `)

	Userslug := printutil.Prompt("Username: "******"Password: ")

	// authenticate
	return authenticate(Userslug, password)
}
Пример #4
0
// Authenticate
func Authenticate() (string, string) {
	fmt.Printf(stylish.Bullet("Authenticating..."))

	//
	if !authenticated() {
		fmt.Println("Before continuing, please login to your account:")

		Userslug := printutil.Prompt("Username: "******"Password: ")

		// authenticate
		return authenticate(Userslug, password)
	}

	return creds.Userslug, creds.Authtoken
}
Пример #5
0
// Update
func Update() {

	update, err := updateAvailable()
	if err != nil {
		fmt.Println("Unable to determing if updates are available (see log for details).")
		Config.Error("[commands/update] updateAvailable() failed", err.Error())
		return
	}

	// stat the update file to get ModTime(); an error here means the file doesn't
	// exist. This is highly unlikely as the file is created if it doesn't exist
	// each time the CLI is run.
	fi, _ := os.Stat(config.UpdateFile)

	// if the md5s don't match and it's 'time' for an update (14 days), OR a force
	// update is issued, update
	if update && time.Since(fi.ModTime()).Hours() >= 336.0 {

		//
		switch printutil.Prompt("Nanobox is out of date, would you like to update it now (y/N)? ") {

		// don't update by default
		default:
			fmt.Println("You can manually update at any time with 'nanobox update'.")

			// if they don't update, assume then that they'll either do it manually or just
			// wait 14 more days
			if err := touchUpdate(); err != nil {
				fmt.Println("Failed to touch update")
				Config.Error("[commands/update] updateAvailable() failed", err.Error())
			}

			return

		// if yes continue to update
		case "Yes", "yes", "Y", "y":
			runUpdate()
		}
	}
}
Пример #6
0
// Update
func Update() error {

	update, err := updatable()
	if err != nil {
		return fmt.Errorf("Nanobox was unable to determine if updates are available - %s", err.Error())
	}

	// stat the update file to get ModTime(); an error here means the file doesn't
	// exist. This is highly unlikely as the file is created if it doesn't exist
	// each time the CLI is run.
	fi, _ := os.Stat(config.UpdateFile)

	// if the md5s don't match and it's 'time' for an update (14 days), OR a force
	// update is issued, update
	if update && time.Since(fi.ModTime()).Hours() >= 336.0 {

		//
		switch printutil.Prompt("Nanobox is out of date, would you like to update it now (y/N)? ") {

		// don't update by default, assuming they'll just do it manually, prompting
		// again after 14 days
		default:
			fmt.Println("You can manually update at any time with 'nanobox update'.")
			return touchUpdate()

		// if yes continue to update
		case "Yes", "yes", "Y", "y":
			if err := runUpdate(); err != nil {
				if _, ok := err.(*os.LinkError); ok {
					fmt.Println(`Nanobox was unable to update, try again with admin privilege (ex. "sudo nanobox update")`)
				} else {
					return fmt.Errorf("Nanobox was unable to update - %s", err.Error())
				}
			}
		}
	}

	return nil
}