Example #1
0
func hwaf_run_cmd_self_init(cmd *commander.Command, args []string) error {
	var err error
	n := "hwaf-self-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		return fmt.Errorf("%s: does NOT take any argument", n)
	}

	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	if verbose {
		fmt.Printf("%s...\n", n)
	}

	hwaf_root := os.Getenv("HWAF_ROOT")
	for _, dir := range []string{g_ctx.Root, hwaf_root} {
		if dir != "" {
			g_ctx.Warnf("you are trying to 'hwaf self init' while running a HWAF_ROOT-based installation\n")
			g_ctx.Warnf("this is like crossing the streams in Ghostbusters (ie: it's bad.)\n")
			g_ctx.Warnf("if you think you know what you are doing, unset HWAF_ROOT and re-run 'hwaf self init'\n")
			return fmt.Errorf("${HWAF_ROOT} was set (%s)", dir)
		}
	}

	// 'hwaf self init' is now dummied out...

	if verbose {
		fmt.Printf("%s... [ok]\n", n)
	}

	return err
}
Example #2
0
func alto_run_cmd_vm_add(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	vm_name := ""
	vm_id := ""
	switch len(args) {
	case 2:
		vm_name = args[0]
		vm_id = args[1]
	default:
		err = fmt.Errorf("%s: needs 2 arguments (vm-name, vm-id)\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	if !quiet {
		fmt.Printf("%s: adding VM [%s] to repository...\n", n, vm_name)
	}

	err = g_ctx.AddVm(altolib.Vm{Id: vm_id, Tag: vm_name})
	handle_err(err)

	if !quiet {
		fmt.Printf("%s: adding VM [%s] to repository... [done]\n", n, vm_name)
	}
	return
}
Example #3
0
func aptlyRepoShow(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 1 {
		cmd.Usage()
		return err
	}

	name := args[0]

	localRepoCollection := debian.NewLocalRepoCollection(context.database)
	repo, err := localRepoCollection.ByName(name)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	err = localRepoCollection.LoadComplete(repo)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	fmt.Printf("Name: %s\n", repo.Name)
	fmt.Printf("Comment: %s\n", repo.Comment)
	fmt.Printf("Number of packages: %d\n", repo.NumPackages())

	withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool)
	if withPackages {
		ListPackagesRefList(repo.RefList())
	}

	return err
}
Example #4
0
func lbpkr_run_cmd_repo_ls(cmd *commander.Command, args []string) error {
	var err error

	debug := cmd.Flag.Lookup("v").Value.Get().(bool)
	siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)

	switch len(args) {
	case 0:
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=0. got=%d (%v)",
			len(args),
			args,
		)
	}

	cfg := NewConfig(siteroot)
	ctx, err := New(cfg, Debug(debug))
	if err != nil {
		return err
	}
	defer ctx.Close()

	err = ctx.ListRepositories()
	return err
}
Example #5
0
func hwaf_run_cmd_pmgr_get(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-pmgr-" + cmd.Name()
	verbose := cmd.Flag.Lookup("v").Value.Get().(bool)

	pkguri := ""
	switch len(args) {
	case 1:
		pkguri = args[0]
	default:
		err = fmt.Errorf("%s: you need to give a package URI to install", n)
		handle_err(err)
	}

	pkguri = strings.Replace(pkguri, "http://", "", 1)
	pkguri = strings.Replace(pkguri, "https://", "", 1)

	if verbose {
		fmt.Printf("%s: get [%s]...\n", n, pkguri)
	}

	//manifest_url := path.Join(pkguri, "MANIFEST")

	if verbose {
		fmt.Printf("%s: get [%s]... [ok]\n", n, pkguri)
	}
}
Example #6
0
func alto_run_cmd_vm_ls(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: listing VMs...\n", n)
	}

	vms := g_ctx.Vms()
	for _, vm := range vms {
		fmt.Printf("%v\n", vm)
	}

	if !quiet {
		fmt.Printf("%s: listing VMs... [done]\n", n)
	}

	return
}
Example #7
0
func fwk_run_cmd_build(cmd *commander.Command, args []string) error {
	var err error
	n := "fwk-app-" + cmd.Name()

	fnames := make([]string, 0, len(args))
	for _, arg := range args {
		if arg == "" {
			continue
		}
		if arg[0] == '-' {
			continue
		}
		fnames = append(fnames, arg)
	}

	if len(fnames) <= 0 {
		return fmt.Errorf("%s: you need to give a list of files or a directory", n)
	}

	bldr, err := builder.NewBuilder(fnames...)
	if err != nil {
		return err
	}

	if o := cmd.Flag.Lookup("o").Value.Get().(string); o != "" {
		bldr.Name = o
	}

	err = bldr.Build()
	if err != nil {
		return err
	}

	return err
}
Example #8
0
func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
	var err error
	if len(args) < 3 {
		cmd.Usage()
		return err
	}

	downloadSources := utils.Config.DownloadSourcePackages || cmd.Flag.Lookup("with-sources").Value.Get().(bool)

	repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], context.architecturesList, downloadSources)
	if err != nil {
		return fmt.Errorf("unable to create mirror: %s", err)
	}

	verifier, err := getVerifier(cmd)
	if err != nil {
		return fmt.Errorf("unable to initialize GPG verifier: %s", err)
	}

	err = repo.Fetch(context.downloader, verifier)
	if err != nil {
		return fmt.Errorf("unable to fetch mirror: %s", err)
	}

	repoCollection := debian.NewRemoteRepoCollection(context.database)

	err = repoCollection.Add(repo)
	if err != nil {
		return fmt.Errorf("unable to add mirror: %s", err)
	}

	fmt.Printf("\nMirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
	return err
}
func crossReleaseChanges(cmd *c.Command, args []string) {
	dev.MustFindCrowbar()
	if len(args) != 2 {
		log.Fatalf("%s takes exactly 2 release names!")
	}
	releases := new([2]dev.Release)
	// Translate command line parameters.
	// releases[0] will be the release with changes, and
	// releases[1] will be the base release.
	for i, name := range args {
		switch name {
		case "current":
			releases[i] = dev.CurrentRelease()
		case "parent":
			if i == 0 {
				log.Fatalf("parent can only be the second arg to %s\n", cmd.Name())
			}
			releases[1] = releases[0].Parent()
			if releases[1] == nil {
				log.Fatalf("%s does not have a parent release.\n", releases[0].Name())
			}
		default:
			releases[i] = dev.GetRelease(name)
		}
	}
	dev.CrossReleaseChanges(releases[0], releases[1])
}
Example #10
0
func lbpkr_run_cmd_provides(cmd *commander.Command, args []string) error {
	var err error

	siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)

	filename := ""

	switch len(args) {
	case 1:
		filename = args[0]
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1. got=%d (%v)",
			len(args),
			args,
		)
	}

	cfg := NewConfig(siteroot)
	ctx, err := New(cfg, Debug(debug))
	if err != nil {
		return err
	}
	defer ctx.Close()

	_, err = ctx.Provides(filename)
	return err
}
Example #11
0
func aptlySnapshotShow(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 1 {
		cmd.Usage()
		return err
	}

	name := args[0]

	snapshotCollection := debian.NewSnapshotCollection(context.database)
	snapshot, err := snapshotCollection.ByName(name)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	err = snapshotCollection.LoadComplete(snapshot)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	fmt.Printf("Name: %s\n", snapshot.Name)
	fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
	fmt.Printf("Description: %s\n", snapshot.Description)
	fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())

	withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool)
	if withPackages {
		ListPackagesRefList(snapshot.RefList())
	}

	return err
}
Example #12
0
func aptlyMirrorUpdate(cmd *commander.Command, args []string) {
	if len(args) != 1 {
		cmd.Usage()
		return
	}

	name := args[0]

	repoCollection := debian.NewRemoteRepoCollection(context.database)
	repo, err := repoCollection.ByName(name)
	if err != nil {
		log.Fatalf("Unable to update: %s", err)
	}

	err = repoCollection.LoadComplete(repo)
	if err != nil {
		log.Fatalf("Unable to update: %s", err)
	}

	err = repo.Fetch(context.downloader)
	if err != nil {
		log.Fatalf("Unable to update: %s", err)
	}

	err = repo.Download(context.downloader, context.database, context.packageRepository)
	if err != nil {
		log.Fatalf("Unable to update: %s", err)
	}

	err = repoCollection.Update(repo)
	if err != nil {
		log.Fatalf("Unable to update: %s", err)
	}

}
Example #13
0
func aptlyMirrorCreate(cmd *commander.Command, args []string) {
	if len(args) < 3 {
		cmd.Usage()
		return
	}

	var architectures []string
	archs := cmd.Flag.Lookup("architecture").Value.String()
	if len(archs) > 0 {
		architectures = strings.Split(archs, ",")
	}

	repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], architectures)
	if err != nil {
		log.Fatalf("Unable to create mirror: %s", err)
	}

	err = repo.Fetch(context.downloader)
	if err != nil {
		log.Fatalf("Unable to fetch mirror: %s", err)
	}

	repoCollection := debian.NewRemoteRepoCollection(context.database)

	err = repoCollection.Add(repo)
	if err != nil {
		log.Fatalf("Unable to add mirror: %s", err)
	}

	fmt.Printf("\nMirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
}
Example #14
0
func lbpkr_run_cmd_rpm(cmd *commander.Command, args []string) error {
	var err error

	siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)

	switch len(args) {
	case 0:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected at least one argument. got=%d (%v)",
			len(args),
			args,
		)
	}

	cfg := NewConfig(siteroot)
	ctx, err := New(cfg, Debug(debug))
	if err != nil {
		return err
	}
	defer ctx.Close()

	err = ctx.Rpm(args...)
	return err
}
Example #15
0
func aptlyPublishDrop(cmd *commander.Command, args []string) error {
	var err error
	if len(args) < 1 || len(args) > 2 {
		cmd.Usage()
		return err
	}

	distribution := args[0]
	prefix := "."

	if len(args) == 2 {
		prefix = args[1]
	}

	publishedCollecton := debian.NewPublishedRepoCollection(context.database)

	err = publishedCollecton.Remove(context.packageRepository, prefix, distribution)
	if err != nil {
		return fmt.Errorf("unable to remove: %s", err)
	}

	fmt.Printf("\nPublished repositroy has been removed successfully.\n")

	return err
}
Example #16
0
func aptlyRepoList(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 0 {
		cmd.Usage()
		return err
	}

	localRepoCollection := debian.NewLocalRepoCollection(context.database)

	if localRepoCollection.Len() > 0 {
		fmt.Printf("List of mirrors:\n")
		repos := make([]string, localRepoCollection.Len())
		i := 0
		localRepoCollection.ForEach(func(repo *debian.LocalRepo) error {
			err := localRepoCollection.LoadComplete(repo)
			if err != nil {
				return err
			}

			repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages())
			i++
			return nil
		})

		sort.Strings(repos)
		for _, repo := range repos {
			fmt.Println(repo)
		}

		fmt.Printf("\nTo get more information about local repository, run `aptly repo show <name>`.\n")
	} else {
		fmt.Printf("No local repositories found, create one with `aptly repo create ...`.\n")
	}
	return err
}
Example #17
0
func alto_run_cmd_box_ls(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: listing boxes...\n", n)
	}

	boxes := g_ctx.Boxes()
	for _, box := range boxes {
		const indent = "    "
		fmt.Printf(
			"::: box [%s] (cpus=%d ram=%dMb)\n%s%v\n%s%v\n",
			box.Id, box.Cpus, box.Ram,
			indent, box.Vm,
			indent, box.Disk,
		)
	}

	if !quiet {
		fmt.Printf("%s: listing boxes... [done]\n", n)
	}

	return
}
Example #18
0
func aptlyMirrorList(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 0 {
		cmd.Usage()
		return err
	}

	repoCollection := debian.NewRemoteRepoCollection(context.database)

	if repoCollection.Len() > 0 {
		fmt.Printf("List of mirrors:\n")
		repos := make(sort.StringSlice, repoCollection.Len())
		i := 0
		repoCollection.ForEach(func(repo *debian.RemoteRepo) error {
			repos[i] = repo.String()
			i++
			return nil
		})

		sort.Strings(repos)
		for _, repo := range repos {
			fmt.Printf(" * %s\n", repo)
		}

		fmt.Printf("\nTo get more information about mirror, run `aptly mirror show <name>`.\n")
	} else {
		fmt.Printf("No mirrors found, create one with `aptly mirror create ...`.\n")
	}
	return err
}
Example #19
0
func aptlySnapshotList(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 0 {
		cmd.Usage()
		return err
	}

	snapshotCollection := debian.NewSnapshotCollection(context.database)

	if snapshotCollection.Len() > 0 {
		fmt.Printf("List of snapshots:\n")

		snapshots := make(sort.StringSlice, snapshotCollection.Len())

		i := 0
		snapshotCollection.ForEach(func(snapshot *debian.Snapshot) error {
			snapshots[i] = snapshot.String()
			i++
			return nil
		})

		sort.Strings(snapshots)
		for _, snapshot := range snapshots {
			fmt.Printf(" * %s\n", snapshot)
		}

		fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show <name>`.\n")
	} else {
		fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n")
	}
	return err

}
Example #20
0
func git_run_cmd_dl_rm(cmd *commander.Command, args []string) {
	n := "github-" + cmd.Name()
	if len(args) != 1 {
		err := fmt.Errorf("%s: needs a file-id to delete", n)
		handle_err(err)
	}
	file_id := args[0]

	repo_name := cmd.Flag.Lookup("repo").Value.Get().(string)
	if repo_name == "" {
		err := fmt.Errorf("%s: needs a github repository name to delete from", n)
		handle_err(err)
	}

	user := cmd.Flag.Lookup("u").Value.Get().(string)
	org := cmd.Flag.Lookup("org").Value.Get().(string)

	if user == "" {
		v, err := Cfg.String("go-octogit", "username")
		handle_err(err)
		user = v
	}

	password, err := Cfg.String("go-octogit", "password")
	handle_err(err)

	ghc, err := client.NewGithubClient(user, password, client.AUTH_USER_PASSWORD)
	handle_err(err)

	account := user
	// DELETE /repos/:owner/:repo/downloads/:id
	if org != "" {
		account = org
	}
	url := path.Join("repos", account, repo_name, "downloads", file_id)

	fmt.Printf("%s: deleting download id=%s from [%s/%s]...\n",
		n, file_id, account, repo_name)

	req, err := ghc.NewAPIRequest("DELETE", url, nil)
	handle_err(err)

	resp, err := ghc.RunRequest(req, new(http.Client))
	handle_err(err)

	sc := resp.RawHttpResponse.StatusCode
	switch sc {
	case 204:
		// all good
	case 404:
		err = fmt.Errorf("%s: no such file-id\n", n)
	default:
		err = fmt.Errorf("%s: request did not succeed. got (status=%d) %v\n", n, resp.RawHttpResponse.StatusCode, resp.RawHttpResponse)
	}
	handle_err(err)

	fmt.Printf("%s: deleting download id=%s from [%s/%s]... [done]\n",
		n, file_id, account, repo_name)
}
Example #21
0
func lbpkr_run_cmd_remove(cmd *commander.Command, args []string) error {
	var err error

	siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)
	force := cmd.Flag.Lookup("force").Value.Get().(bool)
	dry := cmd.Flag.Lookup("dry-run").Value.Get().(bool)

	rpms := make([][3]string, 0)
	switch len(args) {
	case 0:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments (got=%d)", len(args))
	default:
		re := regexp.MustCompile(`(.*)-([\d\.]+)-(\d)$`)
		for _, name := range args {
			rpmname := name
			version := ""
			release := ""

			match := re.FindAllStringSubmatch(rpmname, -1)
			if len(match) == 1 {
				m := match[0]
				switch len(m) {
				case 2:
					rpmname = m[1]
				case 3:
					rpmname = m[1]
					version = m[2]
				case 4:
					rpmname = m[1]
					version = m[2]
					release = m[3]
				}
			}
			rpms = append(rpms, [3]string{rpmname, version, release})
		}
	}

	cfg := NewConfig(siteroot)
	ctx, err := New(cfg, Debug(debug), EnableForce(force), EnableDryRun(dry))
	if err != nil {
		return err
	}
	defer ctx.Close()

	str := []string{}
	for _, s := range rpms {
		str = append(str, fmt.Sprintf("%s %s %s", s[0], s[1], s[2]))
	}
	plural := ""
	if len(rpms) > 1 {
		plural = "s"
	}
	ctx.msg.Infof("removing RPM%s:\n%v\n", plural, strings.Join(str, "\n"))

	err = ctx.RemoveRPM(rpms, force)
	return err
}
Example #22
0
func alto_run_cmd_down(cmd *commander.Command, args []string) {
	var err error
	n := "alto-" + cmd.Name()

	switch len(args) {
	case 0:
		// ok
	default:
		err = fmt.Errorf("%s: does not take any argument\n", n)
		handle_err(err)
	}

	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	do_kill := cmd.Flag.Lookup("kill").Value.Get().(bool)

	if !quiet {
		fmt.Printf("%s: shutting down...\n", n)
	}

	const cfg_fname = "AltoFile"
	if !path_exists(cfg_fname) {
		err = fmt.Errorf("%s: no such file [%s]. did you run 'alto init some-box-name' ?", n, cfg_fname)
		handle_err(err)
	}

	const id_fname = ".alto.id"
	if !path_exists(id_fname) {
		err = fmt.Errorf("%s: no such file [%s]. did you run 'alto up' ?", n, id_fname)
		handle_err(err)
	}

	data, err := ioutil.ReadFile(id_fname)
	handle_err(err)

	id := bytes.Trim(data, " \r\n")

	cmd_name := "stratus-shutdown-instance"
	if do_kill {
		cmd_name = "stratus-kill-instance"
	}

	ssh := exec.Command(cmd_name, string(id))
	ssh.Stdin = os.Stdin
	ssh.Stdout = os.Stdout
	ssh.Stderr = os.Stderr
	err = ssh.Run()
	handle_err(err)

	err = os.Remove(id_fname)
	handle_err(err)

	if !quiet {
		fmt.Printf("%s: shutting down... [done]\n", n)
	}
	return
}
func hwaf_run_cmd_git_rm_submodule(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-" + cmd.Name()

	pkgdir := ""
	pkgname := ""
	switch len(args) {
	case 1:
		pkgdir = args[0]
		pkgname = args[0]
	default:
		err = fmt.Errorf("%s: needs a submodule name to remove", n)
		handle_err(err)
	}

	nocommit := cmd.Flag.Lookup("no-commit").Value.Get().(bool)

	cmtpkgdir := "src"

	if !path_exists(pkgdir) {
		cfg, err := g_ctx.LocalCfg()
		handle_err(err)
		if cfg.HasOption("hwaf-cfg", "cmtpkgs") {
			cmtpkgdir, err = cfg.String("hwaf-cfg", "cmtpkgs")
			handle_err(err)
		}
		if path_exists(filepath.Join(cmtpkgdir, pkgdir)) {
			pkgdir = filepath.Join(cmtpkgdir, pkgdir)
		}
	}

	pkgdir = os.ExpandEnv(pkgdir)
	pkgdir = filepath.Clean(pkgdir)

	if !path_exists(pkgdir) {
		err = fmt.Errorf("no such directory [%s]", pkgdir)
		handle_err(err)
	}

	if !nocommit {
		git := exec.Command("git", "add", ".gitmodules")
		err = git.Run()
		handle_err(err)

		git = exec.Command(
			"git", "commit", "-m",
			fmt.Sprintf("removed submodule [%s]", pkgname),
		)
		err = git.Run()
		handle_err(err)
	}

	handle_err(err)
}
Example #24
0
func remoteChanges(cmd *c.Command, args []string) {
	dev.MustFindCrowbar()
	switch len(args) {
	case 0:
		dev.RemoteChanges(dev.CurrentRelease())
	case 1:
		dev.RemoteChanges(dev.GetRelease(args[0]))
	default:
		log.Fatalf("%s takes 0 or 1 release name!\n", cmd.Name())
	}
}
Example #25
0
func aptlyRepoRemove(cmd *commander.Command, args []string) error {
	var err error
	if len(args) < 2 {
		cmd.Usage()
		return err
	}

	name := args[0]

	localRepoCollection := debian.NewLocalRepoCollection(context.database)
	repo, err := localRepoCollection.ByName(name)
	if err != nil {
		return fmt.Errorf("unable to remove: %s", err)
	}

	err = localRepoCollection.LoadComplete(repo)
	if err != nil {
		return fmt.Errorf("unable to remove: %s", err)
	}

	context.progress.Printf("Loading packages...\n")

	packageCollection := debian.NewPackageCollection(context.database)
	list, err := debian.NewPackageListFromRefList(repo.RefList(), packageCollection)
	if err != nil {
		return fmt.Errorf("unable to load packages: %s", err)
	}

	list.PrepareIndex()
	toRemove, err := list.Filter(args[1:], false, nil, 0, nil)
	if err != nil {
		return fmt.Errorf("unable to remove: %s", err)
	}

	toRemove.ForEach(func(p *debian.Package) error {
		list.Remove(p)
		context.progress.ColoredPrintf("@r[-]@| %s removed", p)
		return nil
	})

	if cmd.Flag.Lookup("dry-run").Value.Get().(bool) {
		context.progress.Printf("\nChanges not saved, as dry run has been requested.\n")
	} else {
		repo.UpdateRefList(debian.NewPackageRefListFromPackageList(list))

		err = localRepoCollection.Update(repo)
		if err != nil {
			return fmt.Errorf("unable to save: %s", err)
		}
	}

	return err
}
Example #26
0
func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 1 {
		cmd.Usage()
		return err
	}

	name := args[0]

	snapshotCollection := debian.NewSnapshotCollection(context.database)
	snapshot, err := snapshotCollection.ByName(name)
	if err != nil {
		return fmt.Errorf("unable to drop: %s", err)
	}

	publishedRepoCollection := debian.NewPublishedRepoCollection(context.database)
	published := publishedRepoCollection.BySnapshot(snapshot)

	if len(published) > 0 {
		fmt.Printf("Snapshot `%s` is published currently:\n", snapshot.Name)
		for _, repo := range published {
			err = publishedRepoCollection.LoadComplete(repo, snapshotCollection)
			if err != nil {
				return fmt.Errorf("unable to load published: %s", err)
			}
			fmt.Printf(" * %s\n", repo)
		}

		return fmt.Errorf("unable to drop: snapshot is published")
	}

	force := cmd.Flag.Lookup("force").Value.Get().(bool)
	if !force {
		snapshots := snapshotCollection.BySnapshotSource(snapshot)
		if len(snapshots) > 0 {
			fmt.Printf("Snapshot `%s` was used as a source in following snapshots:\n", snapshot.Name)
			for _, snap := range snapshots {
				fmt.Printf(" * %s\n", snap)
			}

			return fmt.Errorf("won't delete snapshot that was used as source for other snapshots, use -force to override")
		}
	}

	err = snapshotCollection.Drop(snapshot)
	if err != nil {
		return fmt.Errorf("unable to drop: %s", err)
	}

	fmt.Printf("Snapshot `%s` has been dropped.\n", snapshot.Name)

	return err
}
Example #27
0
func aptlyMirrorShow(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 1 {
		cmd.Usage()
		return err
	}

	name := args[0]

	repoCollection := debian.NewRemoteRepoCollection(context.database)
	repo, err := repoCollection.ByName(name)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	err = repoCollection.LoadComplete(repo)
	if err != nil {
		return fmt.Errorf("unable to show: %s", err)
	}

	fmt.Printf("Name: %s\n", repo.Name)
	fmt.Printf("Archive Root URL: %s\n", repo.ArchiveRoot)
	fmt.Printf("Distribution: %s\n", repo.Distribution)
	fmt.Printf("Components: %s\n", strings.Join(repo.Components, ", "))
	fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, ", "))
	downloadSources := "no"
	if repo.DownloadSources {
		downloadSources = "yes"
	}
	fmt.Printf("Download Sources: %s\n", downloadSources)
	if repo.LastDownloadDate.IsZero() {
		fmt.Printf("Last update: never\n")
	} else {
		fmt.Printf("Last update: %s\n", repo.LastDownloadDate.Format("2006-01-02 15:04:05 MST"))
		fmt.Printf("Number of packages: %d\n", repo.NumPackages())
	}

	fmt.Printf("\nInformation from release file:\n")
	for _, k := range utils.StrMapSortedKeys(repo.Meta) {
		fmt.Printf("%s: %s\n", k, repo.Meta[k])
	}

	withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool)
	if withPackages {
		if repo.LastDownloadDate.IsZero() {
			fmt.Printf("Unable to show package list, mirror hasn't been downloaded yet.\n")
		} else {
			ListPackagesRefList(repo.RefList())
		}
	}

	return err
}
Example #28
0
func runPostHandleNameCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}
	req, err := client.NewRequest("POST", "vm/"+cmd.Name()+"/"+args[0], nil)
	if err != nil {
		return err
	}
	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}
Example #29
0
func lbpkr_run_cmd_install_project(cmd *commander.Command, args []string) error {
	var err error

	siteroot := cmd.Flag.Lookup("siteroot").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)
	force := cmd.Flag.Lookup("force").Value.Get().(bool)
	dry := cmd.Flag.Lookup("dry-run").Value.Get().(bool)
	archs := cmd.Flag.Lookup("platforms").Value.Get().(string)
	nodeps := cmd.Flag.Lookup("nodeps").Value.Get().(bool)
	justdb := cmd.Flag.Lookup("justdb").Value.Get().(bool)

	projname := ""
	version := ""
	release := ""
	switch len(args) {
	case 0:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments (got=%d)", len(args))
	case 1:
		projname = args[0]
	case 2:
		projname = args[0]
		version = args[1]
	case 3:
		projname = args[0]
		version = args[1]
		release = args[2]
	default:
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1|2|3. got=%d (%v)",
			len(args),
			args,
		)
	}

	cfg := NewConfig(siteroot)
	ctx, err := New(
		cfg,
		Debug(debug),
		EnableForce(force), EnableDryRun(dry), EnableNoDeps(nodeps),
		EnableJustDb(justdb),
	)
	if err != nil {
		return err
	}
	defer ctx.Close()

	ctx.msg.Infof("installing project %s %s %s\n", projname, version, release)

	err = ctx.InstallProject(projname, version, release, archs)
	return err
}
Example #30
0
func runGetListHandlesubidCmd(cmd *commander.Command, args []string) error {
	if err := validateCmdArgs(cmd, args); err != nil {
		return err
	}

	req, err := client.NewRequest("GET", "v1/"+cmd.Name()+"/list", nil)
	if err != nil {
		return err
	}
	if _, err := pp(client.Do(req)); err != nil {
		return err
	}
	return nil
}