-
Notifications
You must be signed in to change notification settings - Fork 51
/
WordPress
executable file
·120 lines (100 loc) · 3.32 KB
/
WordPress
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
#! /bin/bash
TEMP=$HOME/temp
#WORDPRESS_DIR=wordpress
#WORDPRESS_DATA_OWNER=foo
#$WORDPRESS_DATA_PASSWORD=bar
if [ -z "$ELF_UTILS" ]; then
echo "ELF_UTILS is unset";
exit 1
else
echo "ELF_UTILS is set to '$ELF_UTILS'";
fi
if [ -z "$ELF_AA_CODE" ]; then
echo "ELF_AA_CODE is unset";
exit 1
else
echo "ELF_AA_CODE is set to '$ELF_AA_CODE'";
fi
if [ -z "$WORDPRESS_DIR" ]; then
echo "WORDPRESS_DIR is unset";
exit 1
else
echo "WORDPRESS_DIR is set to '$WORDPRESS_DIR'";
fi
if [ -z "$WORDPRESS_DATA_OWNER" ]; then
echo "WORDPRESS_DATA_OWNER is unset"
exit 1
else
echo "WORDPRESS_DATA_OWNER is set to '$WORDPRESS_DATA_OWNER'";
fi
if [ -z "$WORDPRESS_DATA_PASSWORD" ]; then
echo "WORDPRESS_DATA_PASSWORD is unset."
exit 1
else
echo "WORDPRESS_DATA_PASSWORD is set.";
fi
APACHE_FILE_INFO=( $(stat -c "%a %G %U" /var/www/html) )
APACHE_PERMISSIONS=${APACHE_FILE_INFO[0]}
APACHE_GROUP=${APACHE_FILE_INFO[1]}
APACHE_OWNER=${APACHE_FILE_INFO[2]}
if [ ! $APACHE_OWNER = $USER ]; then
echo "The /var/www/html directory is not owned by the current user"
echo "consider: sudo chown -R $USER:$USER /var/www/html"
exit 1
fi
# getScriptDirectory was found on StackOverflow. It's not mine.
# Set $SCRIPT_DIR. Call before you navigate (CD) to another directory
function getScriptDirectory() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE"
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}
function tempDir() {
if [ -d $TEMP ]; then
cd $TEMP
pwd
else
mkdir $TEMP
cd $TEMP
pwd
fi
}
function setupWpContent() {
cd $WORDPRESS_DIR
cp wp-config-sample.php wp-config.php
# These three lines work, but are commented out as they may need to be customized above
sed -i -- 's/database_name_here/'$WORDPRESS_DIR'/' wp-config.php
sed -i -- 's/username_here/'$WORDPRESS_DATA_OWNER'/' wp-config.php
sed -i -- 's/password_here/'$WORDPRESS_DATA_PASSWORD'/' wp-config.php
echo 'Updating, please supply sudo password at first prompt, press enter, then enter the MySQL password'
sudo chown -R www-data:www-data wp-content/
cd ..
}
function download() {
if [ ! -d $WORDPRESS_DIR ]; then
# sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
setupWpContent
mv $WORDPRESS_DIR /var/www/html/.
fi
}
function mysqlSetup-Old {
echo 'Updating MySql. Please supply MYSQL password'
mysql -u root -p -e 'create database wordpress;'
mysql -u root -p -e 'GRANT ALL PRIVILEGES ON wordpress.* TO "root"@"localhost" IDENTIFIED BY "foobar";'
mysql -u root -p -e 'FLUSH PRIVILEGES;'
mysql -u root -p -e 'use wordpress; show grants for 'root'@'localhost';'
}
function mysqlSetup {
mysql -u root -p -e 'source '$SCRIPT_DIR'/wordpress.sql;'
}
getScriptDirectory
tempDir
download
mysqlSetup