summaryrefslogtreecommitdiff
path: root/selftest.sh
blob: 87b9d266472376b96d3544e484ee0c6142cc76cf (plain)
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
#!/bin/sh
keyfile=~/.ssh/id_ed25519
port=${1:-22022}

username=$(id -un)
hostname=$(hostname)
pwd=$(pwd)

append_idempotent()
{
    if ! grep -q -F -e "$1" -- "$2"
    then
        printf '%s\n' "$1" >> "$2"
    fi
}

know_thyself()
{
    read keytype keydata _ < "$keyfile".pub || return

    authline=$(printf '[%s]:%d %s %s\n' "$hostname" "$port" "$keytype" "$keydata")
    append_idempotent "$authline" ~/.ssh/known_hosts
}

run_test()
{
    (
        set -x
        export GIT_SSH_COMMAND="ssh -p $port"
        git push "${username}@${hostname}:${pwd}" "$(git branch -q --show-current)"
    )
}

know_thyself
fuser -k "$port"/tcp
(sleep 1
 run_test) &
make run