/
main.go
52 lines (43 loc) · 1.05 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
package main
import (
"context"
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"strings"
"time"
"github.com/rclone/rclone/backend/crypt"
_ "github.com/rclone/rclone/backend/drive"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configfile"
)
func main() {
usr, _ := user.Current()
config.SetConfigPath(filepath.Join(usr.HomeDir, ".rclone.conf"))
configfile.Install()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
if len(os.Args) != 2 {
log.Fatal("path not specified")
}
remotePath := os.Args[1]
pathComponents := strings.Split(remotePath, ":")
if len(pathComponents) != 2 {
log.Fatal("path must be of the following format: remote:/path/to/file/or/directory")
}
remote := pathComponents[0] + ":"
path := pathComponents[1]
f, err := fs.NewFs(ctx, remote)
if err != nil {
log.Fatal(err)
}
cryptFS, ok := f.(*crypt.Fs)
if !ok {
log.Fatal("not a crypt remote")
}
encryptedPath := cryptFS.EncryptFileName(path)
fmt.Println(encryptedPath)
}