blob: 3ed5bee945fc2482c0d39d50fba9f78c86848e5c (
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
|
#!/bin/sh
# Copyright 2017 rsiddharth <s@ricketyspace.net>
#
# This work is free. You can redistribute it and/or modify it under
# the terms of the Do What The Fuck You Want To Public License,
# Version 2, as published by Sam Hocevar. See the COPYING file or
# <http://www.wtfpl.net/> for more details.
usage ()
{
echo '\n Usage: '\
'\n\n'\
' ./gitb-init.sh REPO_NAME [REPOS_DIR] [REMOTE_HOST]'\
'\n'\
'\n REPOS_DIR - Bare repos directory; if not specified'\
'\n $GITBI_DIR is used.'\
'\n'\
'\n REMOTE_HOST - Remote host name (user@host.name); if'\
'\n not specfied $GITBI_HOST is used'\
'\n Examples: '\
'\n\n'\
' ./gitb-init.sh project-snafu.git vcs/git/projects user@fortytwo.net\n'\
'\n Will install bare git repository $HOME/vcs/git/projects/project-snafu.git'\
'\n at host fortytwo.net.'\
'\n\n'\
' ./gitb-init.sh project-snafu.git vcs/git/projects\n'\
'\n Will install bare git repository $HOME/vcs/git/projects/project-snafu.git'\
'\n at host defined by environment variable $GITBI_HOST.'\
'\n\n'\
' ./gitb-init.sh project-snafu.git\n'\
'\n Will install bare git repository $HOME/GITBI_DIR/project-snafu.git'\
'\n at host defined by environment variable $GITBI_HOST, where path GITBI_DIR'\
'\n is defined by environment variable $GITBI_DIR.'\
'\n'
}
ssh_cmd()
{
ssh <<-EOF $REMOTE_HOST\
'mkdir -p '$REPO_PATH\
'&& cd '$REPO_PATH\
'&& git init --bare'\
'&& mv hooks/post-update.sample hooks/post-update'
EOF
}
# Get repo name.
if [ ! -z $1 ]; then
REPO_NAME=$1
else
echo 'ERROR: Repo name not specified.'
usage
exit 1
fi
# Get repos directory name.
if [ ! -z $2 ]; then
REPOS_DIR=$2
elif [ ! -z $GITBI_DIR ]; then
REPOS_DIR=$GITBI_DIR
else
echo 'ERROR: Bare repos directory not specified.'
usage
exit 1
fi
# Get remote host.
if [ ! -z $3 ]; then
REMOTE_HOST=$3
elif [ ! -z $GITBI_HOST ]; then
REMOTE_HOST=$GITBI_HOST
else
echo 'ERROR: Host not specified.'
usage
exit 1
fi
REPO_PATH=$REPOS_DIR'/'$REPO_NAME
ssh_cmd
|