mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -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"
|
"github.com/rwinkhart/MUTN/src/offline"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TempInitCli initializes the MUTN environment based on user input
|
||||||
func TempInitCli() {
|
func TempInitCli() {
|
||||||
// gpgID
|
// gpgID
|
||||||
var gpgID string
|
var gpgID string
|
||||||
|
|||||||
+7
-2
@@ -1,12 +1,12 @@
|
|||||||
package offline
|
package offline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TempInit ensures libmutton directories exist and writes the libmutton configuration file
|
||||||
func TempInit(configFileMap map[string]string) {
|
func TempInit(configFileMap map[string]string) {
|
||||||
// create EntryRoot and ConfigDir
|
// create EntryRoot and ConfigDir
|
||||||
dirInit()
|
dirInit()
|
||||||
@@ -51,6 +51,7 @@ func GpgUIDListGen() []string {
|
|||||||
|
|
||||||
// GpgKeyGen generates a new GPG key and returns the key ID as a string
|
// GpgKeyGen generates a new GPG key and returns the key ID as a string
|
||||||
func GpgKeyGen() 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"})
|
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 := exec.Command("gpg", "-q", "--batch", "--generate-key", ConfigDir+"/gpg-gen")
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -58,10 +59,14 @@ func GpgKeyGen() string {
|
|||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
|
|
||||||
|
// generate GPG key based on gog-gen file
|
||||||
cmd = exec.Command("gpg", "-k", "--with-colons")
|
cmd = exec.Command("gpg", "-k", "--with-colons")
|
||||||
gpgOutputBytes, _ := cmd.Output()
|
gpgOutputBytes, _ := cmd.Output()
|
||||||
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
|
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
|
||||||
uid := strings.Split(gpgOutputLines[len(gpgOutputLines)-4], ":")[9]
|
uid := strings.Split(gpgOutputLines[len(gpgOutputLines)-4], ":")[9]
|
||||||
fmt.Println(uid)
|
|
||||||
|
// remove gpg-gen file
|
||||||
|
removeFile(ConfigDir + "/gpg-gen")
|
||||||
|
|
||||||
return uid
|
return uid
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
const fallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
const fallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
||||||
|
|
||||||
|
// dirInit creates the libmutton directories
|
||||||
func dirInit() {
|
func dirInit() {
|
||||||
// create EntryRoot
|
// create EntryRoot
|
||||||
err := os.MkdirAll(EntryRoot, 0700)
|
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
|
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() {
|
func dirInit() {
|
||||||
// create EntryRoot (includes config directory on Windows)
|
// create EntryRoot (includes config directory on Windows)
|
||||||
err := os.MkdirAll(EntryRoot, 0700)
|
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 {
|
func EntryIsNotEmpty(entryData []string) bool {
|
||||||
for _, line := range entryData {
|
for _, line := range entryData {
|
||||||
if line != "" {
|
if line != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user