Exemplo n.º 1
0
func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
	var err error
	if !(len(args) == 2 && strings.HasPrefix(args[1], "ppa:") || len(args) >= 3) {
		cmd.Usage()
		return commander.ErrCommandError
	}

	downloadSources := LookupOption(context.Config().DownloadSourcePackages, context.Flags(), "with-sources")
	downloadUdebs := context.Flags().Lookup("with-udebs").Value.Get().(bool)

	var (
		mirrorName, archiveURL, distribution string
		components                           []string
	)

	mirrorName = args[0]
	if len(args) == 2 {
		archiveURL, distribution, components, err = deb.ParsePPA(args[1], context.Config())
		if err != nil {
			return err
		}
	} else {
		archiveURL, distribution, components = args[1], args[2], args[3:]
	}

	repo, err := deb.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.ArchitecturesList(),
		downloadSources, downloadUdebs)
	if err != nil {
		return fmt.Errorf("unable to create mirror: %s", err)
	}

	repo.Filter = context.Flags().Lookup("filter").Value.String()
	repo.FilterWithDeps = context.Flags().Lookup("filter-with-deps").Value.Get().(bool)
	repo.SkipComponentCheck = context.Flags().Lookup("force-components").Value.Get().(bool)

	if repo.Filter != "" {
		_, err = query.Parse(repo.Filter)
		if err != nil {
			return fmt.Errorf("unable to create mirror: %s", err)
		}
	}

	verifier, err := getVerifier(context.Flags())
	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)
	}

	err = context.CollectionFactory().RemoteRepoCollection().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
}
Exemplo n.º 2
0
func (a *Api) MirrorCreate(name, url, filter, distribution string, components []string, withSources, withUdebs, filterWithDeps, forceComponents bool) (*deb.RemoteRepo, error) {
	repo, err := deb.NewRemoteRepo(name, url, distribution, components, a.Ctx().ArchitecturesList(), withSources, withUdebs)
	if err != nil {
		return nil, fmt.Errorf("unable to create mirror: %s", err)
	}

	repo.Filter = filter
	repo.FilterWithDeps = filterWithDeps
	repo.SkipComponentCheck = forceComponents

	if repo.Filter != "" {
		_, err := query.Parse(repo.Filter)
		if err != nil {
			return nil, fmt.Errorf("unable to create mirror: %s", err)
		}
	}

	_, err = getVerifier(false)
	if err != nil {
		return nil, fmt.Errorf("unable to init GPG: %s", err)
	}

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

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

	return repo, nil
}