forked from creativecommons/commoners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·211 lines (143 loc) · 6.77 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
################################################################################
# TO RE-EXPORT CONTENT FROM LIVE
################################################################################
# THIS CODE IS NOT MEANT TO BE RUN AS PART OF THIS SCRIPT!
# COPY AND RUN THE CODE IN THE IF ON LIVE, NOT THE MACHINE TO INSTALL ON!
# THEN COPY THE RESULTING FILES INTO PLACE HERE.
: '
WPXMLFILE="/tmp/commoners-wordpress.xml"
GFJSONFILE="/tmp/gravityforms-export.json"
WPEMAILSFILE="/tmp/commoners-emails.json"
wp export --post_type=page --stdout > "${WPXMLFILE}"
wp plugin install gravityformscli --activate
wp gf form export --dir=/tmp
cp "/tmp/gravityforms-export-$(date -u +%Y-%m-%d).json" "${GFJSONFILE}"
wp option list --format=json --search=ccgn-email-* > "${WPEMAILSFILE}"
'
################################################################################
# BEFORE STARTING
################################################################################
: '
# INSTALL APACHE, MYSQL
sudo apt install php-gd
# CREATE WORDPRESS SITE CONFIG FOR THIS SITE
'
################################################################################
# Config
################################################################################
source "$(dirname "$0")/config.sh"
################################################################################
# Check for paths and files
################################################################################
if [ ! -d ${GITROOT} ]; then
echo "Git checkout directory ${GITROOT} doesn't exist"
exit
fi
if [ ! -d ${WPROOT} ]; then
echo "WordPress install directory ${WPROOT} doesn't exist"
exit
fi
if [ ! -f ${WPXMLFILE} ]; then
echo "Cannot find ${WPXMLFILE}"
exit
fi
if [ ! -f ${GFJSONFILE} ]; then
echo "Cannot find ${GFJSONFILE}"
exit
fi
################################################################################
# Install wp-cli
################################################################################
if [ ! $(which wp) ]; then
pushd /tmp
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
popd
# FIX DOWNLOAD BUG AS OF 2017-10-12
#sudo wp cli update --nightly
fi
################################################################################
# Install and configure WordPress
################################################################################
cd "${WPROOT}"
${WPCLI} core download
${WPCLI} config create \
--dbname="${DBNAME}" --dbuser="${DBUSER}" --dbpass="${DBPASSWORD}"
${WPCLI} core install \
--url="${SITEURL}" --title="${SITENAME}" \
--admin_user="${ADMINNAME}" --admin_password="${ADMINPASSWORD}" \
--skip-email --admin_email="${ADMINEMAIL}"
# So BuddyPress activates
${WPCLI} rewrite structure '/%year%/%monthnum%/%day%/%postname%/'
################################################################################
# Fetch and link our repos
################################################################################
# Handle the repo already being present, for dev machines
if [ ! -d "${GITROOT}/commoners" ]; then
cd "${GITROOT}"
sudo git clone https://github.com/creativecommons/commoners.git
sudo chown -R "${WEBUSER}:${WEBGROUP}" commoners
fi
cd "${WPROOT}/wp-content/plugins"
sudo -u "${WEBUSER}" ln -s "${GITROOT}/commoners/plugins/cas-maestro"
sudo -u "${WEBUSER}" ln -s "${GITROOT}/commoners/plugins/cc-global-network"
cd "${WPROOT}/wp-content/themes"
sudo -u "${WEBUSER}" ln -s "${GITROOT}/commoners/themes/cc-commoners"
################################################################################
# Set up plugins
################################################################################
cd "${WPROOT}"
${WPCLI} plugin delete hello
# To make the admin a member later
wp package install buddypress/wp-cli-buddypress
${WPCLI} plugin install multiple-roles --activate
${WPCLI} plugin install if-menu --activate
${WPCLI} plugin install akismet --activate
${WPCLI} plugin install buddypress --activate
#${WPCLI} bp component deactivate activity
#${WPCLI} bp component deactivate notifications
#${WPCLI} bp component activate groups
${WPCLI} bp component activate xprofile
# For importing pages
${WPCLI} plugin install wordpress-importer --activate
${WPCLI} plugin install gravityformscli --activate
${WPCLI} gf install --key="${GFORMSKEY}"
${WPCLI} plugin activate gravityforms
${WPCLI} option update wpCAS_settings \
'{"cas_version": "1.0",
"server_hostname": "login.creativecommons.org",
"server_port": "443",
"server_path": ""}' --format=json
${WPCLI} option update wpCAS_settings '{"cas_menu_location":"sidebar","new_user":"1","email_suffix":"","cas_version":"2.0","server_hostname":"login.creativecommons.org","server_port":"443","server_path":"","e-mail_registration":"2","global_sender":"info@creativecommons.org","full_name":"","welcome_mail":{"send_user":true,"send_global":false,"subject":"","user_body":"","global_body":""},"wait_mail":{"send_user":true,"send_global":false,"subject":"","user_body":"","global_body":""},"ldap_protocol":"3","ldap_server":"","ldap_username_rdn":"","ldap_password":"","ldap_basedn":"","ldap_port":null}' --format=json
#${WPCLI} plugin activate cas-maestro
#${WPCLI} option update rg_gforms_key "${GFORMSKEY}"
${WPCLI} plugin activate cc-global-network
################################################################################
# Set up theme
################################################################################
${WPCLI} theme activate cc-commoners
################################################################################
# Remove the default post and page
################################################################################
${WPCLI} post delete ${DELETEPAGES}
################################################################################
# Copy in forms
################################################################################
${WPCLI} gf form import "${GFJSONFILE}"
################################################################################
# Copy in content
################################################################################
${WPCLI} import --authors=skip "${WPXMLFILE}"
${WPCLI} option update show_on_front "page"
${WPCLI} option update page_on_front "${WPFRONTPAGE}"
################################################################################
# Copy in emails
################################################################################
for i in $(seq 0 $(expr $(jq '. | length' "${WPEMAILSFILE}") - 1)); do
key=$(jq .[$i].option_name "${WPEMAILSFILE}")
value=$(jq .[$i].option_value "${WPEMAILSFILE}")
wp option update "${key}" "${value}"
done