-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_drupal_site.sh
executable file
·98 lines (80 loc) · 3.19 KB
/
create_drupal_site.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
#!/bin/bash
if [ -z $1 ]; then
echo "Usage: create_drupal_site.sh newprojectname"
exit 0
fi
NAME=${1:0:64}
SQLNAME=${NAME:0:16}
cd ~/htdocs
drush make https://bitbucket.org/alexfisher/compro_install_profile/raw/master/make/compro.make $NAME
cd $NAME
# Create drush alias file.
mkdir sites/all/drush
touch sites/all/drush/$NAME.aliases.drushrc.php
echo "Creating drush alias file..."
echo "<?php" >> sites/all/drush/$NAME.aliases.drushrc.php
echo "" >> sites/all/drush/$NAME.aliases.drushrc.php
echo "\$aliases['dev-"$USER"'] = array(" >> sites/all/drush/$NAME.aliases.drushrc.php
echo " 'uri' => '"$NAME".dev'," >> sites/all/drush/$NAME.aliases.drushrc.php
echo " 'root' => '/home/"$USER"/htdocs/"$NAME"'," >> sites/all/drush/$NAME.aliases.drushrc.php
echo ");" >> sites/all/drush/$NAME.aliases.drushrc.php
# Create files directory.
echo "Creating files directory..."
mkdir sites/default/files
chmod 777 sites/default/files
# Create settings.php file.
echo "Creating settings.php file..."
cp sites/default/default.settings.php sites/default/settings.php
chmod 777 sites/default/settings.php
# Create a password.
PASS=${NAME//o/0}
PASS=${PASS//i/1}
PASS=${PASS//e/3}
PASS=${PASS//a/@}
# Create database.
read -s -p "Enter your MYSQL root user password: " SQLPASS
mysql -uroot -p$SQLPASS -e "create database $NAME"
mysql -uroot -p$SQLPASS -e "grant all on $NAME.* to $SQLNAME@localhost identified by '$PASS'"
# Install site.
drush site-install compro --db-url=mysql://$SQLNAME:$PASS@localhost/$NAME --account-name=admin --account-pass=$PASS --site-name=$NAME
# Setup apache vhost.
APACHE=/etc/apache2/sites-available
sudo touch $APACHE/$NAME
echo Wrote the following to $APACHE/$NAME
echo "<VirtualHost *:80>" | sudo tee -a $APACHE/$NAME
echo " ServerName "$NAME.dev | sudo tee -a $APACHE/$NAME
echo " ServerAlias *."$NAME.dev | sudo tee -a $APACHE/$NAME
echo " DirectoryIndex index.php index.html" | sudo tee -a $APACHE/$NAME
echo " DocumentRoot /home/"$USER"/htdocs/"$NAME | sudo tee -a $APACHE/$NAME
echo " <Directory /home/"$USER"/htdocs/"$NAME">" | sudo tee -a $APACHE/$NAME
echo " Options -Indexes FollowSymLinks" | sudo tee -a $APACHE/$NAME
echo " AllowOverride All" | sudo tee -a $APACHE/$NAME
echo " Order allow,deny" | sudo tee -a $APACHE/$NAME
echo " allow from all" | sudo tee -a $APACHE/$NAME
echo " </Directory>" | sudo tee -a $APACHE/$NAME
echo " ErrorLog /var/log/apache2/"$NAME.dev_error.log | sudo tee -a $APACHE/$NAME
echo " CustomLog /var/log/apache2/"$NAME.dev_access.log combined | sudo tee -a $APACHE/$NAME
echo "</VirtualHost>" | sudo tee -a $APACHE/$NAME
echo Activating site...
sudo a2ensite $NAME
echo Done.
echo Restarting apache2...
sudo service apache2 restart
echo Done.
# Add hosts entry.
echo Adding vhost entry to hosts file...
echo 127.0.0.1" "$NAME.dev | sudo tee -a /etc/hosts
echo Done.
# Initial git commit.
git init
git add .
git commit -m "Initial commit."
git branch -m master stage
git branch qa
git branch prod
echo Visit the new site @ http://$NAME.dev
echo Username: admin
echo Password: $PASS
# Change settings.php permissions
chmod 444 sites/default/settings.php
exit 0