Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor relay service files and update success messages #71

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 60 additions & 21 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ var installCmd = &cobra.Command{
// Step 4: Configure Nginx
network.ConfigureNginx()

// Setp 5: Create relay user
// Step 5: Create relay user
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Checking if '%s' user exists...", relays.User))
if !users.UserExists(relays.User) {
spinner.UpdateText(fmt.Sprintf("Creating '%s' user...", relays.User))
users.CreateUser(relays.User, true)
spinner.Success(fmt.Sprintf("Created '%s' user.", relays.User))
spinner.Success(fmt.Sprintf("Created '%s' user", relays.User))
} else {
spinner.Success(fmt.Sprintf("'%s' user already exists.", relays.User))
spinner.Success(fmt.Sprintf("'%s' user already exists", relays.User))
}

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

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

// Step 11: Show success messages
// Step 11: Configure the relay
khatru_pyramid.ConfigureRelay(relayDomain, pubKey, relayContact)

// Step 12: Set up the relay service
khatru_pyramid.SetUpRelayService()

// Step 13: Show success messages
khatru_pyramid.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == nostr_rs_relay.RelayName {
// Step 6: Configure Nginx for HTTP
Expand All @@ -142,10 +148,16 @@ var installCmd = &cobra.Command{
// Step 9: Download and install the relay binary
nostr_rs_relay.InstallRelayBinary()

// Step 10: Set up the relay service
nostr_rs_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
// Step 10: Set up the relay data directory
nostr_rs_relay.SetUpRelayDataDir()

// Step 11: Configure the relay
nostr_rs_relay.ConfigureRelay(relayDomain, pubKey, relayContact, httpsEnabled)

// Step 12: Set up the relay service
nostr_rs_relay.SetUpRelayService()

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

// Step 10: Set up the relay service
strfry.SetupRelayService(relayDomain, pubKey, relayContact)
// Step 10: Set up the relay data directory
strfry.SetUpRelayDataDir()

// Step 11: Show success messages
// Step 11: Configure the relay
strfry.ConfigureRelay(pubKey, relayContact)

// Step 12: Set up the relay service
strfry.SetUpRelayService()

// Step 13: Show success messages
strfry.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == wot_relay.RelayName {
// Step 6: Configure Nginx for HTTP
Expand All @@ -180,10 +198,19 @@ var installCmd = &cobra.Command{
// Step 9: Download and install the relay binary
wot_relay.InstallRelayBinary(pubKey)

// Step 10: Set up the relay service
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
// Step 10: Set up the relay data directory
wot_relay.SetUpRelayDataDir()

// Step 11: Configure the relay
wot_relay.ConfigureRelay(relayDomain, pubKey, relayContact, httpsEnabled)

// Step 11: Show success messages
// Step 12: Set up the relay site
wot_relay.SetUpRelaySite(relayDomain)

// Step 13: Set up the relay service
wot_relay.SetUpRelayService()

// Step 14: Show success messages
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == khatru29.RelayName {
// Step 6: Configure Nginx for HTTP
Expand All @@ -199,10 +226,16 @@ var installCmd = &cobra.Command{
// Step 9: Download and install the relay binary
khatru29.InstallRelayBinary()

// Step 10: Set up the relay service
khatru29.SetupRelayService(relayDomain, privKey, relayContact)
// Step 10: Set up the relay data directory
khatru29.SetUpRelayDataDir()

// Step 11: Configure the relay
khatru29.ConfigureRelay(relayDomain, privKey, relayContact)

// Step 11: Show success messages
// Step 12: Set up the relay service
khatru29.SetUpRelayService()

// Step 13: Show success messages
khatru29.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == strfry29.RelayName {
// Step 6: Configure Nginx for HTTP
Expand All @@ -218,10 +251,16 @@ var installCmd = &cobra.Command{
// Step 9: Download and install the relay binary
strfry29.InstallRelayBinary()

// Step 10: Set up the relay service
strfry29.SetupRelayService(relayDomain, pubKey, privKey, relayContact)
// Step 10: Set up the relay data directory
strfry29.SetUpRelayDataDir()

// Step 11: Configure the relay
strfry29.ConfigureRelay(relayDomain, pubKey, privKey, relayContact)

// Step 12: Set up the relay service
strfry29.SetUpRelayService()

// Step 11: Show success messages
// Step 13: Show success messages
strfry29.SuccessMessages(relayDomain, httpsEnabled)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ func AptInstallPackages(selectedRelayOption string) {
}
}

spinner.Success("Packages updated and installed successfully.")
spinner.Success("Packages updated and installed")
}
2 changes: 1 addition & 1 deletion pkg/network/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func ConfigureFirewall() {
os.Exit(1)
}

spinner.Success("Firewall configured successfully.")
spinner.Success("Firewall configured")
}
2 changes: 1 addition & 1 deletion pkg/network/intrusion_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func ConfigureIntrusionDetection() {
os.Exit(1)
}

spinner.Success("Intrusion detection system configured successfully.")
spinner.Success("Intrusion detection system configured")
}
30 changes: 30 additions & 0 deletions pkg/relays/khatru29/configure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package khatru29

import (
"github.com/nodetec/rwz/pkg/utils/configuration"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/pterm/pterm"
)

// Function to configure the relay
func ConfigureRelay(domain, privKey, relayContact string) {
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay...")

// Ensure the config directory exists and set permissions
spinner.UpdateText("Creating config directory...")
directories.CreateDirectory(ConfigDirPath, 0755)

// Check if the environment file exists and remove it if it does
files.RemoveFile(EnvFilePath)

// Create the environment file
spinner.UpdateText("Creating environment file...")
envFileParams := configuration.EnvFileParams{Domain: domain, PrivKey: privKey, RelayContact: relayContact}
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)

// Set permissions for the environment file
files.SetPermissions(EnvFilePath, 0600)

spinner.Success("Relay configured")
}
21 changes: 21 additions & 0 deletions pkg/relays/khatru29/data_dir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package khatru29

import (
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/pterm/pterm"
)

// Function to set up the relay data directory
func SetUpRelayDataDir() {
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay data directory...")

// Ensure the data directory exists and set permissions
spinner.UpdateText("Creating data directory...")
directories.CreateDirectory(DataDirPath, 0755)

// Use chown command to set ownership of the data directory to the nostr user
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)

spinner.Success("Data directory set up")
}
2 changes: 1 addition & 1 deletion pkg/relays/khatru29/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
}
29 changes: 2 additions & 27 deletions pkg/relays/khatru29/service.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
package khatru29

import (
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/configuration"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/nodetec/rwz/pkg/utils/systemd"
"github.com/pterm/pterm"
)

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

// Ensure the data directory exists and set permissions
spinner.UpdateText("Creating data directory...")
directories.CreateDirectory(DataDirPath, 0755)

// Use chown command to set ownership of the data directory to the nostr user
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)

// Ensure the config directory exists and set permissions
spinner.UpdateText("Creating config directory...")
directories.CreateDirectory(ConfigDirPath, 0755)

// Check if the environment file exists and remove it if it does
files.RemoveFile(EnvFilePath)

// Check if the service file exists and remove it if it does
files.RemoveFile(ServiceFilePath)

// Create the environment file
spinner.UpdateText("Creating environment file...")
envFileParams := configuration.EnvFileParams{Domain: domain, PrivKey: privKey, RelayContact: relayContact}
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)

