-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutil.go
88 lines (70 loc) · 1.58 KB
/
util.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
package main
import (
"os"
"strings"
"path/filepath"
"log"
"io/ioutil"
"encoding/json"
"fmt"
)
// Check the filePath if is a dir
func isDir(fileName string) int {
fileInfo, err := os.Stat(fileName)
if err != nil {
log.Println("file dose not exist: " + fileName)
return -1
}
if fileInfo.IsDir() {
return 1
} else {
return 0
}
}
// Get the change part of filePath
func getChangedFileName(fileName string) string {
fileName = strings.Replace(fileName, localDir, "", -1)
return filepath.ToSlash(fileName)
}
// Check and generate config file
func checkConfigFile() {
// Check
if _, err := os.Stat(ConfigFilePathName); !os.IsNotExist(err) {
return
}
// Generate if config not exist
// config template
var tpl string = `{
"localDir": "./",
"remoteDir": "Remote dir (absolute path like: /root/a)",
"sshHost": "Your host",
"sshPort": 22,
"sshUserName": "Your user name",
"sshPassword": "Your password",
"ignoreFiles": [
".git",
".idea",
".swp",
".swx",
"___jb_old___",
"___jb_tmp___"
]
}`
if err := ioutil.WriteFile(ConfigFilePathName, []byte(tpl), 0755); err != nil {
panic(err)
}
fmt.Println("\n", `Your are first time run this script, The config file 'config,json' not found, And already generated for you.`,
`Please reset the config item as your own infomation suck as ssh host & account, then run script again.`, "\n")
os.Exit(0)
}
// Parse config file
func parseConfigFile() {
configJson, err := ioutil.ReadFile(ConfigFilePathName)
if err != nil {
panic(err)
}
err = json.Unmarshal(configJson, &config)
if err != nil {
panic(err)
}
}