refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / gpg-pubkey / gpg-pubkey.ps1
1 #!/usr/bin/env pwsh
2
3 $my_key_id = gpg --list-secret-keys --keyid-format LONG |
4     Select-String -Pattern '\.*sec.*\/' |
5     Select-Object Line |
6     ForEach-Object {
7         $_.Line.split('/')[1].split(' ')[0]
8     }
9
10 if (!$my_key_id)
11 {
12     $my_name = git config --global user.name
13     $my_email = git config --global user.email
14     $my_host = hostname
15
16     echo "
17      %echo Generating RSA 3072 key
18      Key-Type: RSA
19      Key-Length: 3072
20      Subkey-Type: RSA
21      Subkey-Length: 3072
22      Name-Real: $my_name
23      Name-Comment: $my_host
24      Name-Email: $my_email
25      Expire-Date: 0
26      %commit
27     " | gpg --batch --generate-key
28 }
29
30 $my_asc_relpath = "Downloads/$my_email.$my_key_id.gpg.asc"
31 & gpg --armor --export $my_key_id > "$Env:USERPROFILE/$my_asc_relpath"
32
33 # TODO use the comment (if any) for the name of the file
34 $my_email = git config --global user.email
35 echo ""
36 echo "GnuPG Public Key ID: $MY_KEY_ID"
37 echo ""
38 echo "~/$my_asc_relpath":
39 echo ""
40 & type "$Env:USERPROFILE/$my_asc_relpath"
41 echo ""