-
Notifications
You must be signed in to change notification settings - Fork 12
/
init.go
49 lines (39 loc) · 820 Bytes
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/mhewedy/vermin/db"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
)
func init() {
if err := os.MkdirAll(db.ImagesDir, 0755); err != nil {
log.Fatal(err)
}
if err := os.MkdirAll(db.VMsBaseDir, 0755); err != nil {
log.Fatal(err)
}
loadPrivateKey(
"https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant",
db.VagrantPrivateKey,
)
}
func loadPrivateKey(url, targetFile string) {
keyPath := filepath.Join(db.BaseDir, targetFile)
if _, err := os.Stat(keyPath); !os.IsNotExist(err) {
return
}
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
if err = ioutil.WriteFile(keyPath, b, 0600); err != nil {
log.Fatal(err)
}
}