git-sig/test/test_helper.bash

42 lines
1.2 KiB
Bash
Raw Normal View History

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
bin_dir=/tmp/bin
temp_dir=$(mktemp -d -t test-XXXXXXXXXX)
mkdir -p /tmp/bin
ln -sfn /home/test/sig/sig /tmp/bin/sig
export PATH=${bin_dir}:${PATH}
cd "$temp_dir" || return 1
rm -rf ~/.gnupg
rm -rf ~/.gitconfig
killall gpg-agent >/dev/null 2>&1 || :
2020-11-18 23:23:15 +00:00
}
teardown(){
rm -rf "$temp_dir"
2020-11-18 23:23:15 +00:00
}
set_identity(){
local -r name="${1?}"
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 \
)
git config --global user.email "${name}@example.com"
git config --global user.name "${name}"
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
}