-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashcreatewp
executable file
·156 lines (127 loc) · 5.8 KB
/
bashcreatewp
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
#!/bin/bash
#Create wordpress theme script
#Version: 1.0.0
#default string of wpdefault.mysql. Do not change if you know what you're doing.
default_sql_string='name_of_thang'
# DB user pass.
dbuser='root'
dbpass=''
# Assets_wp recommended have : woocommerce, revolution slider, contactform, regenerate thumbnail, visual composer, wordpress
assets_wp=/home/thang/xampp/assets_WP
# Create a directory to store all your htdocs folder in here. It will auto symlink into ${htdocs_path} when your web folder is created.
web_root=/home/thang/xampp
# Git source folder
gitsrc=/home/thang/solazu-git
# Path to htdocs folder indicate where to symlink web_root to.
htdocs_path=/opt/lampp/htdocs
for (( i=0 ; ; i++ ))
do
echo "Nhap. ten WP muon\' tao. \n";
echo "Type \" :q \" to exit";
read wp_name
case $wp_name in
'')
echo 'empty'
;;
':q')
break ;
;;
':Q')
break ;
;;
*)
array=("${array[@]}" $wp_name)
;;
esac
done
# Coppy Wordpress and symlink plugin to ${web_root}
for wp_name in ${array[@]}
do
if [ ! -d ${web_root}/${wp_name} ]; then
cp -rf ${assets_wp}/wordpress/ ${web_root}/$wp_name
ln -s ${assets_wp}/revslider ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/js_composer ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/contact-form-7 ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/contact-form-7-dynamic-text-extension ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/newsletter/ ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/woocommerce/ ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/yith-woocommerce-wishlist/ ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/yith-woocommerce-zoom-magnifier/ ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/wp-user-avatar/ ${web_root}/$wp_name/wp-content/plugins/
ln -s ${assets_wp}/regenerate-thumbnails/ ${web_root}/$wp_name/wp-content/plugins/
else
echo ${wp_name} 'already have in' ${web_root}/${wp_name}
fi
if [ -d ${gitsrc}/${wp_name} ] ;then
#symlink git code/theme
ln -s ${gitsrc}/$wp_name/code/theme ${web_root}/$wp_name/wp-content/themes/$wp_name
else
echo 'not found' ${gitsrc}/${wp_name}
fi
if [ -d ${gitsrc}/solazu-core/solazu-unyson ] ; then
ln -s ${gitsrc}/solazu-core/solazu-unyson ${web_root}/$wp_name/wp-content/plugins/
fi
if [ -d ${gitsrc}/${wp_name}/code/plugin ] ; then
ln -s ${gitsrc}/${wp_name}/code/plugin ${web_root}/$wp_name/wp-content/plugins/
fi
#=====================Create wp_config.php=============================#
mv ${web_root}/$wp_name/wp-config-sample.php ${web_root}/$wp_name/wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/${wp_name}/g" ${web_root}/$wp_name/wp-config.php
perl -pi -e "s/username_here/$dbuser/g" ${web_root}/$wp_name/wp-config.php
perl -pi -e "s/password_here/$dbpass/g" ${web_root}/$wp_name/wp-config.php
#set WP salts
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' ${web_root}/$wp_name/wp-config.php
sed -i.bak "s|\/\* That's all, stop editing! Happy blogging. \*\/|define('FS_METHOD','direct');|g" ${web_root}/$wp_name/wp-config.php
sed -i.bak "s|define('WP_DEBUG', false);|define('WP_DEBUG', true);|g" ${web_root}/$wp_name/wp-config.php
#====================Done create wp-config===============#
sudo chmod -R 777 ${web_root}/$wp_name/
if [ -f /opt/lampp/htdocs/$wp_name ];then
rm -f $htdocs_path/$wp_name
fi
#symlink to opt/lampp/htdocs
sudo ln -s ${web_root}/$wp_name/ $htdocs_path/
sudo chown daemon:daemon $htdocs_path/$wp_name
#====================Import Mysql database==========================#
cp -rf wpdefault.sql wpdefaultON.sql
#change string of wpdefault.sql from default {string} to ${wp_name}
sed -i 's|'"$default_sql_string"'|'"$wp_name"'|g' wpdefaultON.sql
echo "==============================="
echo "Database ${wp_name} processing"
echo "==============================="
exist_db=`mysqlshow -u ${dbuser} ${wp_name}| grep -v Wildcard | grep -o ${wp_name}`
if [ "$exist_db" == "${wp_name}" ]; then
# Existing database.
echo "Do you want delete curent database & create new one? (y/n)"
read -e newdb
if [ $newdb == y ]; then
mysql -u${dbuser} -e "DROP DATABASE IF EXISTS \`${wp_name}\`; CREATE DATABASE \`${wp_name}\`;"
else
break
fi
else
# Create database.
mysql -u${dbuser} -e "DROP DATABASE IF EXISTS \`${wp_name}\`; CREATE DATABASE \`${wp_name}\`;"
fi
#show databases
mysql -u${dbuser} -e "show databases;"
echo "==============================="
echo "Importing default database"
echo "user:ad pass:ad"
echo "==============================="
#import mysql
mysql -uroot $wp_name < wpdefaultON.sql
#change wpdefault.sql to default {string}
sed -i 's|'"$wp_name"'|'"$default_sql_string"'|g' wpdefault.sql
# delete wpdefaultON.sql
rm -f wpdefaultON.sql
google-chrome localhost/$wp_name & disown
done
echo 'Created:' ${array[@]}