// 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 conf.PackRelated = true 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 }
func newDefaultConfigFile(path string) error { conf := defaultConfigFile{ Listen: defaultListenAddr, HTTPS: false, Auth: "localhost", ReplicateTo: make([]interface{}, 0), } blobDir := osutil.CamliBlobRoot() if err := os.MkdirAll(blobDir, 0700); err != nil { return fmt.Errorf("Could not create default blobs directory: %v", err) } conf.BlobPath = blobDir if sqlite.CompiledIn() { conf.SQLite = filepath.Join(osutil.CamliVarDir(), "camli-index.db") if fi, err := os.Stat(conf.SQLite); os.IsNotExist(err) || (fi != nil && fi.Size() == 0) { if err := initSQLiteDB(conf.SQLite); err != nil { log.Printf("Error initializing DB %s: %v", conf.SQLite, err) } } } else { conf.KVFile = filepath.Join(osutil.CamliVarDir(), "camli-index.kvdb") } var keyId string secRing := osutil.IdentitySecretRing() _, err := os.Stat(secRing) switch { case err == nil: keyId, err = jsonsign.KeyIdFromRing(secRing) if err != nil { return fmt.Errorf("Could not find any keyId in file %q: %v", secRing, err) } log.Printf("Re-using identity with keyId %q found in file %s", keyId, secRing) case os.IsNotExist(err): keyId, err = jsonsign.GenerateNewSecRing(secRing) if err != nil { return fmt.Errorf("Could not generate new secRing at file %q: %v", secRing, err) } log.Printf("Generated new identity with keyId %q in file %s", keyId, secRing) } if err != nil { return fmt.Errorf("Could not stat secret ring %q: %v", secRing, err) } conf.Identity = keyId conf.IdentitySecretRing = secRing confData, err := json.MarshalIndent(conf, "", " ") if err != nil { return fmt.Errorf("Could not json encode config file : %v", err) } if err := ioutil.WriteFile(path, confData, 0600); err != nil { return fmt.Errorf("Could not create or write default server config: %v", err) } return nil }
func newDefaultConfigFile(path string) error { conf := defaultConfigFile{ Listen: ":3179", HTTPS: false, Auth: "localhost", ReplicateTo: make([]interface{}, 0), } blobDir := osutil.CamliBlobRoot() if err := os.MkdirAll(blobDir, 0700); err != nil { return fmt.Errorf("Could not create default blobs directory: %v", err) } conf.BlobPath = blobDir conf.SQLite = filepath.Join(osutil.CamliVarDir(), "camli-index.db") var keyId string secRing := osutil.IdentitySecretRing() _, err := os.Stat(secRing) switch { case err == nil: keyId, err = jsonsign.KeyIdFromRing(secRing) log.Printf("Re-using identity with keyId %q found in file %s", keyId, secRing) case os.IsNotExist(err): keyId, err = jsonsign.GenerateNewSecRing(secRing) log.Printf("Generated new identity with keyId %q in file %s", keyId, secRing) } if err != nil { return fmt.Errorf("Secret ring: %v", err) } conf.Identity = keyId conf.IdentitySecretRing = secRing confData, err := json.MarshalIndent(conf, "", " ") if err != nil { return fmt.Errorf("Could not json encode config file : %v", err) } if err := ioutil.WriteFile(path, confData, 0600); err != nil { return fmt.Errorf("Could not create or write default server config: %v", err) } if sqlite.CompiledIn() { if fi, err := os.Stat(conf.SQLite); os.IsNotExist(err) || (fi != nil && fi.Size() == 0) { if err := initSQLiteDB(conf.SQLite); err != nil { log.Printf("Error initializing DB %s: %v", conf.SQLite, err) } } } else { log.Printf("Wrote config file assuming SQLite, but SQLite is not available. Recompile with SQLite or modify %s and pick an index type. Please see http://camlistore.org/docs/server-config#windows", path) return errors.New("Newly written configuration not usable.") } return nil }