summaryrefslogtreecommitdiff
path: root/git.liw.fi.sh
blob: 56945e46841a8a43ec754a1aab82a6d7e75d3968 (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
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
# Shell library for running git.liw.fi ACL tests.


# We create ssh keys in the test suite. The temporary directory,
# $DATADIR, must be made inaccessible to others before that happens.
# We do it here, so it gets done before any of the code from an
# IMPLEMENTS actually runs.
chmod 0700 "$DATADIR"


# This is handy for giving an error message and aborting.

die()
{
    echo "$@" 1>&2
    exit 1
}


# Attempt to run something, which may fail. Store the stdout,
# stderr, and exit code in $DATADIR.

attempt()
{
    if "$@" > "$DATADIR/attempt.stdout" 2> "$DATADIR/attempt.stderr"
    then
        echo 0 > "$DATADIR/attempt.exit"
    else
        echo $? > "$DATADIR/attempt.exit"
    fi
}


# Run gitano on the server using a desired ssh key. The key is
# either the admin key (i.e., they key of whoever invoked the
# test suite), or a test key we've created in $DATADIR.

run_gitano_as()
{
    local keyname="$1"
    shift
    if [ "$keyname" = "admin" ]
    then
	ssh "$GITANO@$GITHOST" "$@"
    else
	SSH_AUTH_SOCK= ssh -F "ssh.conf" -i "$DATADIR/$keyname.key" \
	    "$GITANO@$GITHOST" "$@"
    fi
}


# Does a user exist on the server?

user_exists()
{
    ssh "$GITANO@$GITHOST" user | grep "^$1:"
}


# Create a user, including setting their ssh key.

user_add()
{
    run_gitano_as "$1" user add "$2" name foo@example.com
    run_gitano_as "$1" as "$2" sshkey add somekey < "$DATADIR/$2.key.pub"
}


# Remove a user from the server. This is a two-step process.

user_del()
{
    if run_gitano_as "$1" user del "$2" 2> "$DATADIR/temp"
    then
	secret=$(awk '{ s = $2 } END { print s }' "$DATADIR/temp")
	run_gitano_as "$1" user del "$2" "$secret"
    fi
}