-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (54 loc) · 1.22 KB
/
main.go
File metadata and controls
65 lines (54 loc) · 1.22 KB
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
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
var nogit bool = false
// Check if any args have been set
if len(os.Args) > 1 {
if os.Args[1] == "nogit" {
nogit = true
fmt.Println("Ok, won't backup to git. Will still move exported files to GitRepoFolder.")
} else {
fmt.Println("The only supported arg is 'nogit'")
os.Exit(1)
}
}
// Get settings from settings.json
// If they don't exist, create them
err := getSettings()
if err != nil {
fmt.Println("Error getting settings: ", err)
}
if !nogit {
// Check if git is accessible
if !checkForGit() {
fmt.Println("Can't access git, make sure it is in your $PATH variable.")
os.Exit(1)
}
// Check if GitRepoFolder exists and is a git repo
setupRepo()
}
// Download backup & get full path to it
files := getBackup()
// Foreach export zip, extract to gitrepo folder then delete zip
for _, file := range files {
// Extract downloaded backup
err := extract(file, filepath.Join(GitRepoFolder, "notes"))
if err != nil {
print(err.Error)
}
// Delete zip
err = os.Remove(file)
if err != nil {
print(err.Error)
}
}
if !nogit {
// Commit and push changes
commitBackup()
}
fmt.Println("Done backing up.")
}