-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.go
85 lines (65 loc) · 2.82 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package wot_relay
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(pubKey string) {
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)
// 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...")
}
// Check if environment file exists
if files.FileExists(EnvFilePath) {
// Check if the pubKey exists in the environment file
installSpinner.UpdateText(fmt.Sprintf("Checking for public key in the %s file...", EnvFilePath))
lineExists := files.LineExists(fmt.Sprintf(`RELAY_PUBKEY="%s"`, pubKey), EnvFilePath)
// If false remove data directory
if !lineExists {
installSpinner.UpdateText("Public key not found, removing data directory...")
directories.RemoveDirectory(DataDirPath)
} else {
installSpinner.UpdateText("Public key found, keeping data directory.")
}
}
// 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))
}