This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.go
65 lines (56 loc) · 1.65 KB
/
install.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
// install.go // This file implements the install functionality //
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
func installCommand(silent bool, binaryNames string) error {
// Disable the progressbar if the installation is to be performed silently
if silent {
UseProgressBar = false
}
binaries := strings.Fields(binaryNames)
for _, binaryName := range binaries {
// Extract the last part of the binaryName to use as the filename
fileName := filepath.Base(binaryName)
// Construct the installPath using the extracted filename
installPath := filepath.Join(InstallDir, fileName)
// Use ReturnCachedFile to check for a cached file
if InstallUseCache {
cachedFile, err := ReturnCachedFile(binaryName)
if err == 0 {
// If the cached file exists, use it
if !silent {
fmt.Printf("Using cached file: %s\n", cachedFile)
}
// Copy the cached file to the install path
if err := copyFile(cachedFile, installPath); err != nil {
return fmt.Errorf("error: Could not copy cached file: %v", err)
}
// Set executable bit immediately after copying
if err := os.Chmod(installPath, 0o755); err != nil {
return fmt.Errorf("failed to set executable bit: %v", err)
}
continue
}
}
// If the cached file does not exist, download the binary
url, err := findURL(binaryName)
if err != nil {
errorOut("%v\n", err)
}
if err := fetchBinaryFromURL(url, installPath); err != nil {
return fmt.Errorf("%v", err)
}
if !silent {
if InstallMessage != "disabled" {
fmt.Print(InstallMessage)
} else {
fmt.Printf("Successfully created %s\n", installPath)
}
}
}
return nil
}