Skip to content

Commit c8c12be

Browse files
authored
feat: add nostr-rs-relay, check for git package, and add network utils (#61)
1 parent 0938446 commit c8c12be

29 files changed

+526
-80
lines changed

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -46,55 +46,55 @@ If you prefer to manually verify the authenticity of the Relay Wizard binary bef
4646

4747
#### Arch
4848

49-
```sh
49+
```bash
5050
sudo pacman -S gnupg
5151
```
5252

5353
#### Debian/Ubuntu
5454

55-
```sh
55+
```bash
5656
sudo apt install -y gnupg
5757
```
5858

5959
### curl
6060

6161
#### Arch
6262

63-
```sh
63+
```bash
6464
sudo pacman -S curl
6565
```
6666

6767
#### Debian/Ubuntu
6868

69-
```sh
69+
```bash
7070
sudo apt install -y curl
7171
```
7272

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

75-
```sh
75+
```bash
7676
curl https://keybase.io/nodetec/pgp_keys.asc | gpg --import
7777
```
7878

7979
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.
8080

8181
To verify the manifest file run the following command:
8282

83-
```sh
83+
```bash
8484
gpg --verify rwz-x.x.x-manifest.sha512sum.asc
8585
```
8686

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

89-
```sh
90-
gpg --verify rwz-0.3.0-alpha2-manifest.sha512sum.asc
89+
```bash
90+
gpg --verify rwz-0.3.0-alpha3-manifest.sha512sum.asc
9191
```
9292

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

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

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

118118
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:
119119

120-
```sh
120+
```bash
121121
sha512sum --check rwz-x.x.x-manifest.sha512sum
122122
```
123123

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

126-
```sh
127-
sha512sum --check rwz-0.3.0-alpha2-manifest.sha512sum
126+
```bash
127+
sha512sum --check rwz-0.3.0-alpha3-manifest.sha512sum
128128
```
129129

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

132-
```sh
133-
rwz-0.3.0-alpha2-x86_64-linux-gnu.tar.gz: OK
132+
```bash
133+
rwz-0.3.0-alpha3-x86_64-linux-gnu.tar.gz: OK
134134
```
135135

136136
By completing the above steps you will have successfully verified the integrity of the binary.

cmd/install.go

+56-23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/nodetec/rwz/pkg/network"
66
"github.com/nodetec/rwz/pkg/relays/khatru29"
77
"github.com/nodetec/rwz/pkg/relays/khatru_pyramid"
8+
"github.com/nodetec/rwz/pkg/relays/nostr_rs_relay"
89
"github.com/nodetec/rwz/pkg/relays/strfry"
910
"github.com/nodetec/rwz/pkg/relays/strfry29"
1011
"github.com/nodetec/rwz/pkg/relays/wot_relay"
@@ -18,25 +19,38 @@ var installCmd = &cobra.Command{
1819
Short: "Install and configure your Nostr relay",
1920
Long: `Install and configure your Nostr relay, including package installation, firewall setup, Nginx configuration, SSL/TLS certificates, and starting the relay service.`,
2021
Run: func(cmd *cobra.Command, args []string) {
22+
ThemeDefault := pterm.ThemeDefault
2123

2224
ui.Greet()
2325

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

2729
// Supported relay options
28-
options := []string{khatru_pyramid.RelayName, strfry.RelayName, khatru29.RelayName, strfry29.RelayName, wot_relay.RelayName}
30+
options := []string{khatru_pyramid.RelayName, nostr_rs_relay.RelayName, strfry.RelayName, wot_relay.RelayName, khatru29.RelayName, strfry29.RelayName}
2931

3032
// Use PTerm's interactive select feature to present the options to the user and capture their selection
3133
// The Show() method displays the options and waits for the user's input
32-
selectedRelayOption, _ := pterm.DefaultInteractiveSelect.WithOptions(options).Show()
34+
relaySelector := pterm.InteractiveSelectPrinter{
35+
TextStyle: &ThemeDefault.PrimaryStyle,
36+
DefaultText: "Please select an option",
37+
Options: []string{},
38+
OptionStyle: &ThemeDefault.DefaultText,
39+
DefaultOption: "",
40+
MaxHeight: 6,
41+
Selector: ">",
42+
SelectorStyle: &ThemeDefault.SecondaryStyle,
43+
Filter: true,
44+
}
45+
46+
selectedRelayOption, _ := relaySelector.WithOptions(options).Show()
3347

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

3751
var privKey string
3852
var pubKey string
39-
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == wot_relay.RelayName {
53+
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == wot_relay.RelayName {
4054
pterm.Println()
4155
pubKey, _ = pterm.DefaultInteractiveTextInput.Show("Public key (hex not npub)")
4256
} else if selectedRelayOption == khatru29.RelayName || selectedRelayOption == strfry29.RelayName {
@@ -46,7 +60,7 @@ var installCmd = &cobra.Command{
4660
}
4761

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

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

6781
// Step 1: Install necessary packages using APT
68-
manager.AptInstallPackages()
82+
manager.AptInstallPackages(selectedRelayOption)
6983

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

90104
// Step 8: Show success messages
91105
khatru_pyramid.SuccessMessages(relayDomain, httpsEnabled)
106+
} else if selectedRelayOption == nostr_rs_relay.RelayName {
107+
// Step 3: Configure Nginx for HTTP
108+
nostr_rs_relay.ConfigureNginxHttp(relayDomain)
109+
110+
// Step 4: Get SSL/TLS certificates
111+
httpsEnabled := network.GetCertificates(relayDomain)
112+
if httpsEnabled {
113+
// Step 5: Configure Nginx for HTTPS
114+
nostr_rs_relay.ConfigureNginxHttps(relayDomain)
115+
}
116+
117+
// Step 6: Download and install the relay binary
118+
nostr_rs_relay.InstallRelayBinary()
119+
120+
// Step 7: Set up the relay service
121+
nostr_rs_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
122+
123+
// Step 8: Show success messages
124+
nostr_rs_relay.SuccessMessages(relayDomain, httpsEnabled)
92125
} else if selectedRelayOption == strfry.RelayName {
93126
// Step 3: Configure Nginx for HTTP
94127
strfry.ConfigureNginxHttp(relayDomain)
@@ -108,63 +141,63 @@ var installCmd = &cobra.Command{
108141

109142
// Step 8: Show success messages
110143
strfry.SuccessMessages(relayDomain, httpsEnabled)
111-
} else if selectedRelayOption == khatru29.RelayName {
144+
} else if selectedRelayOption == wot_relay.RelayName {
112145
// Step 3: Configure Nginx for HTTP
113-
khatru29.ConfigureNginxHttp(relayDomain)
146+
wot_relay.ConfigureNginxHttp(relayDomain)
114147

115148
// Step 4: Get SSL/TLS certificates
116149
httpsEnabled := network.GetCertificates(relayDomain)
117150
if httpsEnabled {
118151
// Step 5: Configure Nginx for HTTPS
119-
khatru29.ConfigureNginxHttps(relayDomain)
152+
wot_relay.ConfigureNginxHttps(relayDomain)
120153
}
121154

122155
// Step 6: Download and install the relay binary
123-
khatru29.InstallRelayBinary()
156+
wot_relay.InstallRelayBinary()
124157

125158
// Step 7: Set up the relay service
126-
khatru29.SetupRelayService(relayDomain, privKey, relayContact)
159+
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
127160

128161
// Step 8: Show success messages
129-
khatru29.SuccessMessages(relayDomain, httpsEnabled)
130-
} else if selectedRelayOption == strfry29.RelayName {
162+
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
163+
} else if selectedRelayOption == khatru29.RelayName {
131164
// Step 3: Configure Nginx for HTTP
132-
strfry29.ConfigureNginxHttp(relayDomain)
165+
khatru29.ConfigureNginxHttp(relayDomain)
133166

134167
// Step 4: Get SSL/TLS certificates
135168
httpsEnabled := network.GetCertificates(relayDomain)
136169
if httpsEnabled {
137170
// Step 5: Configure Nginx for HTTPS
138-
strfry29.ConfigureNginxHttps(relayDomain)
171+
khatru29.ConfigureNginxHttps(relayDomain)
139172
}
140173

141174
// Step 6: Download and install the relay binary
142-
strfry29.InstallRelayBinary()
175+
khatru29.InstallRelayBinary()
143176

144177
// Step 7: Set up the relay service
145-
strfry29.SetupRelayService(relayDomain, privKey)
178+
khatru29.SetupRelayService(relayDomain, privKey, relayContact)
146179

147180
// Step 8: Show success messages
148-
strfry29.SuccessMessages(relayDomain, httpsEnabled)
149-
} else if selectedRelayOption == wot_relay.RelayName {
181+
khatru29.SuccessMessages(relayDomain, httpsEnabled)
182+
} else if selectedRelayOption == strfry29.RelayName {
150183
// Step 3: Configure Nginx for HTTP
151-
wot_relay.ConfigureNginxHttp(relayDomain)
184+
strfry29.ConfigureNginxHttp(relayDomain)
152185

153186
// Step 4: Get SSL/TLS certificates
154187
httpsEnabled := network.GetCertificates(relayDomain)
155188
if httpsEnabled {
156189
// Step 5: Configure Nginx for HTTPS
157-
wot_relay.ConfigureNginxHttps(relayDomain)
190+
strfry29.ConfigureNginxHttps(relayDomain)
158191
}
159192

160193
// Step 6: Download and install the relay binary
161-
wot_relay.InstallRelayBinary()
194+
strfry29.InstallRelayBinary()
162195

163196
// Step 7: Set up the relay service
164-
wot_relay.SetupRelayService(relayDomain, pubKey, relayContact, httpsEnabled)
197+
strfry29.SetupRelayService(relayDomain, privKey)
165198

166199
// Step 8: Show success messages
167-
wot_relay.SuccessMessages(relayDomain, httpsEnabled)
200+
strfry29.SuccessMessages(relayDomain, httpsEnabled)
168201
}
169202

170203
pterm.Println()

pkg/manager/apt.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package manager
22

33
import (
44
"fmt"
5+
"github.com/nodetec/rwz/pkg/relays/nostr_rs_relay"
6+
"github.com/nodetec/rwz/pkg/relays/strfry"
7+
"github.com/nodetec/rwz/pkg/relays/strfry29"
58
"github.com/pterm/pterm"
69
"os"
710
"os/exec"
@@ -36,12 +39,20 @@ func IsPackageInstalled(packageName string) bool {
3639
}
3740

3841
// Function to install necessary packages
39-
func AptInstallPackages() {
42+
func AptInstallPackages(selectedRelayOption string) {
4043
spinner, _ := pterm.DefaultSpinner.Start("Updating and installing packages...")
4144

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

44-
packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban"}
47+
packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban", "git"}
48+
49+
if selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == strfry29.RelayName {
50+
packages = append(packages, "git")
51+
}
52+
53+
if selectedRelayOption == nostr_rs_relay.RelayName {
54+
packages = append(packages, "sqlite3", "libsqlite3-dev")
55+
}
4556

4657
// Check if package is installed, install if not
4758
for _, p := range packages {

pkg/relays/khatru29/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package khatru29
22

3-
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.3.0/relay29-0.4.0-khatru29-x86_64-linux-gnu.tar.gz"
3+
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/relay29-0.4.0-khatru29-x86_64-linux-gnu.tar.gz"
44
const BinaryName = "khatru29"
55
const BinaryFilePath = "/usr/local/bin/khatru29"
66
const NginxConfigFilePath = "/etc/nginx/conf.d/khatru29.conf"

pkg/relays/khatru29/install.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

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

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

40-
spinner.Success("Khatru29 relay installed successfully.")
40+
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
4141
}

pkg/relays/khatru29/nginx_https.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ server {
5858
# Add support to generate the file in the script
5959
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
6060
61-
ssl_protocols TLSv1.2 TLSv1.3;
61+
ssl_protocols TLSv1.3 TLSv1.2;
6262
6363
# For more information on the security of different cipher suites, you can refer to the following link:
6464
# https://ciphersuite.info/

pkg/relays/khatru_pyramid/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package khatru_pyramid
22

3-
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.3.0/khatru-pyramid-0.1.0-x86_64-linux-gnu.tar.gz"
3+
const DownloadURL = "https://github.com/nodetec/relays/releases/download/v0.4.0/khatru-pyramid-0.1.0-x86_64-linux-gnu.tar.gz"
44
const BinaryName = "khatru-pyramid"
55
const BinaryFilePath = "/usr/local/bin/khatru-pyramid"
66
const NginxConfigFilePath = "/etc/nginx/conf.d/khatru_pyramid.conf"

pkg/relays/khatru_pyramid/install.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

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

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

40-
spinner.Success("Khatru Pyramid relay installed successfully.")
40+
spinner.Success(fmt.Sprintf("%s relay installed successfully.", RelayName))
4141
}

pkg/relays/khatru_pyramid/nginx_https.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ server {
5858
# Add support to generate the file in the script
5959
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
6060
61-
ssl_protocols TLSv1.2 TLSv1.3;
61+
ssl_protocols TLSv1.3 TLSv1.2;
6262
6363
# For more information on the security of different cipher suites, you can refer to the following link:
6464
# https://ciphersuite.info/

0 commit comments

Comments
 (0)