forked from james2doyle/git-website-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkproject
executable file
·110 lines (81 loc) · 2.12 KB
/
mkproject
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /usr/bin/env bash
#
# mkproject
#
# Create git-capable, self-hosted, projects easily.
#
# James Doyle(james2doyle)
# Copyright 2013 MIT
red=$(tput setaf 1 || tput AF 1)
green=$(tput setaf 2 || tput AF 2)
yellow=$(tput setaf 3 || tput AF 3)
blue=$(tput setaf 4 || tput AF 4)
magenta=$(tput setaf 5 || tput AF 5)
cyan=$(tput setaf 6 || tput AF 6)
reset=$(tput sgr0)
# grab the name of the project to also be used as the folder names
echo -n "Project name > "
read folder
# check for the existance of $folder
if [[ -e "$folder" ]]; then
printf "$red$folder already exists. Use another name or remove $folder\n$reset"
exit 1
fi
hubFolder="${folder}_hub.git"
thisPath="${PWD}"
printf "Creating $red$hubFolder$reset repo hub\n\n"
mkdir "$hubFolder"
cd "$hubFolder"
git --bare init --shared=all
touch hooks/post-receive
chmod u+x hooks/post-receive
# creating htaccess so that you cant see the .git directory
touch .htaccess
cat > .htaccess <<- _EOF_
Order allow,deny
Deny from all
_EOF_
printf "Created$yellow .htaccess$reset to deny http access\n\n"
cat > hooks/post-receive <<- _EOF_
#!/bin/sh
echo "pulling changes to live site directory"
cd $(printf $thisPath/$folder)
unset GIT_DIR
git pull hub master
exec git-update-server-info
_EOF_
printf "Created$yellow .git/hooks/post-receive$reset with hub pull\n\n"
# start prime folder creation
cd ../
printf "Creating $red$folder$reset site folder\n\n"
mkdir "$folder"
cd "$folder"
git init --shared=all
touch .git/hooks/post-commit
chmod u+x .git/hooks/post-commit
cat > .git/hooks/post-commit <<- _EOF_
#!/bin/sh
echo "pushing changes to hub"
git push hub master
_EOF_
printf "\nCreated$yellow .git/hooks/post-commit$reset with push to hub\n\n"
git remote add hub $(echo $thisPath)/$hubFolder
git remote show hub
touch .gitignore
cat > .gitignore <<- _EOF_
.DS_Store
_EOF_
printf "\ncreated$yellow .gitignore$reset\n\n"
touch README.md
cat > README.md <<- _EOF_
$folder
==================
Created on $(TZ=EST date)
_EOF_
printf "created$yellow README.md$reset\n\n"
git add .
git commit -m 'initial'
git push hub master
cd ../
printf "$green\nFINISHED CREATING $folder PROJECT$reset\n\n"
exit 0