コード例 #1
0
func writeDefaultConfigFile() error {
	if err := wkfs.MkdirAll(baseConfig.BlobPath, 0700); err != nil {
		return fmt.Errorf("Could not create default blobs directory: %v", err)
	}
	if err := wkfs.MkdirAll(path.Base(camliServerConf), 0700); err != nil {
		return fmt.Errorf("Could not create default config directory: %v", err)
	}

	keyID, err := getOrMakeKeyring()
	if err != nil {
		return err
	}
	baseConfig.Identity = keyID
	baseConfig.Auth = fmt.Sprintf("userpass:%s:%s", *flagUsername, *flagPassword)

	confData, err := json.MarshalIndent(baseConfig, "", "    ")
	if err != nil {
		return fmt.Errorf("Could not json encode config file : %v", err)
	}
	if err := wkfs.WriteFile(camliServerConf, confData, 0600); err != nil {
		return fmt.Errorf("Could not create or write default server config: %v", err)
	}

	// chown everything back to "camli" since we run as root.
	// TODO(mpl): do it in Go with os.Chown + filepath.Walk (for recursion), if we care.
	if out, err := exec.Command("chown", "-R", camliUsername+":"+camliUsername, path.Join(home, "var")).CombinedOutput(); err != nil {
		return fmt.Errorf("chown error: %v, %v", string(out), err)
	}
	if out, err := exec.Command("chown", "-R", camliUsername+":"+camliUsername, path.Join(home, ".config")).CombinedOutput(); err != nil {
		return fmt.Errorf("chown error: %v, %v", string(out), err)
	}
	return nil
}
コード例 #2
0
ファイル: genconfig.go プロジェクト: Micrap/camlistore
// WriteDefaultConfigFile generates a new default high-level server configuration
// file at filePath. If useSQLite, the default indexer will use SQLite, otherwise
// leveldb. If filePath already exists, it is overwritten.
func WriteDefaultConfigFile(filePath string, useSQLite bool) error {
	conf := defaultBaseConfig
	blobDir := osutil.CamliBlobRoot()
	if err := wkfs.MkdirAll(blobDir, 0700); err != nil {
		return fmt.Errorf("Could not create default blobs directory: %v", err)
	}
	conf.BlobPath = blobDir
	if useSQLite {
		conf.SQLite = filepath.Join(osutil.CamliVarDir(), "index.sqlite")
	} else {
		conf.LevelDB = filepath.Join(osutil.CamliVarDir(), "index.leveldb")
	}

	keyID, secretRing, err := getOrMakeKeyring()
	if err != nil {
		return err
	}
	conf.Identity = keyID
	conf.IdentitySecretRing = secretRing

	confData, err := json.MarshalIndent(conf, "", "    ")
	if err != nil {
		return fmt.Errorf("Could not json encode config file : %v", err)
	}

	if err := wkfs.WriteFile(filePath, confData, 0600); err != nil {
		return fmt.Errorf("Could not create or write default server config: %v", err)
	}

	return nil
}
コード例 #3
0
ファイル: camlistored.go プロジェクト: Jimmy99/camlistore
// loadConfig returns the server's parsed config file, locating it using the provided arg.
//
// The arg may be of the form:
// - empty, to mean automatic (will write a default high-level config if
//   no cloud config is available)
// - a filepath absolute or relative to the user's configuration directory,
// - a URL
func loadConfig(arg string) (conf *serverinit.Config, isNewConfig bool, err error) {
	if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
		contents, err := slurpURL(arg, 256<<10)
		if err != nil {
			return nil, false, err
		}
		conf, err = serverinit.Load(contents)
		return conf, false, err
	}
	var absPath string
	switch {
	case arg == "":
		absPath = osutil.UserServerConfigPath()
		_, err = wkfs.Stat(absPath)
		if err != nil {
			if !os.IsNotExist(err) {
				return
			}
			conf, err = serverinit.DefaultEnvConfig()
			if err != nil || conf != nil {
				return
			}
			err = wkfs.MkdirAll(osutil.CamliConfigDir(), 0700)
			if err != nil {
				return
			}
			log.Printf("Generating template config file %s", absPath)
			if err = serverinit.WriteDefaultConfigFile(absPath, sqlite.CompiledIn()); err == nil {
				isNewConfig = true
			}
		}
	case filepath.IsAbs(arg):
		absPath = arg
	default:
		absPath = filepath.Join(osutil.CamliConfigDir(), arg)
	}
	conf, err = serverinit.LoadFile(absPath)
	return
}