|
|
|
@ -22,7 +22,8 @@ type Config struct {
|
|
|
|
|
|
|
|
|
|
ConnectionString string
|
|
|
|
|
|
|
|
|
|
CachePath string
|
|
|
|
|
CachePath string // Deprecated, should be removed soon
|
|
|
|
|
DatabaseCachePath string
|
|
|
|
|
ProgramCachePath string
|
|
|
|
|
|
|
|
|
|
Logfile string
|
|
|
|
@ -75,9 +76,11 @@ func (cfg *Config) Persist() (error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (cfg *Config) WasSetup() (bool) {
|
|
|
|
|
if cfg.CachePath == "" ||
|
|
|
|
|
if cfg.DatabaseCachePath == "" ||
|
|
|
|
|
cfg.ProgramCachePath == "" ||
|
|
|
|
|
cfg.ConnectionString == "" ||
|
|
|
|
|
cfg.Logfile == "" {
|
|
|
|
|
cfg.Logfile == "" ||
|
|
|
|
|
cfg.Profile.From == "" {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -88,6 +91,9 @@ func (cfg *Config) Setup() (error) {
|
|
|
|
|
fmt.Printf("\nSUPERHIGHWAY84\n\nInitial Setup\n-------------\n\n")
|
|
|
|
|
|
|
|
|
|
defaultConnectionString := "/orbitdb/bafyreifdpagppa7ve45odxuvudz5snbzcybwyfer777huckl4li4zbc5k4/superhighway84"
|
|
|
|
|
if cfg.ConnectionString != "" {
|
|
|
|
|
defaultConnectionString = cfg.ConnectionString
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Database connection string [%s]: ", defaultConnectionString)
|
|
|
|
|
fmt.Scanln(&cfg.ConnectionString)
|
|
|
|
|
if strings.TrimSpace(cfg.ConnectionString) == "" {
|
|
|
|
@ -100,22 +106,35 @@ func (cfg *Config) Setup() (error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defaultDatabaseCachePath := filepath.Join(cacheDir, "superhighway84", "database")
|
|
|
|
|
// Migration step from old CachePath to new DatabaseCachePath
|
|
|
|
|
if cfg.CachePath != "" {
|
|
|
|
|
defaultDatabaseCachePath = cfg.CachePath
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Database cache path [%s]: ", defaultDatabaseCachePath)
|
|
|
|
|
fmt.Scanln(&cfg.CachePath)
|
|
|
|
|
if strings.TrimSpace(cfg.CachePath) == "" {
|
|
|
|
|
cfg.CachePath = defaultDatabaseCachePath
|
|
|
|
|
fmt.Scanln(&cfg.DatabaseCachePath)
|
|
|
|
|
if strings.TrimSpace(cfg.DatabaseCachePath) == "" {
|
|
|
|
|
cfg.DatabaseCachePath = defaultDatabaseCachePath
|
|
|
|
|
}
|
|
|
|
|
os.MkdirAll(filepath.Dir(cfg.CachePath), 0755)
|
|
|
|
|
os.MkdirAll(filepath.Dir(cfg.DatabaseCachePath), 0755)
|
|
|
|
|
|
|
|
|
|
defaultProgramCachePath := filepath.Join(cacheDir, "superhighway84", "program")
|
|
|
|
|
// Migration step from old CachePath to new DatabaseCachePath
|
|
|
|
|
if cfg.CachePath != "" {
|
|
|
|
|
// If the previous CachePath was used, the folder already contains the
|
|
|
|
|
// OrbitDB, hence we need to find a different place
|
|
|
|
|
defaultProgramCachePath = filepath.Join(cacheDir, "superhighway84.program")
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Program cache path [%s]: ", defaultProgramCachePath)
|
|
|
|
|
fmt.Scanln(&cfg.ProgramCachePath)
|
|
|
|
|
if strings.TrimSpace(cfg.ProgramCachePath) == "" {
|
|
|
|
|
cfg.ProgramCachePath = defaultProgramCachePath
|
|
|
|
|
}
|
|
|
|
|
os.MkdirAll(filepath.Dir(cfg.ProgramCachePath), os.ModeDir)
|
|
|
|
|
os.MkdirAll(filepath.Dir(cfg.ProgramCachePath), 0755)
|
|
|
|
|
|
|
|
|
|
defaultLogfile := filepath.Join(cacheDir, "superhighway84.log")
|
|
|
|
|
if cfg.Logfile != "" {
|
|
|
|
|
defaultLogfile = cfg.Logfile
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Logfile path [%s]: ", defaultLogfile)
|
|
|
|
|
fmt.Scanln(&cfg.Logfile)
|
|
|
|
|
if strings.TrimSpace(cfg.Logfile) == "" {
|
|
|
|
@ -126,13 +145,20 @@ func (cfg *Config) Setup() (error) {
|
|
|
|
|
fmt.Printf("\nProfile information\n-------------------\n\n")
|
|
|
|
|
|
|
|
|
|
defaultProfileFrom := fmt.Sprintf("%s@localhost", os.Getenv("USER"))
|
|
|
|
|
if cfg.Profile.From != "" {
|
|
|
|
|
defaultProfileFrom = cfg.Profile.From
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("From [%s]: ", defaultProfileFrom)
|
|
|
|
|
fmt.Scanln(&cfg.Profile.From)
|
|
|
|
|
if strings.TrimSpace(cfg.Profile.From) == "" {
|
|
|
|
|
cfg.Profile.From = defaultProfileFrom
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Organization []: ")
|
|
|
|
|
defaultProfileOrganization := ""
|
|
|
|
|
if cfg.Profile.Organization != "" {
|
|
|
|
|
defaultProfileOrganization = cfg.Profile.Organization
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Organization [%s]: ", defaultProfileOrganization)
|
|
|
|
|
fmt.Scanln(&cfg.Profile.Organization)
|
|
|
|
|
|
|
|
|
|
return cfg.Persist()
|
|
|
|
|