forked from syedaali/bashbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitbox
executable file
·72 lines (61 loc) · 1.62 KB
/
gitbox
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
#!/bin/bash
#
usage()
{
cat << EOF
Create a bare repo in Dropbox git and clone to ~/git
gitbox <repo_name>
OPTIONS:
-h show this message
-c create a repo of <name> (but gitbox can be called without options as above)
EOF
exit 1
}
while getopts "hc:" option
do
case $option in
c) repo=$OPTARG;;
h) usage;;
*) usage;;
esac
done
repo=$1
TXTDEF='\033[0m' # everything back to defaults
BAKPUR='\033[37;1;45m' # purple background
BAKRED='\033[37;1;41m' # red background
BAKGRN='\033[37;1;42m' # green background
GIT_DROPBOX_DIR=~/Dropbox/Git
LOCAL_GIT_DIR=~/git
git_dropbox_repo=$GIT_DROPBOX_DIR/${repo}.git
local_dropbox_repo=$LOCAL_GIT_DIR/$repo
if [ -d $git_dropbox_repo ]; then
echo -e "${BAKRED}[FAIL]${TXTDEF} Git bare repo $git_dropbox_repo already exists. Aborting."
exit 1
fi
if [ -d $local_dropbox_repo ]; then
echo -e "${BAKRED}[FAIL]${TXTDEF} Directory $local_dropbox_repo already exists. Aborting."
exit 1
fi
if [ -d $repo ]; then
echo -e "${BAKRED}[FAIL]${TXTDEF} Directory $repo already exists. Aborting."
exit 1
fi
echo -e "${BAKPUR}[NOTICE]${TXTDEF} Creating repo"
git init $git_dropbox_repo --bare
git clone -q $git_dropbox_repo $repo
echo 'Cloned dropbox git repo into: '${local_dropbox_repo}
OWD=$PWD
if [ $PWD != "$HOME/git" ]; then
echo 'Creating symlink to '$repo
ln -s $OWD/$repo $HOME/git/$repo
fi
echo "Adding and committing README.md to the repo"
cd $OWD/$repo
echo "$repo repo" > README.md
git add README.md
git commit -m "initial commit"
echo "Pushing to Dropbox git bare repo"
git push origin master
cd $OWD
echo -e "${BAKGRN}[SUCCESS!]${TXTDEF}"
exit 0