-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstallation.go
134 lines (108 loc) · 3.68 KB
/
installation.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package ffcss
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
// InstallAssets installs the assets in the specified profile directory
func (t Theme) InstallAssets(operatingSystem string, variant Variant, profileDir string) (err error) {
files, err := t.AssetsPaths(operatingSystem, variant)
if err != nil {
return fmt.Errorf("while gathering assets: %w", err)
}
LogDebug("gathered %d asset(s)", len(files))
for _, file := range files {
stat, err := os.Stat(file)
if err != nil {
return fmt.Errorf("couldn't check file %s: %w", file, err)
}
if stat.IsDir() {
continue
}
content, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("while reading %s: %w", file, err)
}
destPath, err := t.DestinationPathOfAsset(file, profileDir, operatingSystem, variant)
if err != nil {
println(err.Error())
continue
}
err = os.MkdirAll(filepath.Dir(destPath), 0700)
if err != nil {
return fmt.Errorf("couldn't create parent directories for %s: %w", destPath, err)
}
err = ioutil.WriteFile(destPath, content, 0700)
if err != nil {
return fmt.Errorf("while writing to %s: %w", destPath, err)
}
LogDebug("wrote %s", destPath)
}
return nil
}
// InstallUserJS installs the content of user.js and the config entries to {{profileDir}}/user.js
func (t Theme) InstallUserJS(operatingSystem string, variant Variant, profileDir string) error {
var content []byte
var err error
if t.UserJS != "" {
file := filepath.Join(t.DownloadedTo, renderFileTemplate(t.UserJS, operatingSystem, variant, t.OSNames))
content, err = ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("while reading %s: %w", file, err)
}
} else {
content = []byte{}
}
additionalContent, err := t.UserJSFileContent()
if err != nil {
return fmt.Errorf("while translating config entries to javascript: %w", err)
}
if additionalContent != "" {
content = []byte(string(content) + "\n" + additionalContent)
LogDebug("generated additional user.js content from config entries: %q", additionalContent)
}
if string(content) == "" {
return nil
}
err = ioutil.WriteFile(filepath.Join(profileDir, "user.js"), content, 0700)
if err != nil {
return fmt.Errorf("while writing: %w", err)
}
LogDebug("installed user.js @ %s", filepath.Join(profileDir, "user.js"))
return nil
}
// InstallUserChrome writes the content of userChrome to {{profileDir}}/chrome/userChrome.css
func (t Theme) InstallUserChrome(os string, variant Variant, profileDir string) error {
if t.UserChrome == "" {
return nil
}
file := filepath.Join(t.DownloadedTo, renderFileTemplate(t.UserChrome, os, variant, t.OSNames))
content, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("while reading %s: %w", file, err)
}
err = ioutil.WriteFile(filepath.Join(profileDir, "chrome", "userChrome.css"), content, 0700)
if err != nil {
return fmt.Errorf("while writing: %w", err)
}
LogDebug("installed userChrome.css @ %s", filepath.Join(profileDir, "chrome", "userChrome.css"))
return nil
}
// InstallUserContent writes the content of userContent to {{profileDir}}/chrome/userContent.css
func (t Theme) InstallUserContent(os string, variant Variant, profileDir string) error {
if t.UserContent == "" {
return nil
}
file := filepath.Join(t.DownloadedTo, renderFileTemplate(t.UserContent, os, variant, t.OSNames))
content, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("while reading %s: %w", file, err)
}
err = ioutil.WriteFile(filepath.Join(profileDir, "chrome", "userContent.css"), content, 0700)
if err != nil {
return fmt.Errorf("while writing: %w", err)
}
LogDebug("installed userContent.css @ %s", filepath.Join(profileDir, "chrome", "userContent.css"))
return nil
}