-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare-git-repo
executable file
·49 lines (40 loc) · 1.48 KB
/
share-git-repo
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
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` <folder-with-.git-inside>"
exit 65; # BADARGS
fi
PARENT="`dirname $1`"
REPO="`basename $1`"
GIT_DIR="$PARENT/$REPO/.git"
if [ ! -d "$GIT_DIR" ]; then
# check if the repo is bare
echo "$REPO" | grep "\w\.git\$" > /dev/null
if [ $? -eq 0 ]; then
GIT_DIR="$PARENT/$REPO"
# if it's bare, then enable push
OPTS="--enable=receive-pack"
else
echo ".git not found in $GIT_DIR"
exit 65;
fi
fi
DO_EXPORT="touch $GIT_DIR/git-daemon-export-ok"
CLEAN_EXPORT="rm $GIT_DIR/git-daemon-export-ok"
START_DAEMON="git daemon --reuseaddr --base-path=$PARENT $OPTS $PARENT"
echo "[debug] $DO_EXPORT"
exec `$DO_EXPORT`
if [ "$?" -ne 0 ]; then echo "\tCommand failed"; exit 1; fi
echo "[debug] $START_DAEMON"
echo "Try to clone your repo:"
#echo "git clone git://localhost/$REPO"
ifconfig | sed 's/:/ /g' | grep -B1 "inet" | awk '{ if ( $1 == "inet" ) { print $3 } else if ( $2 == "inet" ) { print $3 } }' | xargs printf "git clone git://%s/$REPO \n"
echo "Note: to share through the internet you should be able to access port 9418"
exec `$START_DAEMON` &
if [ "$?" -ne 0 ]; then echo "\tCommand failed"; exit 1; fi
# wait until ENTER is pressed
read -p "Press ENTER to exit" var # var is the variable where read stores the user input
# kill the process
kill -9 `ps aux | grep git-daemon | grep -v grep | awk '{ print $2 }'`
# remove the export file
echo "[debug] $CLEAN_EXPORT"
exec `$CLEAN_EXPORT`