Skip to content

Commit

Permalink
feat: add nostr-rs-relay, check for git package, and add network utils (
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiarulli authored Oct 5, 2024
1 parent 0938446 commit c8c12be
Show file tree
Hide file tree
Showing 29 changed files with 526 additions and 80 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,55 @@ If you prefer to manually verify the authenticity of the Relay Wizard binary bef

#### Arch

```sh
```bash
sudo pacman -S gnupg
```

#### Debian/Ubuntu

```sh
```bash
sudo apt install -y gnupg
```

### curl

#### Arch

```sh
```bash
sudo pacman -S curl
```

#### Debian/Ubuntu

```sh
```bash
sudo apt install -y curl
```

Now you need to import the public key that signed the manifest file which you can do by running the following command:

```sh
```bash
curl https://keybase.io/nodetec/pgp_keys.asc | gpg --import
```

You're now ready to verify the manifest file. You will need to have the `rwz-x.x.x-manifest.sha512sum` and the `rwz-x.x.x-manifest.sha512sum.asc` files in the same directory as the Relay Wizard binary you downloaded where the `x.x.x` is replaced by whatever version of `rwz` you're verifying.

To verify the manifest file run the following command:

```sh
```bash
gpg --verify rwz-x.x.x-manifest.sha512sum.asc
```

Here's the command to run for the latest version of `rwz`:

```sh
gpg --verify rwz-0.3.0-alpha2-manifest.sha512sum.asc
```bash
gpg --verify rwz-0.3.0-alpha3-manifest.sha512sum.asc
```

You should see output similar to the following if the verification was successful:

```sh
gpg: assuming signed data in 'rwz-0.3.0-alpha2-manifest.sha512sum'
gpg: Signature made Thu 03 Oct 2024 07:40:12 PM UTC
```bash
gpg: assuming signed data in 'rwz-0.3.0-alpha3-manifest.sha512sum'
gpg: Signature made Sat 05 Oct 2024 10:05:41 AM UTC
gpg: using RSA key 252F57B9DCD920EBF14E6151A8841CC4D10CC288
gpg: Good signature from "NODE-TEC Devs <[email protected]>" [unknown]
gpg: aka "[jpeg image of size 5143]" [unknown]
Expand All @@ -104,7 +104,7 @@ Primary key fingerprint: 04BD 8C20 598F A5FD DE19 BECD 8F24 69F7 1314 FAD7

> Unless you tell GnuPG to trust the key, you'll see a warning similar to the following:
```sh
```bash
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
```
Expand All @@ -117,20 +117,20 @@ You have now verified the signature of the manifest file which ensures the integ

To verify the binary you'll need to recompute the SHA512 hash of the file, compare it with the corresponding hash in the manifest file, and ensure they match exactly which you can do by running the following command:

```sh
```bash
sha512sum --check rwz-x.x.x-manifest.sha512sum
```

Here's the command to run for the latest version of `rwz`:

```sh
sha512sum --check rwz-0.3.0-alpha2-manifest.sha512sum
```bash
sha512sum --check rwz-0.3.0-alpha3-manifest.sha512sum
```

If the verification was successful you should see the output similar to the following:

```sh
rwz-0.3.0-alpha2-x86_64-linux-gnu.tar.gz: OK
```bash
rwz-0.3.0-alpha3-x86_64-linux-gnu.tar.gz: OK
```

By completing the above steps you will have successfully verified the integrity of the binary.
Expand Down
79 changes: 56 additions & 23 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/nodetec/rwz/pkg/network"
"github.com/nodetec/rwz/pkg/relays/khatru29"
"github.com/nodetec/rwz/pkg/relays/khatru_pyramid"
"github.com/nodetec/rwz/pkg/relays/nostr_rs_relay"
"github.com/nodetec/rwz/pkg/relays/strfry"
"github.com/nodetec/rwz/pkg/relays/strfry29"
"github.com/nodetec/rwz/pkg/relays/wot_relay"
Expand All @@ -18,25 +19,38 @@ var installCmd = &cobra.Command{
Short: "Install and configure your Nostr relay",
Long: `Install and configure your Nostr relay, including package installation, firewall setup, Nginx configuration, SSL/TLS certificates, and starting the relay service.`,
Run: func(cmd *cobra.Command, args []string) {
ThemeDefault := pterm.ThemeDefault

ui.Greet()

relayDomain, _ := pterm.DefaultInteractiveTextInput.Show("Relay domain name")
pterm.Println()

// Supported relay options
options := []string{khatru_pyramid.RelayName, strfry.RelayName, khatru29.RelayName, strfry29.RelayName, wot_relay.RelayName}
options := []string{khatru_pyramid.RelayName, nostr_rs_relay.RelayName, strfry.RelayName, wot_relay.RelayName, khatru29.RelayName, strfry29.RelayName}

// Use PTerm's interactive select feature to present the options to the user and capture their selection
// The Show() method displays the options and waits for the user's input
selectedRelayOption, _ := pterm.DefaultInteractiveSelect.WithOptions(options).Show()
relaySelector := pterm.InteractiveSelectPrinter{
TextStyle: &ThemeDefault.PrimaryStyle,
DefaultText: "Please select an option",
Options: []string{},
OptionStyle: &ThemeDefault.DefaultText,
DefaultOption: "",
MaxHeight: 6,
Selector: ">",
SelectorStyle: &ThemeDefault.SecondaryStyle,
Filter: true,
}

selectedRelayOption, _ := relaySelector.WithOptions(options).Show()

// Display the selected option to the user with a green color for emphasis
pterm.Info.Printfln("Selected option: %s", pterm.Green(selectedRelayOption))

var privKey string
var pubKey string
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == wot_relay.RelayName {
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == wot_relay.RelayName {
pterm.Println()
pubKey, _ = pterm.DefaultInteractiveTextInput.Show("Public key (hex not npub)")
} else if selectedRelayOption == khatru29.RelayName || selectedRelayOption == strfry29.RelayName {
Expand All @@ -46,7 +60,7 @@ var installCmd = &cobra.Command{
}

var relayContact string
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == khatru29.RelayName {
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == khatru29.RelayName {
pterm.Println()
pterm.Println(pterm.Yellow("Leave email empty if you don't want to provide relay contact information."))

Expand All @@ -65,7 +79,7 @@ var installCmd = &cobra.Command{
pterm.Println()

// Step 1: Install necessary packages using APT
manager.AptInstallPackages()
manager.AptInstallPackages(selectedRelayOption)

// Step 2: Configure the firewall
network.ConfigureFirewall()
Expand All @@ -89,6 +103,25 @@ var installCmd = &cobra.Command{

// Step 8: Show success messages
khatru_pyramid.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == nostr_rs_relay.RelayName {
// Step 3: Configure Nginx for HTTP
nostr_rs_relay.ConfigureNginxHttp(relayDomain)

// Step 4: Get SSL/TLS certificates
httpsEnabled := network.GetCertificates(relayDomain)
if httpsEnabled {
// Step 5: Configure Nginx for HTTPS
nostr_rs_relay.ConfigureNginxHttps(relayDomain)
}

// Step 6: Download and install the relay binary
nostr_rs_relay.InstallRelayBinary()

// Step 7: Set up the relay service
nostr_rs_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)

// Step 8: Show success messages
nostr_rs_relay.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == strfry.RelayName {
// Step 3: Configure Nginx for HTTP
strfry.ConfigureNginxHttp(relayDomain)
Expand All @@ -108,63 +141,63 @@ var installCmd = &cobra.Command{

// Step 8: Show success messages
strfry.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == khatru29.RelayName {
} else if selectedRelayOption == wot_relay.RelayName {
// Step 3: Configure Nginx for HTTP
khatru29.ConfigureNginxHttp(relayDomain)
wot_relay.ConfigureNginxHttp(relayDomain)

// Step 4: Get SSL/TLS certificates
httpsEnabled := network.GetCertificates(relayDomain)
if httpsEnabled {
// Step 5: Configure Nginx for HTTPS
khatru29.ConfigureNginxHttps(relayDomain)
wot_relay.ConfigureNginxHttps(relayDomain)
}

// Step 6: Download and install the relay binary
khatru29.InstallRelayBinary()
wot_relay.InstallRelayBinary()

// Step 7: Set up the relay service
khatru29.SetupRelayService(relayDomain, privKey, relayContact)
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)

// Step 8: Show success messages
khatru29.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == strfry29.RelayName {
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == khatru29.RelayName {
// Step 3: Configure Nginx for HTTP
strfry29.ConfigureNginxHttp(relayDomain)
khatru29.ConfigureNginxHttp(relayDomain)

// Step 4: Get SSL/TLS certificates
httpsEnabled := network.GetCertificates(relayDomain)
if httpsEnabled {
// Step 5: Configure Nginx for HTTPS
strfry29.ConfigureNginxHttps(relayDomain)
khatru29.ConfigureNginxHttps(relayDomain)
}

// Step 6: Download and install the relay binary
strfry29.InstallRelayBinary()
khatru29.InstallRelayBinary()

// Step 7: Set up the relay service
strfry29.SetupRelayService(relayDomain, privKey)
khatru29.SetupRelayService(relayDomain, privKey, relayContact)

// Step 8: Show success messages
strfry29.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == wot_relay.RelayName {
khatru29.SuccessMessages(relayDomain, httpsEnabled)
} else if selectedRelayOption == strfry29.RelayName {
// Step 3: Configure Nginx for HTTP
wot_relay.ConfigureNginxHttp(relayDomain)
strfry29.ConfigureNginxHttp(relayDomain)

// Step 4: Get SSL/TLS certificates
httpsEnabled := network.GetCertificates(relayDomain)
if httpsEnabled {
// Step 5: Configure Nginx for HTTPS
wot_relay.ConfigureNginxHttps(relayDomain)
strfry29.ConfigureNginxHttps(relayDomain)
}

// Step 6: Download and install the relay binary
wot_relay.InstallRelayBinary()
strfry29.InstallRelayBinary()

// Step 7: Set up the relay service
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
strfry29.SetupRelayService(relayDomain, privKey)

// Step 8: Show success messages
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
strfry29.SuccessMessages(relayDomain, httpsEnabled)
}

pterm.Println()
Expand Down
15 changes: 13 additions & 2 deletions pkg/manager/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package manager

import (
"fmt"
"github.com/nodetec/rwz/pkg/relays/nostr_rs_relay"
"github.com/nodetec/rwz/pkg/relays/strfry"
"github.com/nodetec/rwz/pkg/relays/strfry29"
"github.com/pterm/pterm"
"os"
"os/exec"
Expand Down Expand Up @@ -36,12 +39,20 @@ func IsPackageInstalled(packageName string) bool {
}

// Function to install necessary packages
func AptInstallPackages() {
func AptInstallPackages(selectedRelayOption string) {
spinner, _ := pterm.DefaultSpinner.Start("Updating and installing packages...")

exec.Command("apt", "update", "-qq").Run()

packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban"}
packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban", "git"}

if selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == strfry29.RelayName {
packages = append(packages, "git")
}

if selectedRelayOption == nostr_rs_relay.RelayName {
packages = append(packages, "sqlite3", "libsqlite3-dev")
}

// Check if package is installed, install if not
for _, p := range packages {
Expand Down
2 changes: 1 addition & 1 deletion pkg/relays/khatru29/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package khatru29

const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.3.0/relay29-0.4.0-khatru29-x86_64-linux-gnu.tar.gz"
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/relay29-0.4.0-khatru29-x86_64-linux-gnu.tar.gz"
const BinaryName = "khatru29"
const BinaryFilePath = "/usr/local/bin/khatru29"
const NginxConfigFilePath = "/etc/nginx/conf.d/khatru29.conf"
Expand Down
4 changes: 2 additions & 2 deletions pkg/relays/khatru29/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary() {
spinner, _ := pterm.DefaultSpinner.Start("Installing Khatru29 relay...")
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))

// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
Expand All @@ -37,5 +37,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

spinner.Success("Khatru29 relay installed successfully.")
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
}
2 changes: 1 addition & 1 deletion pkg/relays/khatru29/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ server {
# Add support to generate the file in the script
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_protocols TLSv1.3 TLSv1.2;
# For more information on the security of different cipher suites, you can refer to the following link:
# https://ciphersuite.info/
Expand Down
2 changes: 1 addition & 1 deletion pkg/relays/khatru_pyramid/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package khatru_pyramid

const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.3.0/khatru-pyramid-0.1.0-x86_64-linux-gnu.tar.gz"
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/khatru-pyramid-0.1.0-x86_64-linux-gnu.tar.gz"
const BinaryName = "khatru-pyramid"
const BinaryFilePath = "/usr/local/bin/khatru-pyramid"
const NginxConfigFilePath = "/etc/nginx/conf.d/khatru_pyramid.conf"
Expand Down
4 changes: 2 additions & 2 deletions pkg/relays/khatru_pyramid/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Function to download and make the binary executable
func InstallRelayBinary() {
spinner, _ := pterm.DefaultSpinner.Start("Installing Khatru Pyramid relay...")
spinner, _ := pterm.DefaultSpinner.Start(fmt.Sprintf("Installing %s relay...", RelayName))

// Determine the file name from the URL
tmpFileName := filepath.Base(DownloadURL)
Expand All @@ -37,5 +37,5 @@ func InstallRelayBinary() {
// Make the file executable
files.SetPermissions(destPath, 0755)

spinner.Success("Khatru Pyramid relay installed successfully.")
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
}
2 changes: 1 addition & 1 deletion pkg/relays/khatru_pyramid/nginx_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ server {
# Add support to generate the file in the script
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_protocols TLSv1.3 TLSv1.2;
# For more information on the security of different cipher suites, you can refer to the following link:
# https://ciphersuite.info/
Expand Down
Loading

0 comments on commit c8c12be

Please sign in to comment.