Esempio n. 1
0
func releaseDestroyCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to destroy\n")
	}

	release, err := core.FindRelease(args[0])
	if err != nil {
		gologit.Fatalf("Release '%s' not found!\n", args[0])
	}

	fmt.Printf("Ready to remove release: %s\n", release.Name)
	if !force {
		fmt.Print("Are you sure [yN]? ")
		var response string
		_, err = fmt.Scanln(&response)
		if err != nil {
			if err.Error() == "unexpected newline" {
				os.Exit(0)
			}
			gologit.Fatalf("%s", err)
		}

		response = strings.ToLower(strings.TrimSpace(response))
		if len(response) != 1 || response[0] != 'y' {
			return
		}
	}

	fmt.Printf("Destroying: %s\n", release.Name)
	core.ZFSMust(
		fmt.Errorf("Error destroying release"),
		"destroy", "-fr", release.Path)
	os.RemoveAll(release.Mountpoint)
}
Esempio n. 2
0
func releaseUpdateCmdRun(cmd *cobra.Command, args []string) {
	// requires root
	if !core.IsRoot() {
		gologit.Fatalf("Must be root to update\n")
	}

	release, err := core.FindRelease(args[0])
	if err != nil {
		gologit.Fatalf("Release '%s' not found!\n", args[0])
	}

	mountpoint := release.Mountpoint
	resolvconf := path.Join(mountpoint, "root/etc/resolv.conf")
	if _, err := os.Stat(resolvconf); os.IsNotExist(err) {
		data, err := ioutil.ReadFile("/etc/resolv.conf")
		if err != nil {
			gologit.Fatalln("/etc/resolv.conf not present or not readable")
		}

		err = ioutil.WriteFile(resolvconf, data, 0755)
		if err != nil {
			gologit.Fatalf("Could not copy contents to '%s'\n", resolvconf)
		}
	}

	devroot := path.Join(mountpoint, "root/dev")
	ecmd := exec.Command("/sbin/mount", "-t", "devfs", "devfs", devroot)
	gologit.Debugln(ecmd.Args)
	eout, err := ecmd.CombinedOutput()
	if err != nil {
		gologit.Fatalf("Error mounting devfs: %s\n", err)
	}
	gologit.Debugln(string(eout))

	defer func() {
		ecmd := exec.Command("/sbin/umount", devroot)
		gologit.Debugln(ecmd.Args)
		err := ecmd.Run()
		if err != nil {
			gologit.Fatalf("Error unmounting devfs: %s\n", err)
		}
	}()

	fmt.Println("* Updating release...")
	root := path.Join(mountpoint, "root")

	exargs := []string{root, "/usr/sbin/freebsd-update"}
	if release.Name != "9.3-RELEASE" && release.Name != "10.1-RELEASE" {
		exargs = append(exargs, "--not-running-from-cron")
	}
	exargs = append(exargs, "fetch", "install")
	ecmd = exec.Command("/usr/sbin/chroot", exargs...)
	unamer := release.Name
	if release.Patchlevel != "" {
		unamer = release.Patchlevel
	}
	ecmd.Env = []string{
		"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
		fmt.Sprintf("UNAME_r=%s", unamer),
		"PAGER=/bin/cat",
	}
	gologit.Debugln(ecmd.Args)
	ecmd.Stdout = os.Stdout
	ecmd.Stderr = os.Stderr
	ecmd.Stdin = os.Stdin
	ecmd.Run()
	fmt.Println("* update finished")
}