Skip to content

Commit

Permalink
On first run also download the geoip data files
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Mar 23, 2018
1 parent 749cc66 commit 9fe917f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ooni.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Context) Init() error {
return errors.Wrap(err, "migrating home")
}

if err = CreateHomeDirs(c.Home); err != nil {
if err = MaybeInitializeHome(c.Home); err != nil {
return err
}

Expand Down Expand Up @@ -212,16 +212,28 @@ func ParseConfig(b []byte) (*Config, error) {
return c, nil
}

// CreateHomeDirs creates the OONI home subdirectories
func CreateHomeDirs(home string) error {
// MaybeInitializeHome does the setup for a new OONI Home
func MaybeInitializeHome(home string) error {
firstRun := false
requiredDirs := []string{"db", "msmts", "geoip"}
for _, d := range requiredDirs {
if _, e := os.Stat(filepath.Join(home, d)); e != nil {
firstRun = true
if err := os.MkdirAll(filepath.Join(home, d), 0700); err != nil {
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
}
Expand Down

0 comments on commit 9fe917f

Please sign in to comment.