blob: 856c88408e7d8c75a16303c8a63f1bc2f2d3d735 (
plain) (
blame)
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
|
#!/bin/sh
##### Configure These Vars: #####
USER="git"
HOST="labs.anyclip.com"
REPOS="/home/$USER"
POSTCMD="$REPOS/updatewebinterface.sh"
#################################
# Check environment
if [ "$1" == "" ]; then
echo "The first argument of this script must be the description of the git repository."
exit 1
fi
if [ ! -d ".git" ]; then
echo "The current directory is not a git repository."
exit 1
fi
# Initialize constants
repository="`pwd | xargs -0 basename | tr -d ' '`"
connection="$USER@$HOST"
hash="`echo $REPOS $repository $connection $(date +%s%N) | md5sum | cut -d ' ' -f 1`"
options="-o ControlMaster=auto -o ControlPath=./.sshcontrolmaster-$hash"
gitsshpath="./.gitssh-$hash"
# Create git ssh stub to use our options
echo -n "[*] Creating git ssh wrapper script..."
(echo '#!/bin/sh' > $gitsshpath &&
echo -n 'exec ssh ' >> $gitsshpath &&
echo -n "$options " >> $gitsshpath &&
echo '"$@"' >> $gitsshpath &&
chmod +x $gitsshpath) || { echo "failure!"; exit 1; }
echo "success."
export GIT_SSH="$gitsshpath"
# Setup control master
echo -n "[*] Connecting to server..."
ssh $options -fN $connection || { echo "failure!"; exit 1; }
echo "success."
# Create bare repo on server
echo -n "[*] Creating bare remote repository..."
ssh $options $connection "\
cd \"$REPOS\" && \
mkdir \"$repository\" &&\
cd \"$repository\" &&\
git init --bare &&\
echo \"$1\" > description &&\
mv hooks/post-update.sample hooks/post-update &&\
chmod +x hooks/post-update;" > /dev/null 2>&1 || { echo "failure!"; exit 1; }
echo "success."
# Add configuration for remote repo to local repo
echo -n "[*] Setting up local configuration..."
echo "[remote \"origin\"]
url = $connection:$REPOS/$repository
fetch = +refs/heads/*:refs/remotes/origin/*
[branch \"master\"]
remote = origin
merge = refs/heads/master" >> .git/config || { echo "failure!"; exit 1; }
echo "success."
# Push local repo to remote repo
echo -n "[*] Uploading repository..."
git push --all > /dev/null 2>&1 || { echo "failure!"; exit 1; }
echo "success."
# Run the post command if there is one
if [ "$POSTCMD" != "" ]; then
echo -n "[*] Running post-command..."
ssh $options $connection "$POSTCMD" || { echo "failure!"; exit 1; }
echo "success."
fi
# Kill the ssh control master, delete gitssh wrapper
echo -n "[*] Cleaning up..."
ssh $options -O exit $connection 2> /dev/null || echo "\n\tClean up failed: could not kill ssh control master."
rm $gitsshpath > /dev/null || echo "\n\tClean up failed: could not delete git ssh wrapper."
echo "success."
echo "Complete!"
|