forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
68 lines (65 loc) · 1.47 KB
/
status.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
package cmd
import (
"fmt"
obnet "github.com/OpenBazaar/openbazaar-go/net"
"github.com/OpenBazaar/openbazaar-go/repo"
"github.com/OpenBazaar/openbazaar-go/repo/db"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"os"
)
type Status struct {
DataDir string `short:"d" long:"datadir" description:"specify the data directory to be used"`
Testnet bool `short:"t" long:"testnet" description:"use the test network"`
}
func (x *Status) Execute(args []string) error {
// Set repo path
repoPath, err := repo.GetRepoPath(x.Testnet)
if err != nil {
return err
}
if x.DataDir != "" {
repoPath = x.DataDir
}
torAvailable := false
_, err = obnet.GetTorControlPort()
if err == nil {
torAvailable = true
}
if fsrepo.IsInitialized(repoPath) {
sqliteDB, err := db.Create(repoPath, "", x.Testnet)
if err != nil {
return err
os.Exit(1)
}
defer sqliteDB.Close()
if sqliteDB.Config().IsEncrypted() {
if !torAvailable {
fmt.Println("Initialized - Encrypted")
os.Exit(30)
} else {
fmt.Println("Initialized - Encrypted")
fmt.Println("Tor Available")
os.Exit(31)
}
} else {
if !torAvailable {
fmt.Println("Initialized - Not Encrypted")
os.Exit(20)
} else {
fmt.Println("Initialized - Not Encrypted")
fmt.Println("Tor Available")
os.Exit(21)
}
}
} else {
if !torAvailable {
fmt.Println("Not initialized")
os.Exit(10)
} else {
fmt.Println("Not initialized")
fmt.Println("Tor Available")
os.Exit(11)
}
}
return nil
}