-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
179 lines (153 loc) · 6.88 KB
/
action.yaml
File metadata and controls
179 lines (153 loc) · 6.88 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
name: Preparing GPG
author: Frank Brehm
description: 'This action prepares gpg for signing files without entering a password'
inputs:
public_key:
description: "This is the exported public GPG key"
required: true
private_key:
description: "This is the exported private GPG key"
required: true
key_password:
description: "This is the password of the imported private GPG key"
required: true
password_file:
description: "The file containing the password of the private GPG key."
default: '.private/uhu.txt'
key_id:
description: "The ID of the private GPG key."
required: true
runs:
using: "composite"
steps:
- name: 'Importing public GPG key'
env:
GPG_PASSWORD_FILE: ${{ inputs.password_file }}
shell: bash
run: |
all_stuff_there='y'
if [[ -z "${{ inputs.public_key }}" ]] ; then
all_stuff_there='n'
echo "::warning title=setup-gpg::No public GPG key given."
fi
if [[ -z "${{ inputs.private_key }}" ]] ; then
all_stuff_there='n'
echo "::warning title=setup-gpg::No private GPG key given."
fi
if [[ -z "${{ inputs.key_password }}" ]] ; then
all_stuff_there='n'
echo "::warning title=setup-gpg::No password for the private GPG key given."
fi
if [[ -z "${{ inputs.key_id }}" ]] ; then
all_stuff_there='n'
echo "::warning title=setup-gpg::No Id of the GPK key given."
fi
if [[ "${all_stuff_there}" != 'y' ]]; then
if [[ -e "${{ inputs.password_file }}" ]] ; then
echo -e "\nRemoving '${{ inputs.password_file }}' ..."
rm -rfv "${{ inputs.password_file }}"
fi
else
echo "Importing public GPG key ..."
echo "${{ inputs.public_key }}" | gpg --import
echo -e "\nThe imported public keys:"
gpg --list-public-keys
echo "<-- EOF"
GPG_VERSION=$( gpg --version | head -n 1 | sed -e 's/[^0-9]*//' )
echo -e "\nVersion of GPG: '${GPG_VERSION}'"
GPG_MAJOR_VERSION=$( echo "${GPG_VERSION}" | awk -F. '{print $1}' )
GPG_MINOR_VERSION=$( echo "${GPG_VERSION}" | awk -F. '{print $2}' )
GPG_HAS_PINENTRY="y"
if [[ "${GPG_MAJOR_VERSION}" -lt "2" ]] ; then
GPG_HAS_PINENTRY="n"
elif [[ "${GPG_MAJOR_VERSION}" == "2" ]] ; then
if [[ "${GPG_MINOR_VERSION}" -lt "1" ]] ; then
GPG_HAS_PINENTRY="n"
fi
fi
echo "GPG has pinentry mode: ${GPG_HAS_PINENTRY}"
echo -e "\nImporting private GPG key ..."
if [[ "${GPG_HAS_PINENTRY}" == "y" ]] ; then
echo "${{ inputs.private_key }}" | gpg --import --batch --pinentry-mode loopback --passphrase "${{ inputs.key_password }}"
else
echo "${{ inputs.private_key }}" | gpg --import --batch --passphrase "${{ inputs.key_password }}"
fi
echo -e "\nThe imported private keys:"
gpg --list-secret-keys
echo "<-- EOF"
PASSWORD_FILE_REL="${GPG_PASSWORD_FILE:-.private/uhu.txt}"
PASSWORD_FILE_ABS=$( readlink --canonicalize-missing "${PASSWORD_FILE_REL}" )
PASSWORD_DIR=$( dirname "${PASSWORD_FILE_ABS}" )
if [[ ! -d "${PASSWORD_DIR}" ]] ; then
echo -e "\nCreating directory '${PASSWORD_DIR}' ..."
mkdir --parents --verbose --mode 0700 "${PASSWORD_DIR}"
fi
echo -e "\nCreating password file '${PASSWORD_FILE_ABS}' ..."
echo "${{ inputs.key_password }}" > "${PASSWORD_FILE_ABS}"
chmod --verbose 0600 "${PASSWORD_FILE_ABS}"
echo
ls -l --directory --color=auto "${PASSWORD_DIR}" "${PASSWORD_FILE_ABS}"
echo -e "\nCreating GnuPG config ..."
PASSWORD_FILE_REL="${GPG_PASSWORD_FILE:-.private/uhu.txt}"
PASSWORD_FILE_ABS=$( readlink --canonicalize-missing "${PASSWORD_FILE_REL}" )
GPG_DIR="${HOME}/.gnupg"
GPG_CONF="${GPG_DIR}/gpg.conf"
GPG_VERSION=$( gpg --version | head -n 1 | sed -e 's/[^0-9]*//' )
GPG_MAJOR_VERSION=$( echo "${GPG_VERSION}" | awk -F. '{print $1}' )
GPG_MINOR_VERSION=$( echo "${GPG_VERSION}" | awk -F. '{print $2}' )
GPG_HAS_PINENTRY="y"
if [[ "${GPG_MAJOR_VERSION}" -lt "2" ]] ; then
GPG_HAS_PINENTRY="n"
elif [[ "${GPG_MAJOR_VERSION}" == "2" ]] ; then
if [[ "${GPG_MINOR_VERSION}" -lt "1" ]] ; then
GPG_HAS_PINENTRY="n"
fi
fi
if [[ ! -d "${GPG_DIR}" ]] ; then
echo -e "\nCreating directory '${GPG_DIR}' ..."
mkdir --parents --verbose --mode 0700 "${GPG_DIR}"
fi
if [[ ! -f "${GPG_CONF}" ]] ; then
echo -e "\nCreating file '${GPG_CONF}' ..."
touch "${GPG_CONF}"
chmod --verbose 0600 "${GPG_CONF}"
fi
printf "\nSetting default Key-Id "
if grep -q -P '^\s*default-key\s' "${GPG_CONF}" ; then
echo "by substituting old value ..."
sed -i -e "s/[ ]*default-key[ ].*/default-key ${{ inputs.key_id }}/i" "${GPG_CONF}"
else
echo "by setting new value ..."
echo "default-key ${{ inputs.key_id }}" >> "${GPG_CONF}"
fi
printf "\nSetting batch mode "
if grep -q -P '^\s*batch\s*$' "${GPG_CONF}" ; then
echo "- already set."
else
echo "by setting mode."
echo "batch" >> "${GPG_CONF}"
fi
if [[ "${GPG_HAS_PINENTRY}" == "y" ]] ; then
printf "\nSetting Pinentry mode "
if grep -q -P '^\s*pinentry-mode\s' "${GPG_CONF}" ; then
echo "by substituting old value ..."
sed -i -e "s/[ ]*pinentry-mode[ ].*/pinentry-mode loopback/i" "${GPG_CONF}"
else
echo "by setting new value ..."
echo "pinentry-mode loopback" >> "${GPG_CONF}"
fi
fi
printf "\nSetting passphrase-file "
if grep -q -P '^\s*passphrase-file\s' "${GPG_CONF}" ; then
echo "by substituting old value ..."
sed -i -e "s/[ ]*passphrase-file[ ].*/passphrase-file ${PASSWORD_FILE_ABS}/i" "${GPG_CONF}"
else
echo "by setting new value ..."
echo "passphrase-file ${PASSWORD_FILE_ABS}" >> "${GPG_CONF}"
fi
echo -e "\nModified '${GPG_CONF}':"
grep -P -v '^\s*(#|$)' "${GPG_CONF}"
echo "<-- EOF"
fi
# vim: et tabstop=2 expandtab shiftwidth=2 softtabstop=2 list