@@ -12,84 +12,95 @@ import (
12
12
"path/filepath"
13
13
)
14
14
15
- // Function to download and make the binary and plugin binary executable
16
- func InstallRelayBinary () {
17
- downloadSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Downloading %s binaries..." , RelayName ))
15
+ // TODO
16
+ // Abstract this even more
18
17
18
+ func cloneTmpGitRepo () {
19
19
// Check for and remove existing git repository
20
20
directories .RemoveDirectory (GitRepoTmpDirPath )
21
21
22
22
// Download git repository
23
23
git .Clone (GitRepoBranch , GitRepoURL , GitRepoTmpDirPath )
24
24
25
25
directories .SetPermissions (GitRepoTmpDirPath , 0755 )
26
+ }
26
27
27
- // Install
28
- // Determine the file name from the URL
29
- tmpBinaryFileName := filepath .Base (DownloadURL )
28
+ // Determine the temporary file name from the provided path
29
+ func tmpFilePathFromFilePath ( path string ) string {
30
+ tmpFileName := filepath .Base (path )
30
31
31
- // Temporary file path
32
- tmpBinaryFilePath := fmt .Sprintf ("%s/%s" , relays .TmpDirPath , tmpBinaryFileName )
32
+ tmpFilePath := fmt .Sprintf ("%s/%s" , relays .TmpDirPath , tmpFileName )
33
33
34
- // Check if the temporary file exists and remove it if it does
35
- files . RemoveFile ( tmpBinaryFilePath )
34
+ return tmpFilePath
35
+ }
36
36
37
- // Download and copy the file
38
- files .DownloadAndCopyFile (tmpBinaryFilePath , DownloadURL )
37
+ func installRelayBinary (compressedBinaryFilePath , binaryName string ) {
38
+ // Extract relay binary
39
+ files .ExtractFile (compressedBinaryFilePath , relays .BinaryDestDir )
39
40
40
- // Determine the file name from the URL
41
- tmpBinaryPluginFileName := filepath .Base (BinaryPluginDownloadURL )
41
+ // TODO
42
+ // Currently, the downloaded binary is expected to have a name that matches the binaryName variable
43
+ // Ideally, the extracted binary file should be renamed to match the binaryName variable
42
44
43
- // Temporary file path
44
- tmpBinaryPluginFilePath := fmt . Sprintf ( "%s/%s" , relays .TmpDirPath , tmpBinaryPluginFileName )
45
+ // Define the final destination path
46
+ destPath := filepath . Join ( relays .BinaryDestDir , binaryName )
45
47
46
- // Check if the temporary file exists and remove it if it does
47
- files .RemoveFile (tmpBinaryPluginFilePath )
48
+ // Make the file executable
49
+ files .SetPermissions (destPath , 0755 )
50
+ }
48
51
49
- // Download and copy the file
50
- files .DownloadAndCopyFile (tmpBinaryPluginFilePath , BinaryPluginDownloadURL )
52
+ // Function to download and make the binary and plugin binary executable
53
+ func InstallRelayBinaries () {
54
+ pterm .Println ()
55
+ relayBinaryCheckSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Checking for existing %s binary..." , BinaryName ))
51
56
52
- downloadSpinner . Success ( fmt . Sprintf ( "%s binaries downloaded" , RelayName ) )
57
+ cloneTmpGitRepo ( )
53
58
54
- // Verify relay binary
55
- verification . VerifyRelayBinary ( BinaryName , tmpBinaryFilePath )
59
+ // Check if the service file exists and disable and stop the service if it does
60
+ systemd . DisableAndStopService ( ServiceFilePath , ServiceName )
56
61
57
- // Verify relay binary plugin
58
- verification .VerifyRelayBinary (fmt .Sprintf ("%s plugin" , RelayName ), tmpBinaryPluginFilePath )
62
+ // Check if relay binary exists
63
+ if ! files .FileExists (BinaryFilePath ) {
64
+ relayBinaryCheckSpinner .Info (fmt .Sprintf ("%s binary not found" , BinaryName ))
65
+ pterm .Println ()
59
66
60
- installSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Installing %s binaries..." , RelayName ))
67
+ // Determine the temporary file path
68
+ tmpCompressedBinaryFilePath := tmpFilePathFromFilePath (DownloadURL )
61
69
62
- // Check if the service file exists and disable and stop the service if it does
63
- if files .FileExists (ServiceFilePath ) {
64
- // Disable and stop the Nostr relay service
65
- installSpinner .UpdateText ("Disabling and stopping service..." )
66
- systemd .DisableService (ServiceName )
67
- systemd .StopService (ServiceName )
68
- } else {
69
- installSpinner .UpdateText ("Service file not found..." )
70
- }
70
+ // Check if the temporary file exists and remove it if it does
71
+ files .RemoveFile (tmpCompressedBinaryFilePath )
71
72
72
- // Extract relay binary
73
- files .ExtractFile (tmpBinaryFilePath , relays .BinaryDestDir )
73
+ // Download and copy the file
74
+ downloadSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Downloading %s binary..." , BinaryName ))
75
+ files .DownloadAndCopyFile (tmpCompressedBinaryFilePath , DownloadURL )
76
+ downloadSpinner .Success (fmt .Sprintf ("%s binary downloaded" , BinaryName ))
74
77
75
- // Extract relay binary plugin
76
- files . ExtractFile ( tmpBinaryPluginFilePath , relays . BinaryDestDir )
78
+ // Verify relay binary
79
+ verification . VerifyRelayBinary ( BinaryName , tmpCompressedBinaryFilePath )
77
80
78
- // TODO
79
- // Currently, the downloaded binary is expected to have a name that matches the BinaryName variable
80
- // Ideally, the extracted binary file should be renamed to match the BinaryName variable
81
+ installSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Installing %s binary..." , BinaryName ))
82
+ installRelayBinary (tmpCompressedBinaryFilePath , BinaryName )
83
+ installSpinner .Success (fmt .Sprintf ("%s binary installed" , BinaryName ))
84
+ } else {
85
+ relayBinaryCheckSpinner .Info (fmt .Sprintf ("%s binary found" , BinaryName ))
86
+ pterm .Println ()
87
+ }
81
88
82
- // Define the final destination path
83
- destPath := filepath . Join ( relays . BinaryDestDir , BinaryName )
89
+ // Determine the temporary file path
90
+ tmpCompressedBinaryPluginFilePath := tmpFilePathFromFilePath ( BinaryPluginDownloadURL )
84
91
85
- // Make the file executable
86
- files .SetPermissions ( destPath , 0755 )
92
+ // Check if the temporary file exists and remove it if it does
93
+ files .RemoveFile ( tmpCompressedBinaryPluginFilePath )
87
94
88
- // Define the final destination path
89
- destPath = filepath .Join (relays .BinaryDestDir , BinaryPluginName )
95
+ // Download and copy the file
96
+ binaryPluginDownloadSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Downloading %s plugin binary..." , BinaryPluginName ))
97
+ files .DownloadAndCopyFile (tmpCompressedBinaryPluginFilePath , BinaryPluginDownloadURL )
98
+ binaryPluginDownloadSpinner .Success (fmt .Sprintf ("%s plugin binary downloaded" , BinaryPluginName ))
90
99
91
- // Make the file executable
92
- files . SetPermissions ( destPath , 0755 )
100
+ // Verify relay binary plugin
101
+ verification . VerifyRelayBinary ( fmt . Sprintf ( "%s plugin" , BinaryPluginName ), tmpCompressedBinaryPluginFilePath )
93
102
94
- installSpinner .Success (fmt .Sprintf ("%s binaries installed" , RelayName ))
103
+ binaryPluginInstallSpinner , _ := pterm .DefaultSpinner .Start (fmt .Sprintf ("Installing %s plugin binary..." , BinaryPluginName ))
104
+ installRelayBinary (tmpCompressedBinaryPluginFilePath , BinaryPluginName )
105
+ binaryPluginInstallSpinner .Success (fmt .Sprintf ("%s plugin binary installed" , BinaryPluginName ))
95
106
}
0 commit comments