Example #1
0
func loadConfig(command *commander.Command) error {
	var err error

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

		if err != nil {
			return 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)
		}
	}

	return nil
}
Example #2
0
// Config loads and returns current configuration
func (context *AptlyContext) Config() *utils.ConfigStructure {
	if !context.configLoaded {
		var err error

		configLocation := context.flags.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.configLoaded = true

	}
	return &utils.Config
}
Example #3
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)
	}
}