Ejemplo n.º 1
0
Archivo: main.go Proyecto: sbinet/aptly
func main() {
	err := cmd.Flag.Parse(os.Args[1:])
	if err != nil {
		log.Fatalf("%s", err)
	}

	context.downloader = utils.NewDownloader(2)
	defer context.downloader.Shutdown()

	// TODO: configure DB dir
	context.database, err = database.OpenDB("/tmp/aptly/db")
	if err != nil {
		log.Fatalf("can't open database: %s", err)
	}
	defer context.database.Close()

	// TODO:configure pool dir
	context.packageRepository = debian.NewRepository("/tmp/aptly")

	args := cmd.Flag.Args()
	err = cmd.Run(args)
	if err != nil {
		log.Fatalf("%s", err)
	}
}
Ejemplo n.º 2
0
func main() {
	err := cmd.Flag.Parse(os.Args[1:])
	if err != nil {
		fatal(err)
	}

	configLocation := cmd.Flag.Lookup("config").Value.String()
	if configLocation != "" {
		err = utils.LoadConfig(configLocation, &utils.Config)

		if err != nil {
			fatal(err)
		}
	} else {
		configLocations := []string{
			filepath.Join(os.Getenv("HOME"), ".aptly.conf"),
			"/etc/aptly.conf",
		}

		for _, configLocation := range configLocations {
			err = utils.LoadConfig(configLocation, &utils.Config)
			if err == nil {
				break
			}
			if !os.IsNotExist(err) {
				fatal(fmt.Errorf("error loading config file %s: %s", configLocation, err))
			}
		}

		if err != nil {
			fmt.Printf("Config file not found, creating default config at %s\n\n", configLocations[0])
			utils.SaveConfig(configLocations[0], &utils.Config)
		}
	}

	context.dependencyOptions = 0
	if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSuggests
	}
	if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowRecommends
	}
	if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowAllVariants
	}
	if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSource
	}

	context.architecturesList = utils.Config.Architectures
	optionArchitectures := cmd.Flag.Lookup("architectures").Value.String()
	if optionArchitectures != "" {
		context.architecturesList = strings.Split(optionArchitectures, ",")
	}

	context.downloader = utils.NewDownloader(utils.Config.DownloadConcurrency)
	defer context.downloader.Shutdown()

	context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
	if err != nil {
		fatal(fmt.Errorf("can't open database: %s", err))
	}
	defer context.database.Close()

	context.packageRepository = debian.NewRepository(utils.Config.RootDir)

	err = cmd.Dispatch(cmd.Flag.Args())
	if err != nil {
		fatal(err)
	}
}