mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Remove the gpg-gen file after use
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/rwinkhart/MUTN/src/offline"
|
||||
)
|
||||
|
||||
// TempInitCli initializes the MUTN environment based on user input
|
||||
func TempInitCli() {
|
||||
// gpgID
|
||||
var gpgID string
|
||||
|
||||
+7
-2
@@ -1,12 +1,12 @@
|
||||
package offline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TempInit ensures libmutton directories exist and writes the libmutton configuration file
|
||||
func TempInit(configFileMap map[string]string) {
|
||||
// create EntryRoot and ConfigDir
|
||||
dirInit()
|
||||
@@ -51,6 +51,7 @@ func GpgUIDListGen() []string {
|
||||
|
||||
// GpgKeyGen generates a new GPG key and returns the key ID as a string
|
||||
func GpgKeyGen() string {
|
||||
// create and write gpg-gen file
|
||||
createFile(ConfigDir+"/gpg-gen", []string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton", "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"})
|
||||
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", ConfigDir+"/gpg-gen")
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -58,10 +59,14 @@ func GpgKeyGen() string {
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Run()
|
||||
|
||||
// generate GPG key based on gog-gen file
|
||||
cmd = exec.Command("gpg", "-k", "--with-colons")
|
||||
gpgOutputBytes, _ := cmd.Output()
|
||||
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
|
||||
uid := strings.Split(gpgOutputLines[len(gpgOutputLines)-4], ":")[9]
|
||||
fmt.Println(uid)
|
||||
|
||||
// remove gpg-gen file
|
||||
removeFile(ConfigDir + "/gpg-gen")
|
||||
|
||||
return uid
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
const fallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
||||
|
||||
// dirInit creates the libmutton directories
|
||||
func dirInit() {
|
||||
// create EntryRoot
|
||||
err := os.MkdirAll(EntryRoot, 0700)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
const fallbackEditor = "nvim" // since there is no pre-installed CLI editor on Windows, default to the most popular one
|
||||
|
||||
// dirInit creates the libmutton directories
|
||||
func dirInit() {
|
||||
// create EntryRoot (includes config directory on Windows)
|
||||
err := os.MkdirAll(EntryRoot, 0700)
|
||||
|
||||
@@ -126,6 +126,7 @@ func StringGen(length int, complex bool, complexity float64) string {
|
||||
}
|
||||
}
|
||||
|
||||
// EntryIsNotEmpty iterates through entryData and returns true if any line is not empty
|
||||
func EntryIsNotEmpty(entryData []string) bool {
|
||||
for _, line := range entryData {
|
||||
if line != "" {
|
||||
|
||||
Reference in New Issue
Block a user