Skip to content

Commit 6b78e4b

Browse files
committed
chore: refactor relay service files and update success messages
1 parent 36422ee commit 6b78e4b

29 files changed

+512
-295
lines changed

cmd/install.go

+60-21
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ var installCmd = &cobra.Command{
9999
// Step 4: Configure Nginx
100100
network.ConfigureNginx()
101101

102-
// Setp 5: Create relay user
102+
// Step 5: Create relay user
103103
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Checking if '%s' user exists...", relays.User))
104104
if !users.UserExists(relays.User) {
105105
spinner.UpdateText(fmt.Sprintf("Creating '%s' user...", relays.User))
106106
users.CreateUser(relays.User, true)
107-
spinner.Success(fmt.Sprintf("Created '%s' user.", relays.User))
107+
spinner.Success(fmt.Sprintf("Created '%s' user", relays.User))
108108
} else {
109-
spinner.Success(fmt.Sprintf("'%s' user already exists.", relays.User))
109+
spinner.Success(fmt.Sprintf("'%s' user already exists", relays.User))
110110
}
111111

112112
if selectedRelayOption == khatru_pyramid.RelayName {
@@ -123,10 +123,16 @@ var installCmd = &cobra.Command{
123123
// Step 9: Download and install the relay binary
124124
khatru_pyramid.InstallRelayBinary(pubKey)
125125

126-
// Step 10: Set up the relay service
127-
khatru_pyramid.SetupRelayService(relayDomain, pubKey, relayContact)
126+
// Step 10: Set up the relay data directory
127+
khatru_pyramid.SetUpRelayDataDir()
128128

129-
// Step 11: Show success messages
129+
// Step 11: Configure the relay
130+
khatru_pyramid.ConfigureRelay(relayDomain, pubKey, relayContact)
131+
132+
// Step 12: Set up the relay service
133+
khatru_pyramid.SetUpRelayService()
134+
135+
// Step 13: Show success messages
130136
khatru_pyramid.SuccessMessages(relayDomain, httpsEnabled)
131137
} else if selectedRelayOption == nostr_rs_relay.RelayName {
132138
// Step 6: Configure Nginx for HTTP
@@ -142,10 +148,16 @@ var installCmd = &cobra.Command{
142148
// Step 9: Download and install the relay binary
143149
nostr_rs_relay.InstallRelayBinary()
144150

145-
// Step 10: Set up the relay service
146-
nostr_rs_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
151+
// Step 10: Set up the relay data directory
152+
nostr_rs_relay.SetUpRelayDataDir()
153+
154+
// Step 11: Configure the relay
155+
nostr_rs_relay.ConfigureRelay(relayDomain, pubKey, relayContact, httpsEnabled)
156+
157+
// Step 12: Set up the relay service
158+
nostr_rs_relay.SetUpRelayService()
147159

148-
// Step 11: Show success messages
160+
// Step 13: Show success messages
149161
nostr_rs_relay.SuccessMessages(relayDomain, httpsEnabled)
150162
} else if selectedRelayOption == strfry.RelayName {
151163
// Step 6: Configure Nginx for HTTP
@@ -161,10 +173,16 @@ var installCmd = &cobra.Command{
161173
// Step 9: Download and install the relay binary
162174
strfry.InstallRelayBinary()
163175

164-
// Step 10: Set up the relay service
165-
strfry.SetupRelayService(relayDomain, pubKey, relayContact)
176+
// Step 10: Set up the relay data directory
177+
strfry.SetUpRelayDataDir()
166178

167-
// Step 11: Show success messages
179+
// Step 11: Configure the relay
180+
strfry.ConfigureRelay(pubKey, relayContact)
181+
182+
// Step 12: Set up the relay service
183+
strfry.SetUpRelayService()
184+
185+
// Step 13: Show success messages
168186
strfry.SuccessMessages(relayDomain, httpsEnabled)
169187
} else if selectedRelayOption == wot_relay.RelayName {
170188
// Step 6: Configure Nginx for HTTP
@@ -180,10 +198,19 @@ var installCmd = &cobra.Command{
180198
// Step 9: Download and install the relay binary
181199
wot_relay.InstallRelayBinary(pubKey)
182200

183-
// Step 10: Set up the relay service
184-
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
201+
// Step 10: Set up the relay data directory
202+
wot_relay.SetUpRelayDataDir()
203+
204+
// Step 11: Configure the relay
205+
wot_relay.ConfigureRelay(relayDomain, pubKey, relayContact, httpsEnabled)
185206

186-
// Step 11: Show success messages
207+
// Step 12: Set up the relay site
208+
wot_relay.SetUpRelaySite(relayDomain)
209+
210+
// Step 13: Set up the relay service
211+
wot_relay.SetUpRelayService()
212+
213+
// Step 14: Show success messages
187214
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
188215
} else if selectedRelayOption == khatru29.RelayName {
189216
// Step 6: Configure Nginx for HTTP
@@ -199,10 +226,16 @@ var installCmd = &cobra.Command{
199226
// Step 9: Download and install the relay binary
200227
khatru29.InstallRelayBinary()
201228

202-
// Step 10: Set up the relay service
203-
khatru29.SetupRelayService(relayDomain, privKey, relayContact)
229+
// Step 10: Set up the relay data directory
230+
khatru29.SetUpRelayDataDir()
231+
232+
// Step 11: Configure the relay
233+
khatru29.ConfigureRelay(relayDomain, privKey, relayContact)
204234

205-
// Step 11: Show success messages
235+
// Step 12: Set up the relay service
236+
khatru29.SetUpRelayService()
237+
238+
// Step 13: Show success messages
206239
khatru29.SuccessMessages(relayDomain, httpsEnabled)
207240
} else if selectedRelayOption == strfry29.RelayName {
208241
// Step 6: Configure Nginx for HTTP
@@ -218,10 +251,16 @@ var installCmd = &cobra.Command{
218251
// Step 9: Download and install the relay binary
219252
strfry29.InstallRelayBinary()
220253

221-
// Step 10: Set up the relay service
222-
strfry29.SetupRelayService(relayDomain, pubKey, privKey, relayContact)
254+
// Step 10: Set up the relay data directory
255+
strfry29.SetUpRelayDataDir()
256+
257+
// Step 11: Configure the relay
258+
strfry29.ConfigureRelay(relayDomain, pubKey, privKey, relayContact)
259+
260+
// Step 12: Set up the relay service
261+
strfry29.SetUpRelayService()
223262

224-
// Step 11: Show success messages
263+
// Step 13: Show success messages
225264
strfry29.SuccessMessages(relayDomain, httpsEnabled)
226265
}
227266

pkg/manager/apt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ func AptInstallPackages(selectedRelayOption string) {
6666
}
6767
}
6868

69-
spinner.Success("Packages updated and installed successfully.")
69+
spinner.Success("Packages updated and installed")
7070
}

pkg/network/firewall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ func ConfigureFirewall() {
4242
os.Exit(1)
4343
}
4444

45-
spinner.Success("Firewall configured successfully.")
45+
spinner.Success("Firewall configured")
4646
}

pkg/network/intrusion_detection.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func ConfigureIntrusionDetection() {
2828
os.Exit(1)
2929
}
3030

31-
spinner.Success("Intrusion detection system configured successfully.")
31+
spinner.Success("Intrusion detection system configured")
3232
}

pkg/relays/khatru29/configure.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package khatru29
2+
3+
import (
4+
"github.com/nodetec/rwz/pkg/utils/configuration"
5+
"github.com/nodetec/rwz/pkg/utils/directories"
6+
"github.com/nodetec/rwz/pkg/utils/files"
7+
"github.com/pterm/pterm"
8+
)
9+
10+
// Function to configure the relay
11+
func ConfigureRelay(domain, privKey, relayContact string) {
12+
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay...")
13+
14+
// Ensure the config directory exists and set permissions
15+
spinner.UpdateText("Creating config directory...")
16+
directories.CreateDirectory(ConfigDirPath, 0755)
17+
18+
// Check if the environment file exists and remove it if it does
19+
files.RemoveFile(EnvFilePath)
20+
21+
// Create the environment file
22+
spinner.UpdateText("Creating environment file...")
23+
envFileParams := configuration.EnvFileParams{Domain: domain, PrivKey: privKey, RelayContact: relayContact}
24+
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)
25+
26+
// Set permissions for the environment file
27+
files.SetPermissions(EnvFilePath, 0600)
28+
29+
spinner.Success("Relay configured")
30+
}

pkg/relays/khatru29/data_dir.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package khatru29
2+
3+
import (
4+
"github.com/nodetec/rwz/pkg/relays"
5+
"github.com/nodetec/rwz/pkg/utils/directories"
6+
"github.com/pterm/pterm"
7+
)
8+
9+
// Function to set up the relay data directory
10+
func SetUpRelayDataDir() {
11+
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay data directory...")
12+
13+
// Ensure the data directory exists and set permissions
14+
spinner.UpdateText("Creating data directory...")
15+
directories.CreateDirectory(DataDirPath, 0755)
16+
17+
// Use chown command to set ownership of the data directory to the nostr user
18+
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
19+
20+
spinner.Success("Data directory set up")
21+
}

pkg/relays/khatru29/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ func InstallRelayBinary() {
4848
// Make the file executable
4949
files.SetPermissions(destPath, 0755)
5050

51-
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
51+
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
5252
}

pkg/relays/khatru29/service.go

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
11
package khatru29
22

33
import (
4-
"github.com/nodetec/rwz/pkg/relays"
5-
"github.com/nodetec/rwz/pkg/utils/configuration"
6-
"github.com/nodetec/rwz/pkg/utils/directories"
74
"github.com/nodetec/rwz/pkg/utils/files"
85
"github.com/nodetec/rwz/pkg/utils/systemd"
96
"github.com/pterm/pterm"
107
)
118

129
// Function to set up the relay service
13-
func SetupRelayService(domain, privKey, relayContact string) {
10+
func SetUpRelayService() {
1411
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay service...")
1512

16-
// Ensure the data directory exists and set permissions
17-
spinner.UpdateText("Creating data directory...")
18-
directories.CreateDirectory(DataDirPath, 0755)
19-
20-
// Use chown command to set ownership of the data directory to the nostr user
21-
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
22-
23-
// Ensure the config directory exists and set permissions
24-
spinner.UpdateText("Creating config directory...")
25-
directories.CreateDirectory(ConfigDirPath, 0755)
26-
27-
// Check if the environment file exists and remove it if it does
28-
files.RemoveFile(EnvFilePath)
29-
3013
// Check if the service file exists and remove it if it does
3114
files.RemoveFile(ServiceFilePath)
3215

33-
// Create the environment file
34-
spinner.UpdateText("Creating environment file...")
35-
envFileParams := configuration.EnvFileParams{Domain: domain, PrivKey: privKey, RelayContact: relayContact}
36-
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)
37-
38-
// Set permissions for the environment file
39-
files.SetPermissions(EnvFilePath, 0600)
40-
4116
// Create the systemd service file
4217
spinner.UpdateText("Creating service file...")
4318
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
@@ -52,5 +27,5 @@ func SetupRelayService(domain, privKey, relayContact string) {
5227
systemd.EnableService(ServiceName)
5328
systemd.StartService(ServiceName)
5429

55-
spinner.Success("Nostr relay service configured")
30+
spinner.Success("Relay service enabled and started")
5631
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package khatru_pyramid
2+
3+
import (
4+
"github.com/nodetec/rwz/pkg/utils/configuration"
5+
"github.com/nodetec/rwz/pkg/utils/directories"
6+
"github.com/nodetec/rwz/pkg/utils/files"
7+
"github.com/pterm/pterm"
8+
)
9+
10+
// Function to configure the relay
11+
func ConfigureRelay(domain, pubKey, relayContact string) {
12+
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay...")
13+
14+
// Ensure the config directory exists and set permissions
15+
spinner.UpdateText("Creating config directory...")
16+
directories.CreateDirectory(ConfigDirPath, 0755)
17+
18+
// Check if the environment file exists and remove it if it does
19+
files.RemoveFile(EnvFilePath)
20+
21+
// Create the environment file
22+
spinner.UpdateText("Creating environment file...")
23+
envFileParams := configuration.EnvFileParams{Domain: domain, PubKey: pubKey, RelayContact: relayContact}
24+
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)
25+
26+
// Set permissions for the environment file
27+
files.SetPermissions(EnvFilePath, 0644)
28+
29+
spinner.Success("Relay configured")
30+
}

pkg/relays/khatru_pyramid/data_dir.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package khatru_pyramid
2+
3+
import (
4+
"github.com/nodetec/rwz/pkg/relays"
5+
"github.com/nodetec/rwz/pkg/utils/directories"
6+
"github.com/pterm/pterm"
7+
)
8+
9+
// Function to set up the relay data directory
10+
func SetUpRelayDataDir() {
11+
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay data directory...")
12+
13+
// Ensure the data directory exists and set permissions
14+
spinner.UpdateText("Creating data directory...")
15+
directories.CreateDirectory(DataDirPath, 0755)
16+
17+
// Use chown command to set ownership of the data directory to the nostr user
18+
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
19+
20+
spinner.Success("Data directory set up")
21+
}

pkg/relays/khatru_pyramid/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ func InstallRelayBinary(pubKey string) {
6464
// Make the file executable
6565
files.SetPermissions(destPath, 0755)
6666

67-
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
67+
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
6868
}

pkg/relays/khatru_pyramid/service.go

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
11
package khatru_pyramid
22

33
import (
4-
"github.com/nodetec/rwz/pkg/relays"
5-
"github.com/nodetec/rwz/pkg/utils/configuration"
6-
"github.com/nodetec/rwz/pkg/utils/directories"
74
"github.com/nodetec/rwz/pkg/utils/files"
85
"github.com/nodetec/rwz/pkg/utils/systemd"
96
"github.com/pterm/pterm"
107
)
118

129
// Function to set up the relay service
13-
func SetupRelayService(domain, pubKey, relayContact string) {
10+
func SetUpRelayService() {
1411
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay service...")
1512

16-
// Ensure the data directory exists and set permissions
17-
spinner.UpdateText("Creating data directory...")
18-
directories.CreateDirectory(DataDirPath, 0755)
19-
20-
// Use chown command to set ownership of the data directory to the nostr user
21-
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
22-
23-
// Ensure the config directory exists and set permissions
24-
spinner.UpdateText("Creating config directory...")
25-
directories.CreateDirectory(ConfigDirPath, 0755)
26-
27-
// Check if the environment file exists and remove it if it does
28-
files.RemoveFile(EnvFilePath)
29-
3013
// Check if the service file exists and remove it if it does
3114
files.RemoveFile(ServiceFilePath)
3215

33-
// Create the environment file
34-
spinner.UpdateText("Creating environment file...")
35-
envFileParams := configuration.EnvFileParams{Domain: domain, PubKey: pubKey, RelayContact: relayContact}
36-
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)
37-
38-
// Set permissions for the environment file
39-
files.SetPermissions(EnvFilePath, 0644)
40-
4116
// Create the systemd service file
4217
spinner.UpdateText("Creating service file...")
4318
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
@@ -52,5 +27,5 @@ func SetupRelayService(domain, pubKey, relayContact string) {
5227
systemd.EnableService(ServiceName)
5328
systemd.StartService(ServiceName)
5429

55-
spinner.Success("Nostr relay service configured")
30+
spinner.Success("Relay service enabled and started")
5631
}

0 commit comments

Comments
 (0)