-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
107 lines (101 loc) · 3.07 KB
/
deploy.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func rsyncDeploy(destination string) {
if !dirExists(deployDirName) {
sprintln("deploy dir does not exist - make sure to run the `mbgen generate` command first")
} else {
source, err := filepath.Abs(deployDirName)
check(err)
sprintln(
" - deploy source: "+source,
" - deploy destination: "+destination,
)
destPathSeparator := '/'
for i := 0; i < len(destination); i++ {
if destination[i] == '\\' {
destPathSeparator = '\\'
break
}
}
deployOpts := []deployOptions{
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, mediaDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, mediaDirName),
},
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, deployPageDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, deployPageDirName),
},
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, deployPostDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, deployPostDirName),
},
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, deployPostsDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, deployPostsDirName),
},
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, deployTagsDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, deployTagsDirName),
},
{
source: fmt.Sprintf("%s%c%s%c", source, os.PathSeparator, deployArchiveDirName, os.PathSeparator),
destination: fmt.Sprintf("%s%c%s", destination, destPathSeparator, deployArchiveDirName),
},
{
source: fmt.Sprintf("%s%c", source, os.PathSeparator),
destination: destination,
exclude: []string{
mediaDirName,
deployPageDirName,
deployPostDirName,
deployPostsDirName,
deployTagsDirName,
deployArchiveDirName,
},
},
}
for i := 0; i < len(deployOpts); i++ {
dOpts := deployOpts[i]
if dirExists(dOpts.source) {
fmt.Printf("\n - deploy: %s -> %s\n", dOpts.source, dOpts.destination)
args := []string{
"--archive",
"--compress",
"--delete",
"--no-t",
"--no-o",
"--no-g",
"--no-p",
"--progress",
"--verbose",
}
if len(dOpts.exclude) > 0 {
for _, exclude := range dOpts.exclude {
args = append(args, fmt.Sprintf("--exclude=%s", exclude))
}
}
args = append(args, dOpts.source)
args = append(args, dOpts.destination)
cmd := exec.Command("rsync", args...)
output, err := cmd.Output()
check(err)
outputLines := strings.Split(string(output), "\n")
for _, line := range outputLines {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "sent") ||
strings.HasPrefix(line, "total") {
fmt.Println(" - " + line)
}
}
fmt.Printf(" - deploy: %s -> %s [complete]\n", dOpts.source, dOpts.destination)
}
}
}
}