This repository was archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpg.nu
More file actions
144 lines (118 loc) · 3.24 KB
/
gpg.nu
File metadata and controls
144 lines (118 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#*
#* _ __ _ _
#* __ _ ___ __ _| |_ / _(_) |___ ___ WEBSITE: https://goatfiles.github.io
#* / _` / _ \/ _` | _| _| | / -_|_-< REPOS: https://github.com/goatfiles
#* \__, \___/\__,_|\__|_| |_|_\___/__/ LICENCE: https://github.com/goatfiles/dotfiles/blob/main/LICENSE
#* |___/
#* MAINTAINERS:
#* AMTOINE: https://github.com/amtoine antoine#1306 7C5EE50BA27B86B7F9D5A7BA37AAE9B486CFF1AB
#* ATXR: https://github.com/atxr atxr#6214 3B25AF716B608D41AB86C3D20E55E4B1DE5B2C8B
#*
# TODO: documentation
def poll_gpg [
key: string = ""
] {
if ($key == "") {
gpg --list-keys --with-colons
} else {
gpg --list-keys --with-colons $key
}
}
# TODO: documentation
def get_gpg_tru [] {
poll_gpg | lines | find --regex "^tru" | split column ":" --collapse-empty a b c d e f g
}
# TODO: documentation
def get_gpg_keys [] {
poll_gpg | lines | find --regex "^pub" | parse "{pub}:{1}:{2}:{3}:{key}:{rest}" | get key
}
# TODO: documentation
def get_section [
section: string
context: int = 1
] {
grep $"^($section)" -A $context | str trim
}
# TODO: documentation
def format_section [
section: list # list<string>
] {
{
main: ($section | get 0 | split column ":" --collapse-empty a b c d e f g h i j k)
fpr: ($section | get 1 | split column ":" --collapse-empty a b)
}
}
# TODO: documentation
def get_gpg_pub [
key: string
] {
let pub = (poll_gpg $key | get_section "pub" | lines)
format_section $pub
}
# TODO: documentation
def get_gpg_sub [
key: string
] {
let sub = (poll_gpg $key | get_section "sub" | lines)
format_section $sub
}
# TODO: documentation
def get_gpg_uid [
key: string
] {
poll_gpg $key | get_section "uid" | split column ":" --collapse-empty a b c d name e f g h i j
}
# TODO: documentation
def get_gpg_keys_data [] {
(get_gpg_keys)
| each {|key|
{
key: $key
data: {
pub: (get_gpg_pub $key)
sub: (get_gpg_sub $key)
uid: (get_gpg_uid $key)
}
}
}
}
# TODO: documentation
export def list [] {
{
tru: (get_gpg_tru)
keys: (get_gpg_keys_data)
}
}
# TODO: documentation
export def export [
pubkeys_file: string = "keys.pub.asc"
privkeys_file: string = "keys.asc"
trust_file: string = "trust.txt"
--dump_dir: string = "/tmp/gpg-keys"
] {
if not ($dump_dir | path exists) {
mkdir $dump_dir
}
gpg --armor --export-options backup --export | save --force ($dump_dir | path join $pubkeys_file)
gpg --armor --export-options backup --export-secret-keys | save --force ($dump_dir | path join $privkeys_file)
gpg --export-ownertrust | save --force ($dump_dir | path join $trust_file)
}
# TODO: documentation
export def import [
pubkeys_file: string = "keys.pub.asc"
privkeys_file: string = "keys.asc"
trust_file: string = "trust.txt"
--dump_dir: string = "/tmp/gpg-keys"
] {
gpg --import ($dump_dir | path join $pubkeys_file)
gpg --import ($dump_dir | path join $privkeys_file)
gpg --import-ownertrust ($dump_dir | path join $trust_file)
}
# TODO: documentation
export def "make keyring" [keyring?] {
let keyring = (if ($keyring | is-empty) {
$env | get -i GNUPGHOME | default "~/.gnupg" | path expand
} else { $keyring })
mkdir $keyring
chmod -R 700 $keyring
}