@@ -3,13 +3,15 @@ package khatru_pyramid
3
3
import (
4
4
"fmt"
5
5
"github.com/nodetec/rwz/pkg/relays"
6
+ "github.com/nodetec/rwz/pkg/utils/directories"
6
7
"github.com/nodetec/rwz/pkg/utils/files"
8
+ "github.com/nodetec/rwz/pkg/utils/systemd"
7
9
"github.com/pterm/pterm"
8
10
"path/filepath"
9
11
)
10
12
11
13
// Function to download and make the binary executable
12
- func InstallRelayBinary () {
14
+ func InstallRelayBinary (pubKey string ) {
13
15
spinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Installing %s relay..." , RelayName ))
14
16
15
17
// Determine the file name from the URL
@@ -24,6 +26,31 @@ func InstallRelayBinary() {
24
26
// Download and copy the file
25
27
files .DownloadAndCopyFile (tmpFilePath , DownloadURL )
26
28
29
+ // Check if the service file exists and disable and stop the service if it does
30
+ if files .FileExists (ServiceFilePath ) {
31
+ // Disable and stop the Nostr relay service
32
+ spinner .UpdateText ("Disabling and stopping service..." )
33
+ systemd .DisableService (ServiceName )
34
+ systemd .StopService (ServiceName )
35
+ } else {
36
+ spinner .UpdateText ("Service file not found..." )
37
+ }
38
+
39
+ // Check if users.json file exists
40
+ if files .FileExists (UsersFilePath ) {
41
+ // Check if the pubKey exists in the users.json file
42
+ spinner .UpdateText ("Checking for public key in users.json file..." )
43
+ lineExists := files .LineExists (fmt .Sprintf (`"%s":""` , pubKey ), UsersFilePath )
44
+
45
+ // If false remove data directory
46
+ if ! lineExists {
47
+ spinner .UpdateText ("Public key not found, removing data directory..." )
48
+ directories .RemoveDirectory (DataDirPath )
49
+ } else {
50
+ spinner .UpdateText ("Public key found, keeping data directory." )
51
+ }
52
+ }
53
+
27
54
// Extract binary
28
55
files .ExtractFile (tmpFilePath , relays .BinaryDestDir )
29
56
0 commit comments