forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
115 lines (92 loc) · 2.84 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// Keybase file system
package main
import (
"flag"
"fmt"
"os"
"bazil.org/fuse"
"github.com/keybase/client/go/logger"
"github.com/keybase/kbfs/env"
"github.com/keybase/kbfs/libfs"
"github.com/keybase/kbfs/libfuse"
"github.com/keybase/kbfs/libkbfs"
)
var runtimeDir = flag.String("runtime-dir", os.Getenv("KEYBASE_RUNTIME_DIR"), "runtime directory")
var label = flag.String("label", os.Getenv("KEYBASE_LABEL"), "label to help identify if running as a service")
var mountType = flag.String("mount-type", defaultMountType, "mount type: default, force, none")
var version = flag.Bool("version", false, "Print version")
const usageFormatStr = `Usage:
kbfsfuse -version
To run against remote KBFS servers:
kbfsfuse
[-runtime-dir=path/to/dir] [-label=label] [-mount-type=force]
%s
%s/path/to/mountpoint
To run in a local testing environment:
kbfsfuse
[-runtime-dir=path/to/dir] [-label=label] [-mount-type=force]
%s
%s/path/to/mountpoint
Defaults:
%s
`
func getUsageString(ctx libkbfs.Context) string {
remoteUsageStr := libkbfs.GetRemoteUsageString()
localUsageStr := libkbfs.GetLocalUsageString()
platformUsageStr := libfuse.GetPlatformUsageString()
defaultUsageStr := libkbfs.GetDefaultsUsageString(ctx)
return fmt.Sprintf(usageFormatStr,
remoteUsageStr, platformUsageStr,
localUsageStr, platformUsageStr, defaultUsageStr)
}
func start() *libfs.Error {
ctx := env.NewContext()
kbfsParams := libkbfs.AddFlags(flag.CommandLine, ctx)
platformParams := libfuse.AddPlatformFlags(flag.CommandLine)
flag.Parse()
if *version {
fmt.Printf("%s\n", libkbfs.VersionString())
return nil
}
if len(flag.Args()) < 1 {
fmt.Print(getUsageString(ctx))
return libfs.InitError("no mount specified")
}
if len(flag.Args()) > 1 {
fmt.Print(getUsageString(ctx))
return libfs.InitError("extra arguments specified (flags go before the first argument)")
}
if kbfsParams.Debug {
fuseLog := logger.NewWithCallDepth("FUSE", 1)
fuseLog.Configure("", true, "")
fuse.Debug = libfuse.MakeFuseDebugFn(
fuseLog, false /* superVerbose */)
}
mountpoint := flag.Arg(0)
var mounter libfuse.Mounter
if *mountType == "force" {
mounter = libfuse.NewForceMounter(mountpoint, *platformParams)
} else if *mountType == "none" {
mounter = libfuse.NewNoopMounter()
} else {
mounter = libfuse.NewDefaultMounter(mountpoint, *platformParams)
}
options := libfuse.StartOptions{
KbfsParams: *kbfsParams,
PlatformParams: *platformParams,
RuntimeDir: *runtimeDir,
Label: *label,
}
return libfuse.Start(mounter, options, ctx)
}
func main() {
err := start()
if err != nil {
fmt.Fprintf(os.Stderr, "kbfsfuse error: (%d) %s\n", err.Code, err.Message)
os.Exit(err.Code)
}
os.Exit(0)
}