-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffold.sh
executable file
·71 lines (62 loc) · 2.92 KB
/
scaffold.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
#!/bin/bash
########## Function Creation ##########
function error_exit
{
echo "$1" 1>&2
exit 1
}
function print_files
{
number=1
for file in /home/hgdesign/www/themes/WordPress/zipfiles/*
do
echo "$number. ${file:45}"
(( number++ ))
themes[${number-1}]=${file:45}
done
}
########## Get User Input ##########
echo -e "User?"
read cpaneluser
echo -e "Domain?"
read domain
password="hostgator123"
########## Create Script Variables ##########
validator=""
WPPATH=/home/$cpaneluser/www/
MYSQLUSER="$cpaneluser"_wrdp1
MYSQLDBNAME="$cpaneluser"_wrdp1
MYSQLPASS=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1`
########## Create cPanel Account ##########
/scripts/wwwacct $domain $cpaneluser $password 1000 0 n n n 10 10 10 10 10 5000 y hgdesign hgdesign_default 10 10 || error_exit "Could not create cPanel User account, script terminating"
########## Create DB For Use by WP ##########
mysql -u root --execute="CREATE DATABASE ${MYSQLDBNAME};" || error_exit "Could not create MySQL Database ${MYSQLDBNAME}, script terminating"
mysql -u root --execute="CREATE USER '${MYSQLUSER}'@'localhost' IDENTIFIED BY '${MYSQLPASS}';" || error_exit "Could not create MySQL User ${MYSQLUSER}, script terminating"
mysql -u root --execute="GRANT ALL PRIVILEGES ON ${MYSQLDBNAME} . * TO '${MYSQLUSER}'@'localhost';" || error_exit "Could not assign ${MYSQLUSER} to ${MYSQLDBNAME} successfully, script terminating"
########## Map the Database to the correct cPanel User ########
/usr/local/cpanel/bin/dbmaptool $cpaneluser --type mysql --dbs $MYSQLDBNAME
########## Create WordPress Install ###########
cd $WPPATH || error_exit "Could not move to correct WP directory, $WPPATH, script terminating"
su $cpaneluser -c "wp core download --force" || error_exit "Could not download WordPress Core, script terminating"
su $cpaneluser -c "wp core config --dbname=$MYSQLDBNAME --dbuser=$MYSQLUSER --dbpass=$MYSQLPASS" || error_exit "Could not configure the WordPress Install on the correct Database ${MYSQLDBNAME}, script terminating"
su $cpaneluser -c "wp core install --url=\"198.20.227.88/~$cpaneluser\" --title=\"New WordPress\" --admin_user=\"$cpaneluser\" --admin_password=\"hostgator123\" --admin_email=\"dbarron@hostgator.com\"" || error_exit "Could not install correct variables to WordPress DB / Installation, script terminating"
########## Get User Theme Choice ##########
number=1
choice=""
themes[0]=""
validator="n"
while [ "$validator" != "y" ]; do
print_files
echo -e "Which theme would you like? (Enter 0 for no theme)"
read choice
theme=${themes[$choice+1]}
echo "You chose #$choice. $theme. Is that correct?"
read validator
done
if [ "$choice" != "0" ]; then
echo "You chose $theme, installing and activating."
cd /home/$cpaneluser/www
cp /home/hgdesign/www/themes/WordPress/zipfiles/$theme ./$theme
perms $cpaneluser
su $cpaneluser -c "wp theme install $theme --activate"
fi