// Set permissions for the environment file
files.SetPermissions(EnvFilePath, 0600)

// Create the systemd service file
spinner.UpdateText("Creating service file...")
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
Expand All @@ -52,5 +27,5 @@ func SetupRelayService(domain, privKey, relayContact string) {
systemd.EnableService(ServiceName)
systemd.StartService(ServiceName)

spinner.Success("Nostr relay service configured")
spinner.Success("Relay service enabled and started")
}
30 changes: 30 additions & 0 deletions pkg/relays/khatru_pyramid/configure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package khatru_pyramid

import (
"github.com/nodetec/rwz/pkg/utils/configuration"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/pterm/pterm"
)

// Function to configure the relay
func ConfigureRelay(domain, pubKey, relayContact string) {
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay...")

// Ensure the config directory exists and set permissions
spinner.UpdateText("Creating config directory...")
directories.CreateDirectory(ConfigDirPath, 0755)

// Check if the environment file exists and remove it if it does
files.RemoveFile(EnvFilePath)

// Create the environment file
spinner.UpdateText("Creating environment file...")
envFileParams := configuration.EnvFileParams{Domain: domain, PubKey: pubKey, RelayContact: relayContact}
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)

// Set permissions for the environment file
files.SetPermissions(EnvFilePath, 0644)

spinner.Success("Relay configured")
}
21 changes: 21 additions & 0 deletions pkg/relays/khatru_pyramid/data_dir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package khatru_pyramid

import (
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/pterm/pterm"
)

// Function to set up the relay data directory
func SetUpRelayDataDir() {
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay data directory...")

// Ensure the data directory exists and set permissions
spinner.UpdateText("Creating data directory...")
directories.CreateDirectory(DataDirPath, 0755)

// Use chown command to set ownership of the data directory to the nostr user
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)

spinner.Success("Data directory set up")
}
2 changes: 1 addition & 1 deletion pkg/relays/khatru_pyramid/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ func InstallRelayBinary(pubKey string) {
// Make the file executable
files.SetPermissions(destPath, 0755)

spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
spinner.Success(fmt.Sprintf("%s relay binary downloaded and installed", RelayName))
}
29 changes: 2 additions & 27 deletions pkg/relays/khatru_pyramid/service.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
package khatru_pyramid

import (
"github.com/nodetec/rwz/pkg/relays"
"github.com/nodetec/rwz/pkg/utils/configuration"
"github.com/nodetec/rwz/pkg/utils/directories"
"github.com/nodetec/rwz/pkg/utils/files"
"github.com/nodetec/rwz/pkg/utils/systemd"
"github.com/pterm/pterm"
)

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

// Ensure the data directory exists and set permissions
spinner.UpdateText("Creating data directory...")
directories.CreateDirectory(DataDirPath, 0755)

// Use chown command to set ownership of the data directory to the nostr user
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)

// Ensure the config directory exists and set permissions
spinner.UpdateText("Creating config directory...")
directories.CreateDirectory(ConfigDirPath, 0755)

// Check if the environment file exists and remove it if it does
files.RemoveFile(EnvFilePath)

// Check if the service file exists and remove it if it does
files.RemoveFile(ServiceFilePath)

// Create the environment file
spinner.UpdateText("Creating environment file...")
envFileParams := configuration.EnvFileParams{Domain: domain, PubKey: pubKey, RelayContact: relayContact}
configuration.CreateEnvFile(EnvFilePath, EnvFileTemplate, &envFileParams)

// Set permissions for the environment file
files.SetPermissions(EnvFilePath, 0644)

// Create the systemd service file
spinner.UpdateText("Creating service file...")
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
Expand All @@ -52,5 +27,5 @@ func SetupRelayService(domain, pubKey, relayContact string) {
systemd.EnableService(ServiceName)
systemd.StartService(ServiceName)

spinner.Success("Nostr relay service configured")
spinner.Success("Relay service enabled and started")
}
Loading
Loading