On first run also download the geoip data files
This commit is contained in:
parent
749cc665af
commit
9fe917f294
18
ooni.go
18
ooni.go
|
@ -77,7 +77,7 @@ func (c *Context) Init() error {
|
||||||
return errors.Wrap(err, "migrating home")
|
return errors.Wrap(err, "migrating home")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = CreateHomeDirs(c.Home); err != nil {
|
if err = MaybeInitializeHome(c.Home); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,16 +212,28 @@ func ParseConfig(b []byte) (*Config, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateHomeDirs creates the OONI home subdirectories
|
// MaybeInitializeHome does the setup for a new OONI Home
|
||||||
func CreateHomeDirs(home string) error {
|
func MaybeInitializeHome(home string) error {
|
||||||
|
firstRun := false
|
||||||
requiredDirs := []string{"db", "msmts", "geoip"}
|
requiredDirs := []string{"db", "msmts", "geoip"}
|
||||||
for _, d := range requiredDirs {
|
for _, d := range requiredDirs {
|
||||||
if _, e := os.Stat(filepath.Join(home, d)); e != nil {
|
if _, e := os.Stat(filepath.Join(home, d)); e != nil {
|
||||||
|
firstRun = true
|
||||||
if err := os.MkdirAll(filepath.Join(home, d), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Join(home, d), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if firstRun == true {
|
||||||
|
log.Info("This is the first time you are running OONI Probe. Downloading some files.")
|
||||||
|
geoipDir := utils.GeoIPDir(home)
|
||||||
|
if err := utils.DownloadGeoIPDatabaseFiles(geoipDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := utils.DownloadLegacyGeoIPDatabaseFiles(geoipDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user