-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.go
71 lines (53 loc) · 2.24 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
66
67
68
69
70
71
package strfry
import (
"fmt"
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/nodetec/rwz/pkg/utils/git"
"github.com/nodetec/rwz/pkg/utils/systemd"
"github.com/nodetec/rwz/pkg/verification"
"github.com/pterm/pterm"
"path/filepath"
)
// Function to download and make the binary executable
func InstallRelayBinary() {
downloadSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Downloading %s relay binary...", RelayName))
// Check for and remove existing git repository
directories.RemoveDirectory(GitRepoTmpDirPath)
// Download git repository
git.Clone(GitRepoBranch, GitRepoURL, GitRepoTmpDirPath)
directories.SetPermissions(GitRepoTmpDirPath, 0755)
// Install
// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
// Temporary file path
tmpFilePath := fmt.Sprintf("%s/%s", relays.TmpDirPath, tmpFileName)
// Check if the temporary file exists and remove it if it does
files.RemoveFile(tmpFilePath)
// Download and copy the file
files.DownloadAndCopyFile(tmpFilePath, DownloadURL)
downloadSpinner.Success(fmt.Sprintf("%s relay binary downloaded", RelayName))
// Verify relay binary
verification.VerifyRelayBinary(tmpFilePath)
installSpinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay binary...", RelayName))
// Check if the service file exists and disable and stop the service if it does
if files.FileExists(ServiceFilePath) {
// Disable and stop the Nostr relay service
installSpinner.UpdateText("Disabling and stopping service...")
systemd.DisableService(ServiceName)
systemd.StopService(ServiceName)
} else {
installSpinner.UpdateText("Service file not found...")
}
// Extract binary
files.ExtractFile(tmpFilePath, relays.BinaryDestDir)
// TODO
// Currently, the downloaded binary is expected to have a name that matches the BinaryName variable
// Ideally, the extracted binary file should be renamed to match the BinaryName variable
// Define the final destination path
destPath := filepath.Join(relays.BinaryDestDir, BinaryName)
// Make the file executable
files.SetPermissions(destPath, 0755)
installSpinner.Success(fmt.Sprintf("%s relay binary installed", RelayName))
}