From 9bb456bc1771ff6f065a408a4c37e57811579c4f Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 1 Nov 2023 20:59:49 +0000 Subject: [PATCH] add newline to keyfile if needed --- external/cmd/helpers/createkeyfile/main.go | 7 ++++--- external/cmd/welcome/main.go | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/external/cmd/helpers/createkeyfile/main.go b/external/cmd/helpers/createkeyfile/main.go index 990578c..cdcff38 100644 --- a/external/cmd/helpers/createkeyfile/main.go +++ b/external/cmd/helpers/createkeyfile/main.go @@ -76,12 +76,13 @@ func main() { quit(fmt.Sprintf("file contents look wrong: %s", string(stdin)), 8) } - n, err = f.Write(stdin) + _, err = f.Write(stdin) if err != nil { quit(err.Error(), 9) - } else if n == 0 { - quit("wrote nothing to keyfile", 10) } + + _, err = f.WriteString("\n") + } /* diff --git a/external/cmd/welcome/main.go b/external/cmd/welcome/main.go index 87a483c..b51fbb5 100644 --- a/external/cmd/welcome/main.go +++ b/external/cmd/welcome/main.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "os/exec" + "strings" "time" "git.tilde.town/tildetown/town/invites" @@ -205,12 +206,16 @@ func createUser(data newUserData) (err error) { } func keyfileText(data newUserData) string { + pkey := data.PubKey + if !strings.HasSuffix(pkey, "\n") { + pkey += "\n" + } header := `########## GREETINGS! ########## # This file was automatically generated by tilde.town when # your account was created. You can edit it if you want, but we # recommend adding stuff to ~/.ssh/authorized_keys instead.` - return fmt.Sprintf("%s\n%s", header, data.PubKey) + return fmt.Sprintf("%s\n%s", header, pkey) } func main() {