-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from nodetec/relays29
feat: add support for strfry and khatru29
- Loading branch information
Showing
22 changed files
with
744 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# These are supported funding model platforms | ||
|
||
github: christianchiarulli | ||
github: [christianchiarulli, jchiarulli] | ||
patreon: chrisatmachine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
relaywiz | ||
|
||
# Ignore .DS_Store files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package khatru29 | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pterm/pterm" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
// Function to download and make the binary executable | ||
func InstallRelayBinary() { | ||
// URL of the binary to download | ||
const downloadURL = "https://github.com/nodetec/relays/releases/download/v0.1.0/khatru29-0.4.0-x86_64-linux-gnu.tar.gz" | ||
|
||
// Name of the binary after downloading | ||
const binaryName = "nostr-relay-khatru29" | ||
|
||
// Destination directory for the binary | ||
const destDir = "/usr/local/bin" | ||
|
||
// Data directory for the relay | ||
const dataDir = "/var/lib/nostr-relay-khatru29" | ||
|
||
spinner, _ := pterm.DefaultSpinner.Start("Installing khatru29 relay...") | ||
|
||
// Ensure the data directory exists | ||
err := os.MkdirAll(dataDir, 0755) | ||
if err != nil { | ||
log.Fatalf("Error creating data directory: %v", err) | ||
} | ||
|
||
// Determine the file name from the URL | ||
tempFileName := filepath.Base(downloadURL) | ||
|
||
// Create the temporary file | ||
out, err := os.Create(fmt.Sprintf("/tmp/%s", tempFileName)) | ||
if err != nil { | ||
log.Fatalf("Error creating temporary file: %v", err) | ||
} | ||
defer out.Close() | ||
|
||
// Download the file | ||
resp, err := http.Get(downloadURL) | ||
if err != nil { | ||
log.Fatalf("Error downloading file: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Check server response | ||
if resp.StatusCode != http.StatusOK { | ||
log.Fatalf("Bad status: %s", resp.Status) | ||
} | ||
|
||
// Write the body to the temporary file | ||
_, err = io.Copy(out, resp.Body) | ||
if err != nil { | ||
log.Fatalf("Error writing to temporary file: %v", err) | ||
} | ||
|
||
// Extract binary | ||
err = exec.Command("tar", "-xf", fmt.Sprintf("/tmp/%s", tempFileName), "-C", fmt.Sprintf("%s", destDir)).Run() | ||
if err != nil { | ||
log.Fatalf("Error extracting binary to /usr/local/bin: %v", err) | ||
} | ||
|
||
// TODO | ||
// Currently, the downloaded binary is expected to have a name that matches the binaryName variable | ||
// Ideally, the extracted binary file should be renamed to match the binaryName variable | ||
|
||
// Define the final destination path | ||
destPath := filepath.Join(destDir, binaryName) | ||
|
||
// Make the file executable | ||
err = os.Chmod(destPath, 0755) | ||
if err != nil { | ||
log.Fatalf("Error making file executable: %v", err) | ||
} | ||
|
||
spinner.Success("khatru29 relay installed successfully.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package khatru29 | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pterm/pterm" | ||
"log" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
// Function to configure nginx for HTTP | ||
func ConfigureNginxHttp(domainName string) { | ||
spinner, _ := pterm.DefaultSpinner.Start("Configuring nginx for HTTP...") | ||
|
||
err := os.MkdirAll(fmt.Sprintf("/var/www/%s/.well-known/acme-challenge/", domainName), 0755) | ||
if err != nil { | ||
log.Fatalf("Error creating directories: %v", err) | ||
} | ||
|
||
const configFile = "nostr_relay_khatru29.conf" | ||
|
||
err = os.Remove(fmt.Sprintf("/etc/nginx/conf.d/%s", configFile)) | ||
if err != nil && !os.IsNotExist(err) { | ||
log.Fatalf("Error removing existing nginx configuration: %v", err) | ||
} | ||
|
||
var configContent string | ||
|
||
configContent = fmt.Sprintf(`map $http_upgrade $connection_upgrade { | ||
default upgrade; | ||
'' close; | ||
} | ||
upstream websocket_khatru29 { | ||
server 0.0.0.0:5577; | ||
} | ||
# %s | ||
server { | ||
listen 80; | ||
listen [::]:80; | ||
server_name %s; | ||
location /.well-known/acme-challenge/ { | ||
root /var/www/%s; | ||
allow all; | ||
} | ||
location / { | ||
proxy_pass http://websocket_khatru29; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection $connection_upgrade; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Forwarded-For $remote_addr; | ||
} | ||
} | ||
`, domainName, domainName, domainName) | ||
|
||
err = os.WriteFile(fmt.Sprintf("/etc/nginx/conf.d/%s", configFile), []byte(configContent), 0644) | ||
if err != nil { | ||
log.Fatalf("Error writing nginx configuration: %v", err) | ||
} | ||
|
||
err = exec.Command("systemctl", "restart", "nginx").Run() | ||
if err != nil { | ||
log.Fatalf("Error reloading nginx: %v", err) | ||
} | ||
|
||
spinner.Success("Nginx configured for HTTP") | ||
} |
Oops, something went wrong.