-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
197 lines (180 loc) · 6.59 KB
/
setup.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
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
#!/usr/bin/env bash
#
# WP SETUP FILE
#
# Author: Flurin Dürst » github.com/flurinduerst
# URL: https://github.com/flurinduerst/WPDistillery
#
# File version 1.6.1
# ERROR Handler
# ask user to continue on error
function continue_error {
read -p "$(echo -e "${RED}Do you want to continue anyway? (y/n) ${NC}")" -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
printf "\n${RED}»»» aborting WPDistillery setup! ${NC}\n"
exit 1
else
printf "\n${GRN}»»» continuing WPDistillery setup... ${NC}\n"
fi
}
trap 'continue_error' ERR
# REQUIREMENTS
####################################################################################################
# YAML PARSER FUNCTION
function parse_yaml() {
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_]*'
fs="$(echo @|tr @ '\034')"
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
awk -F"$fs" '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
}
}' | sed 's/_=/+=/g'
}
# DEFINE COLORS
RED='\033[0;31m' # error
GRN='\033[0;32m' # success
BLU='\033[0;34m' # task
BRN='\033[0;33m' # headline
NC='\033[0m' # no color
# EXECUTIVE SETUP
####################################################################################################
printf "${BRN}========== WPDISTILLERY START ==========${NC}\n\n"
# READ CONFIG
eval $(parse_yaml config.yml "CONF_")
# CHECK WP FOLDER
if [ ! -d "$CONF_wpfolder" ]; then
mkdir $CONF_wpfolder
printf "${BLU}»»» creating WP Folder $CONF_wpfolder...${NC}\n"
fi
cd $CONF_wpfolder
# INSTALL WORDPRESS
if $CONF_setup_wp ; then
printf "${BRN}[=== INSTALL WORDPRESS ===]${NC}\n"
printf "${BLU}»»» downloading WordPress...${NC}\n"
wp core download --locale=$CONF_wplocale
printf "${BLU}»»» creating wp-config...${NC}\n"
wp core config --dbname=$CONF_db_name --dbuser=$CONF_db_user --dbpass=$CONF_db_pass --dbprefix=$CONF_db_prefix --locale=$CONF_wplocale
printf "${BLU}»»» installing wordpress...${NC}\n"
wp core install --url=$CONF_wpsettings_url --title="$CONF_wpsettings_title" --admin_user=$CONF_admin_user --admin_password=$CONF_admin_password --admin_email=$CONF_admin_email
else
printf "${BLU}>>> skipping WordPress installation...${NC}\n"
fi
if $CONF_setup_settings ; then
printf "${BLU}»»» configure settings...${NC}\n"
printf "» timezone:\n"
wp option update timezone $CONF_timezone
wp option update timezone_string $CONF_timezone
printf "» permalink structure:\n"
wp rewrite structure "$CONF_wpsettings_permalink_structure"
wp rewrite flush
printf "» description:\n"
wp option update blogdescription "$CONF_wpsettings_description"
printf "» image sizes:\n"
wp option update thumbnail_size_w $CONF_wpsettings_thumbnail_width
wp option update thumbnail_size_h $CONF_wpsettings_thumbnail_height
wp option update medium_size_w $CONF_wpsettings_medium_width
wp option update medium_size_h $CONF_wpsettings_medium_height
wp option update large_size_w $CONF_wpsettings_large_width
wp option update large_size_h $CONF_wpsettings_large_height
if ! $CONF_wpsettings_convert_smilies ; then
wp option update convert_smilies 0
fi
if $CONF_wpsettings_page_on_front ; then
printf "» front page:\n"
# create and set frontpage
wp post create --post_type=page --post_title="$CONF_wpsettings_page_on_front_frontpage_name" --post_content='Front Page created by WPDistillery' --post_status=publish
wp option update page_on_front $(wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename="$CONF_wpsettings_page_on_front_frontpage_name" --field=ID --format=ids)
wp option update show_on_front 'page'
fi
else
printf "${BLU}>>> skipping settings...${NC}\n"
fi
# INSTALL THEME
if $CONF_setup_theme ; then
printf "${BRN}[=== INSTALL $CONF_theme_name ===]${NC}\n"
printf "${BLU}»»» downloading $CONF_theme_name...${NC}\n"
wp theme install $CONF_theme_url
printf "${BLU}»»» installing/activating $CONF_theme_name...${NC}\n"
if [ ! -z "$CONF_theme_rename" ]; then
# rename theme
printf "${BLU}»»» renaming $CONF_theme_name to $CONF_theme_rename...${NC}\n"
# check if git source
if [ ! -z "$CONF_theme_source_branch" ]; then
mv wp-content/themes/$CONF_theme_name-$CONF_theme_source_branch wp-content/themes/$CONF_theme_rename
else
mv wp-content/themes/$CONF_theme_name wp-content/themes/$CONF_theme_rename
fi
wp theme activate $CONF_theme_rename
else
# check if git source
if [ ! -z "$CONF_theme_source_branch" ]; then
mv wp-content/themes/$CONF_theme_name-$CONF_theme_source_branch wp-content/themes/$CONF_theme_name
else
wp theme activate $CONF_theme_name
fi
fi
else
printf "${BLU}>>> skipping theme installation...${NC}\n"
fi
# CLEANUP
if $CONF_setup_cleanup ; then
printf "${BRN}[=== CLEANUP ===]${NC}\n"
if $CONF_setup_cleanup_comment ; then
printf "${BLU}»»» removing default comment...${NC}\n"
wp comment delete 1 --force
fi
if $CONF_setup_cleanup_posts ; then
printf "${BLU}»»» removing default posts...${NC}\n"
wp post delete 1 2 --force
fi
if $CONF_setup_cleanup_files ; then
printf "${BLU}»»» removing WP readme/license files...${NC}\n"
# delete default files
if [ -f readme.html ]; then rm readme.html; fi
if [ -f license.txt ]; then rm license.txt; fi
# delete german files
if [ -f liesmich.html ]; then rm liesmich.html; fi
fi
if $CONF_setup_cleanup_themes ; then
printf "${BLU}»»» removing default themes...${NC}\n"
wp theme delete twentyfourteen
wp theme delete twentyfifteen
wp theme delete twentysixteen
fi
else
printf "${BLU}>>> skipping Cleanup...${NC}\n"
fi
# PLUGINS
if $CONF_setup_plugins ; then
printf "${BRN}[=== PLUGINS ===]${NC}\n"
printf "${BLU}»»» removing WP default plugins${NC}\n"
wp plugin delete akismet
wp plugin delete hello
printf "${BLU}»»» adding active plugins${NC}\n"
for entry in "${CONF_plugins_active[@]}"
do
wp plugin install $entry --activate
done
printf "${BLU}»»» adding inactive plugins${NC}\n"
for entry in "${CONF_plugins_inactive[@]}"
do
wp plugin install $entry
done
else
printf "${BLU}>>> skipping Plugin installation...${NC}\n"
fi
# MISC
printf "${BLU}»»» checking wp cli version${NC}\n"
wp cli check-update
printf "${BRN}========== WPDISTILLERY FINISHED ==========${NC}\n"