forked from gohxs/cloudmount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (67 loc) · 1.69 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build linux
package main
//go:generate go get dev.hexasoftware.com/hxs/genversion
//go:generate genversion -package main -out version.go
import (
"fmt"
"log"
"os"
"github.com/gohxs/cloudmount/internal/core"
"github.com/gohxs/cloudmount/internal/fs/dropboxfs"
"github.com/gohxs/cloudmount/internal/fs/gdrivefs"
"github.com/gohxs/cloudmount/internal/fs/megafs"
"github.com/gohxs/prettylog"
"os/exec"
)
var (
//Name app name
Name = "cloudmount"
)
func main() {
// TODO: TEMP
/*{
// Globally insecure SSL for debugging
r, _ := http.NewRequest("GET", "http://localhost", nil)
cli := &http.Client{}
cli.Do(r)
tr := http.DefaultTransport.(*http.Transport)
tr.TLSClientConfig.InsecureSkipVerify = true
}*/
prettylog.Global()
fmt.Fprintf(os.Stderr, "%s-%s\n", Name, Version)
// getClient
c := core.New()
// More will be added later
c.Drivers["gdrive"] = gdrivefs.New
c.Drivers["dropbox"] = dropboxfs.New
c.Drivers["mega"] = megafs.New
if err := parseFlags(&c.Config); err != nil {
log.Fatalln(err)
}
err := c.Init() // Before daemon, because might require interactivity
if err != nil {
log.Println("Err:", err)
return
}
fmt.Fprintf(os.Stderr, "%s on %s type %s\n", c.Config.Source, c.Config.Target, c.Config.Type)
////////////////////////////////
// Daemon
/////////////////
if !c.Config.Foreground {
subArgs := []string{"-f"}
for _, arg := range os.Args[1:] {
if arg == "-f" { // ignore daemon flag, already added
continue
}
subArgs = append(subArgs, arg)
}
cmd := exec.Command(os.Args[0], subArgs...)
//cmd.Stdout = os.Stdout
//cmd.Stderr = os.Stderr
cmd.Start()
fmt.Println("[PID]", cmd.Process.Pid)
os.Exit(0)
return
}
c.Mount()
}