-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpgsign.sh
74 lines (57 loc) · 1.08 KB
/
gpgsign.sh
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
#!/bin/bash
echo "SET
1.Use existing GPG key to change
2.Generate new GPG key"
read n
if [[ $n -eq 1 ]]
then
declare -a key=()
declare -a name=()
j=0
sec=$(gpg --list-secret-keys --keyid-format=long | awk '/sec/{if (length($2)>0) print $2}')
uid=$(gpg --list-secret-keys --keyid-format=long | awk '/uid/')
n1=${#sec}
n2=${#uid}
for((i=0;i<$n1;i++));
do
if [[ ${sec:$i:1} == "/" ]]
then
key[$j]=${sec:$i+1:16}
((j++))
echo ${key[$j-1]}
fi
done
j=0
index=0
for((i=0;i<$n2;i++));
do
if [[ ${uid:$i:1} == ")" ]]
then
name[$j]=${uid:$index:$i-$index+1}
((index=i+2))
((j++))
fi
done
echo "Choose one key:"
for((i=0;i<$j;i++));
do
echo "$((i+1)) ${name[$i]}"
done
read x
if [[ $x -le $j ]]
then
c="gpg --armor --export "${key[$x-1]}""
$c
else
echo "invalid input"
fi
cc="git config --global user.signingkey "${key[$x-1]}""
$cc
elif [[ $n -eq 2 ]]
then
gpg --full-generate-key
echo "your key has been generated"
bash gpgsign.sh
else
echo "Please enter a valid number"
fi