Skip to content

Commit

Permalink
allow installer to get cert without email
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianChiarulli committed Jun 23, 2024
1 parent 0f68e3f commit eb41bc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 6 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ var installCmd = &cobra.Command{
ui.Greet()

relayDomain, _ := pterm.DefaultInteractiveTextInput.Show("Relay domain name")
email, _ := pterm.DefaultInteractiveTextInput.Show("Email address")
pterm.Println()
pterm.Println(pterm.Yellow("Leave email empty if you don't want to receive notifications from Let's Encrypt about your SSL cert."))
pterm.Println()
ssl_email, _ := pterm.DefaultInteractiveTextInput.Show("Email address")
pubkey, _ := pterm.DefaultInteractiveTextInput.Show("Public key (hex not npub)")

pterm.Println()
Expand All @@ -36,7 +39,7 @@ var installCmd = &cobra.Command{
network.ConfigureNginxHttp(relayDomain)

// Step 4: Get SSL certificates
var shouldContinue = network.GetCertificates(relayDomain, email)
var shouldContinue = network.GetCertificates(relayDomain, ssl_email)

if !shouldContinue {
return
Expand All @@ -55,6 +58,7 @@ var installCmd = &cobra.Command{
pterm.Println(pterm.Magenta("The installation is complete."))
pterm.Println(pterm.Magenta("You can access your relay at wss://" + relayDomain))
pterm.Println()
pterm.Println(pterm.Magenta("You can re-run this installer with `relaywiz install`."))
},
}

Expand Down
20 changes: 14 additions & 6 deletions pkg/network/certbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func GetCertificates(domainName, email string) bool {

prompt := pterm.DefaultInteractiveContinue.WithOptions(options)

pterm.Println()
pterm.Println()
pterm.Println(pterm.Cyan("Do you want to obtain SSL certificates using Certbot?"))
pterm.Println(pterm.Cyan("This step requires that you already have a configured domain name."))
pterm.Println(pterm.Cyan("You can always re-run this installer after you have configured your domain name."))
pterm.Println()
pterm.Println()

result, _ := prompt.Show()

Expand All @@ -48,10 +48,18 @@ func GetCertificates(domainName, email string) bool {
}

spinner.UpdateText("Obtaining SSL certificates...")
cmd := exec.Command("certbot", "certonly", "--webroot", "-w", fmt.Sprintf("/var/www/%s", dirName), "-d", domainName, "--email", email, "--agree-tos", "--no-eff-email", "-q")
err = cmd.Run()
if err != nil {
log.Fatalf("Certbot failed to obtain the certificate for %s: %v", domainName, err)
if email == "" {
cmd := exec.Command("certbot", "certonly", "--webroot", "-w", fmt.Sprintf("/var/www/%s", dirName), "-d", domainName, "--agree-tos", "--no-eff-email", "-q", "--register-unsafely-without-email")
err = cmd.Run()
if err != nil {
log.Fatalf("Certbot failed to obtain the certificate for %s: %v", domainName, err)
}
} else {
cmd := exec.Command("certbot", "certonly", "--webroot", "-w", fmt.Sprintf("/var/www/%s", dirName), "-d", domainName, "--email", email, "--agree-tos", "--no-eff-email", "-q")
err = cmd.Run()
if err != nil {
log.Fatalf("Certbot failed to obtain the certificate for %s: %v", domainName, err)
}
}

spinner.Success("SSL certificates obtained successfully.")
Expand Down

0 comments on commit eb41bc8

Please sign in to comment.