From 9fe917f294d5fa19c8660c04a58f7de033ed8a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Fri, 23 Mar 2018 15:38:25 +0100 Subject: [PATCH] On first run also download the geoip data files --- ooni.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ooni.go b/ooni.go index 903ae99..8000c0b 100644 --- a/ooni.go +++ b/ooni.go @@ -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 } @@ -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 }