-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewProject.bash
341 lines (271 loc) · 7.81 KB
/
newProject.bash
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
# Build Project Directories
# v18
# Last Updated: Nov. 15, 2016
# Documentation:
# https://www.nickyeoman.com/blog/workflow/18-creating-a-new-web-project-directory
# Gist:
# https://gist.github.com/760ca8af6b868be3301d.git
# GitHub:
# https://github.com/nickyeoman/NYScripts/blob/master/newProject.bash
# Use like this: bash newProject.bash domainName.com dbname dbuser dbpass
# REQUIREMENTS
# Joomla 3.6.4
# Ubuntu/debian:
# You need an internet connection (to pull from github)
##
# Variables
##
projectDir=/git #full path to install directory
salt=$RANDOM
sinstall=https://downloads.joomla.org/cms/joomla3/3-6-4/joomla_3-6-4-stable-full_package-zip?format=zip
htacc=https://raw.githubusercontent.com/nickyeoman/NYScripts/master/htaccess.txt
humans=https://raw.githubusercontent.com/nickyeoman/NYScripts/master/humans.txt
robots=https://raw.githubusercontent.com/nickyeoman/NYScripts/master/robots.txt
wmtools=https://raw.githubusercontent.com/nickyeoman/NYScripts/master/google5e5f3b5cfa769687.html
linuxusername=nick
linuxgroup=nick
#Project Domain
if [ -z "$1" ]; then
echo -n "What is the domain name for this project? [DomainName]"
read domain
else
domain=$1
fi
##
# Create Directories
##
cd $projectDir
#check if dir exists
directory=$projectDir/$domain
if [ -d "$directory" ]; then
echo "$directory already exists"
exit 0
fi
#create folders
mkdir $domain
cd $projectDir/$domain
mkdir scripts sql apache frostybot
mkdir sql/backup
mkdir apache/ssl
##
# Database info
##
#db name
if [ -z "$2" ]; then
notld=`echo $domain | sed 's/\(.*\)\..*/\1/'` #no tld
#make it pretty for plesk (optional)
len=${#notld}
if [ $len -gt 7 ]; then
firstpart=`echo $notld | cut -c1-7`
dbname=${firstpart}_joomla
else
dbname=${notld}_joomla
fi
else
dbname=$2
fi
#db user
if [ -z "$3" ]; then
dbuser=`echo $dbname`
#make it pretty for plesk (optional)
len=${#notld}
if [ $len -gt 5 ]; then
firstpart=`echo "$dbuser" | cut -c1-5`
dbuser=${firstpart}_joomla
else
dbuser=${notld}_joomla
fi
else
dbuser=$3
fi
#dbpass
if [ -z "$4" ]; then
cd sql
wget https://raw.github.com/nickyeoman/NYScripts/master/sha1.php
dbpass=`php sha1.php $domain $salt $salt`
dbpass=`echo "$dbpass" | cut -c1-16`
rm sha1.php
cd $projectDir
else
dbpass=$4
fi
##
# Grab Nick Yeoman's scripts
##
cd $projectDir/$domain/scripts
wget https://raw.github.com/nickyeoman/NYScripts/master/database.bash
wget https://raw.github.com/nickyeoman/NYScripts/master/config.bash
wget https://raw.github.com/nickyeoman/NYScripts/master/remove.bash
wget https://raw.github.com/nickyeoman/NYScripts/master/sslupdate.bash
wget https://raw.github.com/nickyeoman/NYScripts/master/testing-checklist.bash
cat <<xFiledumpx > dump_db.bash
./database.bash d $dbname $dbuser $dbpass localhost
xFiledumpx
cat <<xFileupdatex > update_db.bash
./database.bash u $dbname $dbuser $dbpass localhost
xFileupdatex
cd $projectDir/$domain
#--------Begin Config sql document-----------#
cat <<xFileconfigsqlx > $projectDir/$domain/sql/config.sql
-- DB Name: $dbname
-- DB User: $dbuser
-- DB Pass: $dbpass
-- Remove Existing Database
DROP DATABASE IF EXISTS $dbname;
-- Create database
CREATE DATABASE $dbname;
-- Make remove user (create one to suppress errors)
GRANT USAGE ON *.* TO '$dbuser'@'localhost';
-- Drop the user
DROP USER '$dbuser'@'localhost';
-- Create the correct user with correct password
GRANT ALL PRIVILEGES ON $dbname.* to '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';
xFileconfigsqlx
#----------End document-----------#
#--------Begin Config sql document-----------#
cat <<xFileremovesqlx > $projectDir/$domain/sql/remove.sql
-- Remove Existing Database
DROP DATABASE IF EXISTS $dbname;
-- Drop the user
DROP USER '$dbuser'@'localhost';
xFileremovesqlx
#----------End document-----------#
##
# Create Apache config file (config.sh uses this)
##
cd $projectDir/$domain/apache
project=`echo $domain | sed 's/\(.*\)\..*/\1/'`
#--------Begin here document-----------#
cat <<xFileconfigshx > $domain.conf
<VirtualHost *:80>
ServerName $domain
ServerAlias www.$domain *.$domain $project.ny $project.fb
DocumentRoot $projectDir/$domain/public/
ServerAdmin [email protected]
<Directory $projectDir/$domain/public/>
Options +Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error_$domain.log
</VirtualHost>
# https://www.digitalocean.com/community/tutorials/how-to-set-up-multiple-ssl-certificates-on-one-ip-with-apache-on-ubuntu-12-04
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName $domain
ServerAlias www.$domain *.$domain $project.ny $project.fb
DocumentRoot $projectDir/$domain/public/
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /git/$domain/apache/ssl/apache.crt
SSLCertificateKeyFile /git/$domain/apache/ssl/apache.key
<Directory /git/$domain/public/>
Options +Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error_$domain.log
</VirtualHost>
</IfModule>
xFileconfigshx
#----------End here document-----------#
##
# Install Joomla to Public
##
mkdir $projectDir/$domain/public
cd $projectDir/$domain/public
wget $sinstall -O joomla.zip
unzip -e *.zip
rm -rf *.zip
cd $projectDir/$domain
##
# Pull stuff from Frostybot.com
##
cd $projectDir/$domain/public
wget $humans #humans.txt
wget $robots #robots.txt
wget $wmtools #Google webmaster tools
wget $htacc --output-document=.htaccess #get custom htaccess
# Pump in db info to installer
cd installation/view/database/tmpl
sed -i "s/getInput('db_user')/getInput('db_user',null,'$dbuser')/g" default.php
sed -i "s/getInput('db_pass')/getInput('db_pass',null,'$dbpass')/g" default.php
sed -i "s/getInput('db_name')/getInput('db_name',null,'$dbname')/g" default.php
cd $projectDir/$domain
##
# README file for gitlab
##
cat <<xFilereadmex > README.md
# Info for $domain
# INSTALLATION
## First Time
* [ ] Have your root system and mysql username and password ready
* [ ] Run 'sudo bash config.bash' to install the database
* [ ] Configure your DNS or /etc/hosts file
* [ ] Go to the domain and run the Joomla web installer
* [ ] Dump the database 'sudo bash dump_db.bash'
* [ ] Create the git repo 'git init'
* [ ] Add your remote
* [ ] Push to remote
## From repo
* git clone url name
* cd scripts && sudo bash config.bash
#Billing Information
Monthly Maintenance plan for the rate of *amount* until *date*.
## Contact Information
Name:
Email:
Phone:
Contact Page:
# Domain Name
Domain Name is registered at:
With the username:
# DNS
Name Servers are pointed to: Cloudflare
# Hosting
Currently on server: lamp.frostybot.com
# Email
MX record currently points to: Fbemail.net
# Website
Currently running: Joomla
## SMTP
* SMTP Sends through sendgrid with username
## Joomla Core Edits
No core edits at this Time
## Joomla plugins installed
* osmap
* frostyform
* FJT Template
* bruteforce
* rokpad
* rokboost
## Databse config
* DB Name: $dbname
* DB User: $dbuser
* DB Pass: $dbpass
xFilereadmex
#----------End here document-----------#
## Permissions
cd $projectDir/$domain/scripts
chmod u+x *
cd $projectDir/$domain
##
# All Done
##
cat <<xtalkToMex
****************************************
Installation Finished
Your domain ($domain) is setup
Go to $projectDir/$domain and open
README.md for more info
****************************************
xtalkToMex
exit