summaryrefslogtreecommitdiff
path: root/selftest.sh
blob: 22d91824a8ab09be013013db348f7fc9e2cf39f1 (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
39
40
#!/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()
{
    (
        export GIT_SSH_COMMAND="ssh -p $port"
        branch=$(git branch -q --show-current) || exit
        remote=${username}@${hostname}:${pwd#$HOME/}
        set -x
        git push "$remote" "$branch"
        git ls-remote "${remote}"
    )
}

#fuser -k "$port"/tcp
make install-user
know_thyself
run_test