Example #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
}
Example #2
0
func (a *Api) MirrorCreatePPA(name, ppaUrl, filter string, withSources, withUdebs, filterWithDeps, forceComponents bool) (*deb.RemoteRepo, error) {
	var archiveUrl, distribution string
	var components []string

	archiveUrl, distribution, components, err := deb.ParsePPA(ppaUrl, a.Ctx().Config())
	if err != nil {
		return nil, err
	}
	return a.MirrorCreate(name, archiveUrl, filter, distribution, components, withSources, withUdebs, filterWithDeps, forceComponents)
}