-
Notifications
You must be signed in to change notification settings - Fork 1
/
fix-build.go
101 lines (91 loc) · 2.21 KB
/
fix-build.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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func cmdFixBuild() *cli.Command {
return &cli.Command{
Name: "fix-build",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Usage: "version",
},
&cli.StringFlag{
Name: "in",
Usage: "in",
Value: "release",
},
&cli.StringFlag{
Name: "out",
Usage: "out",
Value: "release",
},
&cli.StringFlag{
Name: "platform",
Usage: "platform",
Value: runtime.GOOS,
},
},
Action: func(c *cli.Context) error {
switch c.String("platform") {
case "darwin":
return fixBuildDarwin(c.String("version"), c.String("in"), c.String("out"))
case "windows":
return fixBuildWindows(c.String("version"), c.String("in"), c.String("out"))
default:
log.Printf("No fixes required for %s", runtime.GOOS)
return nil
}
},
}
}
func fixBuildWindows(version string, in string, out string) error {
if version == "" {
return errors.Errorf("no version specified")
}
inFile, outFile := fmt.Sprintf("Keys %s.msi", version), fmt.Sprintf("Keys-%s.msi", version)
inPath, outPath := filepath.Join(in, inFile), filepath.Join(out, outFile)
log.Printf("Renaming %s to %s\n", inPath, outPath)
return os.Rename(inPath, outPath)
}
func fixBuildDarwin(version string, in string, out string) error {
if version == "" {
return errors.Errorf("no version specified")
}
zipBase := fmt.Sprintf("Keys-%s-mac.zip", version)
appDir := filepath.Join(in, "mac")
app := "Keys.app"
// Chdir to zip dir
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := os.Chdir(appDir); err != nil {
return err
}
log.Printf("Re-zipping %s (from %s)\n", zipBase, in)
cmd := exec.Command("ditto", "-c", "-k", "--sequesterRsrc", "--keepParent", app, zipBase)
if err := cmd.Run(); err != nil {
return err
}
// Chdir back
if err := os.Chdir(cwd); err != nil {
return err
}
zipOut := filepath.Join(out, zipBase)
if _, err := os.Stat(zipOut); err == nil {
if err := os.Remove(zipOut); err != nil {
return err
}
}
zipIn := filepath.Join(appDir, zipBase)
log.Printf("Moving %s to %s\n", zipIn, zipOut)
return os.Rename(zipIn, zipOut)
}