/
main.go
58 lines (52 loc) · 1.26 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
package main
import (
"fmt"
"os"
"os/user"
"path"
"github.com/yookoala/realpath"
)
func check_config_directory(){
usr, _ := user.Current()
if _, err := os.Stat(usr.HomeDir+"/.exablock/"); os.IsNotExist(err) {
os.Mkdir(usr.HomeDir+"/.exablock", 0777)
os.Mkdir(usr.HomeDir+"/.exablock/files", 0777)
db_create()
var password string = display_get_pass("Enter a password (remember it, it will encrypt your files) : ")
var hashed_password string = make_hash(password)
db_insert_password(hashed_password)
}
}
func send_file(filename string){
var identifier string = generate_id()
realpath, _ := realpath.Realpath(filename)
filename = path.Base(filename)
var hfn string = make_hash(filename)
var host string = "local.dev"
encrypt_file(realpath, hfn)
fmt.Println(host, identifier)
}
func main(){
// Check config directory
check_config_directory()
if(len(os.Args) == 1){
display_help()
}else{
switch os.Args[1]{
case "help":
display_help()
case "version":
display_version()
case "list":
display_list_files()
case "send":
if len(os.Args) == 3{
send_file(os.Args[2])
}else{
display_error("MISSING_ARGV", os.Args[1])
}
default:
display_error("BAD_ARGV", os.Args[1])
}
}
}