2020-11-18 23:23:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
setup(){
|
2020-11-19 21:40:38 +00:00
|
|
|
test -f /usr/bin/git || sudo apt install --reinstall -y git
|
|
|
|
test -f /usr/bin/getopt || sudo apt install --reinstall -y util-linux
|
|
|
|
test -f /usr/bin/gpg || sudo apt install --reinstall -y gpg
|
|
|
|
test -f /usr/bin/openssl || sudo apt install --reinstall -y openssl
|
2020-11-19 03:22:08 +00:00
|
|
|
bin_dir=/tmp/bin
|
|
|
|
temp_dir=$(mktemp -d -t test-XXXXXXXXXX)
|
|
|
|
mkdir -p /tmp/bin
|
2020-12-04 04:56:38 +00:00
|
|
|
ln -sfn /home/test/sig/sig /tmp/bin/sig
|
2020-11-19 03:22:08 +00:00
|
|
|
export PATH=${bin_dir}:${PATH}
|
|
|
|
cd "$temp_dir" || return 1
|
2020-11-20 10:32:45 +00:00
|
|
|
rm -rf ~/.gnupg
|
|
|
|
rm -rf ~/.gitconfig
|
2020-12-04 04:56:38 +00:00
|
|
|
killall gpg-agent >/dev/null 2>&1 || :
|
2020-11-18 23:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown(){
|
2020-11-19 03:22:08 +00:00
|
|
|
rm -rf "$temp_dir"
|
2020-11-18 23:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 03:22:08 +00:00
|
|
|
set_identity(){
|
|
|
|
local -r name="${1?}"
|
2020-11-20 10:32:45 +00:00
|
|
|
killall gpg-agent || :
|
|
|
|
rm -rf ~/.gnupg || :
|
|
|
|
rm -rf ~/.gitconfig || :
|
|
|
|
gpg --import ${HOME}/sig/test/keys/*.pub.asc
|
|
|
|
gpg --import ${HOME}/sig/test/keys/${name}.sec.asc
|
|
|
|
local -r fingerprint=$( \
|
|
|
|
gpg --list-keys --with-colons "${name}" 2>&1 \
|
|
|
|
| awk -F: '$1 == "fpr" {print $10}' \
|
|
|
|
| head -n1 \
|
|
|
|
)
|
2020-11-19 03:22:08 +00:00
|
|
|
git config --global user.email "${name}@example.com"
|
|
|
|
git config --global user.name "${name}"
|
2020-11-20 10:32:45 +00:00
|
|
|
git config --global user.signingKey "${fingerprint}"
|
|
|
|
git config --global commit.gpgSign "true"
|
|
|
|
git config --global merge.gpgSign "true"
|
|
|
|
echo "default-key ${fingerprint}" > ~/.gnupg/gpg.conf
|
2020-11-19 03:22:08 +00:00
|
|
|
}
|