aboutsummaryrefslogtreecommitdiff
blob: a8ef87953cec5c5e083082680a7176b2b239e900 (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
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# Copyright 2013-2016 Robin H. Johnson <robbat2@gentoo.org>
# ExecHook is designed to be a partner to the GitHub webhook concept.
# Instead of HTTP request as the transport, it uses SSH & exec as the
# transport.
#
# This is a little helper for GIT_SSH, because Git expects GIT_SSH to point
# directly to a single command, and does not take parameters.
#
# Newer git also supports GIT_SSH_COMMAND, but this was written for systems
# where older Git still exists and GIT_SSH_COMMAND is not supported.
vars=$(env -0 |grep -zZi -e '^GIT_SSH_OPT' | sed -z 's,=.*,,g' | tr '\0' '\n')
for v in $vars ; do
	optname=${v#GIT_SSH_OPT_}
	#optvalue=${!v} # Bash-specific, don't use it
	eval optvalue=\$$v
	set -- -o "$optname"="$optvalue" "$@"
done

# NOT available in configfile
[ -n "$GIT_SSH_CONFIG" ] && set -- -F "$GIT_SSH_CONFIG" "$@"
[ -n "$GIT_SSH_LOGFILE" ] && set -- -E "$GIT_SSH_LOGFILE" "$@"
# Common, but available in Config
[ -n "$GIT_SSH_USER" ] && set -- -l "$GIT_SSH_USER" "$@"
[ -n "$GIT_SSH_IDENTITYFILE" ] && set -- -i "$GIT_SSH_IDENTITYFILE" "$@"
[ -n "$GIT_SSH_BACKGROUND" ] && set -- -f "$@"

# TODO: 
# - support multiple 
#   - IdentityFiles
#   - LocalForward
#   - RemoteForward
#   - DynamicForward

# If you want other options, you should PROBABLY be using the GIT_SSH_OPT stuff.
# Prefix the name of the option with GIT_SSH_OPT_
# Options allowed multiple times specified with *
# -1 Protocol=1
# -2 Protocol=2
# -4 AddressFamily=inet
# -6 AddressFamily=inet6
# -A/-a ForwardAgent
# -b BindAddress
# -C Compression
# -c Ciphers
# -D DynamicForward*
# -g GatewayPorts
# -I PKCS11Provider
# -i IdentityFile*
# -K/-k GSSAPIAuthentication
# -L LocalForward*
# -l User
# -M ControlMaster
# -m MACs
# -N ... no mapping, not useful to us
# -n ... no mapping, not useful to us
# -O ... no mapping, not useful to us
# -o ... we use this a lot!
# -p Port
# -Q ... no mapping, not useful to us
# -q ... no mapping, but we do it manually
# -R RemoteForward*
# -S ControlPath
# -s ... no mapping, not useful to us
# -T/-t RequestTTY
# -v LogLevel
# -W ... no mapping, not useful to us
# -w Tunnel
# -X/-x ForwardX11
# -Y ForwardX11Trusted
# -y ... no mapping, not useful to us

[ -n "$GIT_SSH__VERBOSE" ] &&
echo exec /usr/bin/ssh \
	-a \
	-q \
	-T \
	-o IdentitiesOnly=yes \
	-o StrictHostKeyChecking=yes \
	-o BatchMode=yes \
	"$@" 1>&2

exec /usr/bin/ssh \
	-a \
	-q \
	-T \
	-o IdentitiesOnly=yes \
	-o StrictHostKeyChecking=yes \
	-o BatchMode=yes \
	"$@"