-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsetup.go
More file actions
49 lines (38 loc) · 1.46 KB
/
Copy pathsetup.go
File metadata and controls
49 lines (38 loc) · 1.46 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
package png
import (
"fmt"
"path/filepath"
"runtime"
"github.com/Achno/gowall/config"
"github.com/Achno/gowall/internal/logger"
"github.com/Achno/gowall/utils"
)
func SetupPngquant() error {
destFolder := filepath.Join(config.GowallConfig.OutputFolder, "compression", "pngquant")
urls := map[string]string{
"linux": "https://pngquant.org/pngquant-linux.tar.bz2",
"windows": "https://pngquant.org/pngquant-windows.zip",
"darwin": "https://pngquant.org/pngquant.tar.bz2",
}
url, exists := urls[runtime.GOOS]
if !exists {
return fmt.Errorf("unsupported OS: %s\n Only available for linux,mac,windows", runtime.GOOS)
}
logger.Print(utils.BlueColor + " ➜ Downloading pngquant binary, sit back and relax" + utils.ResetColor)
if err := utils.DownloadAndExtract(url, destFolder, config.PngquantBinaryName, true); err != nil {
return fmt.Errorf("setup pngquant: %w", err)
}
logger.Print(utils.BlueColor + " ➜ Process complete. Pngquant setup" + utils.ResetColor)
return nil
}
// CheckPngquantInstalled checks if pngquant is available (either installed or downloaded)
func CheckPngquantInstalled() (string, error) {
binaryNames := map[string]string{
"linux": config.PngquantBinaryName,
"windows": config.PngquantBinaryName + ".exe",
"darwin": config.PngquantBinaryName,
"freebsd": config.PngquantBinaryName,
}
destFolder := filepath.Join(config.GowallConfig.OutputFolder, "compression", "pngquant")
return utils.FindBinary(binaryNames, destFolder)
}