-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrucapify.sh
executable file
·238 lines (188 loc) · 5.99 KB
/
drucapify.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#! /bin/bash
function usage () {
cat <<EOF
Usage: scriptname [-d folder] [-p project] [-g git repo] [-b git branch] [-i remote ip] [-u user] [-h]
-d the folder you're going to install this
-p project name
-g defines the git repo
-b defines the git branch
-i defines the remote ip
-u defines the user
-s defines the domain
-t initializing git repo
-h displays basic help
EOF
}
if [ "$1" = "-h" ]
then
usage
exit 0
fi
while getopts p:d:g:b:i:u:h:s:m o
do case "$o" in
p) APPLICATION="$OPTARG";;
d) PROJECT="$OPTARG";;
g) REMOTE_GIT="$OPTARG";;
b) BRANCH="$OPTARG";;
i) REMOTE_IP="$OPTARG";;
u) USER="$OPTARG";;
s) DOMAIN="$OPTARG";;
m) MAMP="$OPTARG";;
\?) echo "Invalid option: -$OPTARG" >&2
usage
exit 1
esac
done
shift $OPTIND-1
if [ "$PROJECT" = "" ]; then
echo "give me a project name"
exit 0
fi
if [ "$APPLICATION" = "" ]; then
echo "give me an application name"
exit 0
fi
if [ "$REMOTE_GIT" = "" ]; then
REMOTE_GIT=$APPLICATION
fi
if [ "$BRANCH" = "" ]; then
BRANCH="master"
fi
if [ "$REMOTE_IP" = "" ]; then
REMOTE_IP="cap.nois3lab.it"
fi
if [ "$USER" = "" ]; then
USER="nois3lab"
fi
if [ "$DOMAIN" != "" ]; then
DOMAIN=$APPLICATION
fi
clear
if [ ! -d "$PROJECT/sites" ]; then
echo "$PROJECT/sites"
echo "This is for Drupal projects, please provide a 'sites' folder"
exit 1
else
rm -rf /tmp/Drushistrano
echo " "
echo " "
echo "---------------------------------------------"
echo " Checking if this is already drucapified "
echo "---------------------------------------------"
echo " "
echo " "
if [ -d "includes/deploy" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
clear
echo "Cheers! the project is already drucapified!"
exit 1
else
echo "[ok!]"
echo " "
echo " "
echo "---------------------------------------------"
echo " Cloning script for the black magic "
echo "---------------------------------------------"
echo " "
echo " "
git clone https://github.com/carl0s/Drushistrano.git /tmp/Drushistrano
echo "[ok!]"
echo " "
echo " "
echo "---------------------------------------------"
echo " SETTING UP THE ENVIRONMENT FOR CAPISTRANO "
echo "---------------------------------------------"
echo " "
echo " "
cd $PROJECT
rm -rf .git
rm -rf .gitignore
echo "[ok!]"
echo -n "You're in "
echo -n `pwd`
echo -n " folder"
echo " "
echo " "
echo " "
echo " "
echo "---------------------------------------------"
echo " Preparing environment for cosy deployment "
echo "---------------------------------------------"
echo " "
echo " "
cp /tmp/Drushistrano/Capfile .
cp -R /tmp/Drushistrano/includes/deploy includes/
sed -i -bak "s/#APPLICATION_NAME#/$APPLICATION/g" includes/deploy/stages.rb
sed -i -bak "s/#REMOTE_GIT_PATH#/$REMOTE_GIT/g" includes/deploy/stages.rb
sed -i -bak "s/#BRANCH#/$BRANCH/g" includes/deploy/stages.rb
sed -i -bak "s/#REMOTE_SERVER_IP#/$REMOTE_IP/g" includes/deploy/stages.rb
sed -i -bak "s/#USER#/$USER/g" includes/deploy/stages.rb
sed -i -bak "s/#DOMAIN#/$DOMAIN/g" includes/deploy/stages.rb
cp .htaccess htaccess
cd $PROJECT/sites
echo "[ok!]"
echo " "
echo " "
echo "---------------------------------------------"
echo " Removing old default folder from drupal "
echo "---------------------------------------------"
echo " "
echo " "
rm -rf default
cp -R /tmp/Drushistrano/default-development .
cp -R /tmp/Drushistrano/default-production .
echo " "
echo "executed "
echo -n cp -R /tmp/Drushistrano/default-production .
echo " "
echo "executed "
echo -n cp -R /tmp/Drushistrano/default-development .
echo " [ok!]"
echo " "
echo " "
echo "---------------------------------------------"
echo " Creating the right domain "
echo "---------------------------------------------"
echo " "
echo " "
cp -R /tmp/Drushistrano/default $APPLICATION
mkdir $APPLICATION/files
echo " "
echo "executed "
echo -n cp -R /tmp/Drushistrano/default $APPLICATION
echo " [ok!]"
echo " "
echo " "
echo "---------------------------------------------"
echo " Symlinking for the win "
echo "---------------------------------------------"
echo " "
echo " "
ln -s $APPLICATION default
echo " "
echo "executed "
echo -n ln -s $APPLICATION default
echo " [ok!]"
if [ ! -d "$PROJECT/.git" ]; then
echo " "
echo " "
echo "---------------------------------------------"
echo " Initializing Git environment "
echo "---------------------------------------------"
echo " "
echo " "
git init $PROJECT/.
cp /tmp/Drushistrano/gitignore .gitignore
git add .
git commit -am "Initial commit"
git add -f $PROJECT/sites/$APPLICATION/settings.development.php
git add -f $PROJECT/sites/$APPLICATION/settings.production.php
git remote add origin [email protected]:$REMOTE_GIT.git
echo "[ok!]"
else
git add -f $PROJECT/sites/$APPLICATION/settings.development.php
git add -f $PROJECT/sites/$APPLICATION/settings.production.php
git commit -am "Adding settings to repository"
fi
fi
fi