.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Prime Mover (PrimeMover.io)
2 |
3 | # CAUTION!!!
4 |
5 | This is all VERY alpha right now. This isn't anything inherently "destructive" about this script other than the fact that it can theoretically fill your hard drive up in the process of making tar/gz clones of all of your sites.
6 |
7 | *Use at your own risk!*
8 |
9 | # Description:
10 |
11 | PrimeMover.sh is a bash script that facilitates migration of WordPress sites into and out of servers managed by [GridPane.com](https://gridpane.com), ServerPilot, RunCloud, and some CPanel installations (currently only out of CPanel).
12 |
13 | This is a somewhat neutered version of the MigrateSafely migration tool we use internally at GridPane.com to migrate sites into our clients servers.
14 |
15 | Currently the following migrations are tested and working:
16 |
17 | ServerPilot -> GridPane servers *WORKS*
18 |
19 | RunCloud -> GridPane servers *WORKS*
20 |
21 | EasyEngine/Webinoly -> GridPane servers *WORKS*
22 |
23 | Some "Stock" Cpanel -> GridPane servers *WORKS*
24 |
25 | ServerPilot -> ServerPilot *WORKS*
26 |
27 | ServerPilot -> RunCloud *WORKS* (Sites must be manually built in RunCloud FIRST)
28 |
29 | RunCloud -> ServerPilot *WORKS* (Single User - i.e. "runcloud" to "serverpilot")
30 |
31 | All other migration "combinations" not explicitly listed above (i.e. RunCloud -> RunCloud) are NOT yet implemented or testing fails.
32 |
33 | Currently you need to have root access to both the source server and the destination. With all server types *other than GridPane* this works best if you've already generated a SSH key pair on both sides and have exchanged those keys and successfully tested a root login from the source to the destination.
34 |
35 | At the very least you'll need the root password for the destination server and root logins need to be allowed.
36 |
37 | Best of luck! Drop me a line at patrick at gridpane dot com
38 |
39 | # INSTALL
40 |
41 | More documentation on this will be forthcoming.
42 |
43 | But basically:
44 |
45 | 1.) Download primemover.sh
46 |
47 | 2.) Run "chmod +x primemover.sh"
48 |
49 | 3.) Run "mv primemover.sh /usr/local/bin/primemover"
50 |
51 | 4.) Run "primemover" and the script will automatically detect what the source machine is and guide you through the migration process.
52 |
53 | # Notes
54 |
55 | As this was built from our internal tools it obviously works best for migrating things into GridPane. In order to migrate into GridPane servers all you'll need your account API key which is accessible inside your account dashboard. SSH key exchange is handled automatically.
56 |
57 | I'm not planning to build a version of this that doesn't explicitly use SSH keys. Knock yourself out.
58 |
59 | I am also not planning on building a version of this which allows migration into CPanel/Plesk/similar. It's complicated enough getting sites OUT of CPanel and given that they don't have API site builds it's even more complicated to try to get sites to migrate in. This could be built obviously but you'd always need to manually build the sites at the destination.
60 |
61 | I will eventually build in the necessary mechanisms to migrate sites out of GridPane and into these other control panels but this is not a priority at this moment as I've yet to have anyone request this. All of the code required to do so is actually already there, if you know what you're looking for.
62 |
63 | Building sites on RunCloud currently can't be automated. You'll need to manually build them first. Their API is supposed to be coming by the end of February 2018 and we'll obviously circle back on this. Given the multi-step nature of manually building WordPress sites in RunCloud we will likely not work on additional RunCloud migration paths (i.e. RunCloud -> RunCloud) until their API is complete.
64 |
65 | This ONLY Migrates WordPress sites and NOTHING else.
66 |
67 | Please test and let me know if you hit any snags.
68 |
69 | Copyright 2018 - K. Patrick Gallagher
70 |
71 | Sponsored by GridPane.com
72 | 
73 |
--------------------------------------------------------------------------------
/primemover.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # PrimeMover.io
4 |
5 | # Universal WordPress VPS Migration Assistant
6 |
7 | # Copyright 2018 PrimeMover.io - K. Patrick Gallagher
8 |
9 | # Easily move WordPress sites between two different servers managed by GridPane, ServerPilot, RunCloud and Others...
10 |
11 | # You'll need to already have manually built your sites at RunCloud and have WordPress successfully running there BEFORE trying to move sites in from other sources.
12 | # ServerPilot site build code (via API) is already built but needs to be reintegrated to this work.
13 |
14 | source ~/.bash_profile
15 |
16 | if [[ $EUID -ne 0 ]]; then
17 | echo "This script must be run as root, exiting!!!"
18 | exit 1
19 | fi
20 |
21 | # Check is PV is installed, and install if needed...
22 | if ! type "pv" > /dev/null; then
23 | echo "PV was not installed... fixing..."
24 | apt -y install pv
25 | fi
26 |
27 | mkdir -p /var/tmp/primemover
28 |
29 | ipaddress=$(curl http://ip4.ident.me 2>/dev/null)
30 |
31 | MigrateType=$1
32 |
33 | MeImCounting() {
34 |
35 | echo "This is all very VERY aplha right now. Use at your own risk."
36 | echo " "
37 | echo "All kinds of things might be broken. It's a work in progress and we'll get it hammered out shortly."
38 | echo " "
39 | echo "Please feel free to help out."
40 | echo " "
41 | echo "Best of luck! Drop me a line at patrick at gridpane dot com"
42 | echo " "
43 | echo "You need to have already created SSH keys on both your source server and your destination server and shared them between the two."
44 | echo " "
45 | echo "This all automatically works if you're using GridPane because we (try, at least, to) kick all of the asses."
46 |
47 | }
48 | MeImCounting
49 |
50 | CommandVariablesCheck() {
51 |
52 | #THIS IS OLD AND WILL SOON BE KILLED!!!
53 | #THIS IS OLD AND WILL SOON BE KILLED!!!
54 | #THIS IS OLD AND WILL SOON BE KILLED!!!
55 |
56 | # Checking correct startup variables
57 | if [ -z "$1" ] || [ -z "$2" ]
58 | then
59 | echo " "
60 | echo " "
61 | echo " ***************************************"
62 | echo "******* ERROR - MISSING VARIABLES *******"
63 | echo " ***************************************"
64 | echo " "
65 | echo " "
66 | echo "Command line variables required: "
67 | echo " "
68 | echo " 1.) URL/ALL "
69 | echo " 2.) Target IP address "
70 | echo " 3.) *OPTIONAL* Source API token (GridPane servers only - ServerPilot and RunCloud API support coming soon) "
71 | echo " 4.) *OPTIONAL* Target API token (GridPane servers only - ServerPilot and RunCloud API support coming soon) "
72 |
73 | # LOTS of work needs to be added in here to make this work seamlessly between SP and RC nodes, and between RC and RC, and between SP and SP, and... you get the point.
74 | echo " "
75 | echo " "
76 | exit 187;
77 |
78 | else
79 | # Set all the primary variables - Additional Variables - REQUIRED - But we'll get these soon... appname username finaldomain
80 | site_to_clone=$1
81 | remote_IP=$2
82 | sourcetoken=$3
83 | targettoken=$3
84 | fi
85 |
86 | }
87 |
88 | # Install WP-CLI - Makes everything so much easier!!!
89 | CheckWPcli() {
90 |
91 | if [ -f /usr/local/bin/wp ]
92 | then
93 | echo "WP-CLI is already installed, making sure it's the most current version..."
94 | yes | wp cli update --allow-root
95 | else
96 | curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
97 | chmod +x wp-cli.phar
98 | sudo mv wp-cli.phar /usr/local/bin/wp
99 | fi
100 |
101 |
102 | if [ -f /usr/local/bin/wp-completion.bash ]
103 | then
104 | if grep -q "source /usr/local/bin/wp-completion.bash" ~/.bash_profile; then
105 | echo "WP-CLI Bash Completion already set..."
106 | else
107 | echo "source /usr/local/bin/wp-completion.bash" >> ~/.bash_profile
108 | fi
109 | else
110 | wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
111 | mv wp-completion.bash /usr/local/bin/wp-completion.bash
112 |
113 | echo "source /usr/local/bin/wp-completion.bash" >> ~/.bash_profile
114 | fi
115 |
116 | }
117 | CheckWPcli
118 |
119 | ServerPilotShell() {
120 |
121 | #Check if ServerPilot API is Installed...
122 | if [ -f "/usr/local/bin/serverpilot" ]
123 | then
124 | echo "ServerPilot API Already Installed!"
125 | sed -i 's/printf "%-20s"/printf "%-30s"/g' /usr/local/bin/serverpilot #Fixes the column bleed issue...Just making sure here!
126 | source ~/.bash_profile
127 | else
128 | #install jq
129 | sudo apt-get -y install jq
130 | curl -sSL https://raw.githubusercontent.com/kodie/serverpilot-shell/master/lib/serverpilot.sh > /usr/local/bin/serverpilot
131 | chmod a+x /usr/local/bin/serverpilot
132 | sed -i 's/printf "%-20s"/printf "%-25s"/g' /usr/local/bin/serverpilot #Fixes the column bleed issue...
133 | echo "Enter ClientID from ServerPilot Account..."
134 | read clientID
135 | echo "Enter API Key from ServerPilot Account..."
136 | read APIkey
137 | printf '\nexport serverpilot_client_id="'$clientID'"\nexport serverpilot_api_key="'$APIkey'"' >> ~/.bash_profile && source ~/.bash_profile
138 | fi
139 |
140 | }
141 |
142 |
143 | # Check is SSH key present, if not make it so... This currently only applies to migrating IN to GridPane servers...
144 | # Disabled by default because while I may be a total egotistical prick I recognize that you're MUCH more likely to be running on a SP or RC node than a GridPane managed box.
145 |
146 | DoSSH() {
147 |
148 | if [ "$y" = "1" ]
149 | then
150 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
151 | return 1
152 | fi
153 |
154 | remote_IP=$1
155 |
156 | ipaddress=$(curl http://ip4.ident.me 2>/dev/null)
157 |
158 | if [ -f /root/.ssh/id_rsa.pub ]
159 | then
160 | echo "Local SSH Keys exist..."
161 | echo ""
162 |
163 | else
164 | echo "We need to create a public key pair..."
165 | echo "CREATING SSH!!!"
166 |
167 | #echo -e "\n\n\n" | ssh-keygen -t rsa -b 4096
168 | ssh-keygen -t rsa -b 4096 -N "" -f /root/.ssh/id_rsa
169 |
170 | fi
171 |
172 | echo "Checking remote connection to $remote_IP..."
173 |
174 | sshcheck=$(ssh-keygen -F $remote_IP 2>&1)
175 |
176 | if [ $? -eq 0 ]
177 | then
178 | echo "Remote host is already in the Known Hosts file..."
179 | echo ""
180 | else
181 |
182 | echo "Adding remote system at $remote_IP..."
183 |
184 | ssh-keyscan $remote_IP >> /root/.ssh/known_hosts
185 |
186 | echo "Remote host $remote_IP added to the known hosts file..."
187 | fi
188 |
189 | sshtatus=$(ssh -o BatchMode=yes -o ConnectTimeout=5 $remote_IP echo ok 2>&1)
190 |
191 | if [ "$sshtatus" == "ok" ]
192 | then
193 | echo "Remote SSH Test Successful..."
194 | else
195 | if [[ $MigrateType == "RC2GP" ]] || [[ $MigrateType == "SP2GP" ]] || [[ $MigrateType == "GP2GP" ]]
196 | then
197 | curl -F "ssh_key=@/root/.ssh/id_rsa.pub" -F "source_ip=$ipaddress" -F "failover_ip=$remote_IP" https://my.gridpane.com/api/pair-external-servers?api_token=$gridpanetoken
198 | echo "Remote host added to the Known Hosts file..."
199 | echo ""
200 | else
201 | echo "Attempting to connect to remote system at $remote_IP..."
202 |
203 | ssh-copy-id -i ~/.ssh/id_rsa.pub root@$remote_IP
204 | fi
205 |
206 | fi
207 |
208 | }
209 |
210 | GetSPUserAppDetails() {
211 |
212 | appholder=word$appnameCOL
213 | appname=$(echo ${!appholder})
214 |
215 | runholder=word$runtimeCOL
216 | php=$(echo ${!runholder})
217 |
218 | appidhold=word$appidCOL
219 | appid=$(echo ${!appidhold})
220 |
221 | serverhold=word$serveridCOL
222 | serverid=$(echo ${!serverhold})
223 |
224 | datehold=word$datecreatedCOL
225 | datecreated=$(echo ${!datehold})
226 |
227 | userhold=word$sysuserCOL
228 | sysuserid=$(echo ${!userhold})
229 |
230 | echo ""
231 | echo ""
232 | echo "Application Name/Folder is $appname"
233 | echo "PHP Version is $php"
234 | echo "User ID is $sysuserid"
235 | serverpilot sysusers $sysuserid > /var/tmp/primemover/source-user-name.txt
236 |
237 | serverCOL=$(awk -v name='serverid' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-user-name.txt)
238 | #echo "serverid Column is $serverCOL"
239 |
240 | usernameCOL=$(awk -v name='name' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-user-name.txt)
241 | #echo "UserName Column is $usernameCOL"
242 |
243 | userIDCOL=$(awk -v name='id' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-user-name.txt)
244 | #echo "UserID Column is $userIDCOL"
245 |
246 | sed '1d' /var/tmp/primemover/source-user-name.txt > /var/tmp/primemover/tmpfile; mv /var/tmp/primemover/tmpfile /var/tmp/primemover/source-user-name.txt
247 |
248 | if [ $usernameCOL -eq 1 ]
249 | then
250 | currentuser=$(awk '{print $1}' /var/tmp/primemover/source-user-name.txt)
251 | elif [ $usernameCOL -eq 2 ]
252 | then
253 | currentuser=$(awk '{print $2}' /var/tmp/primemover/source-user-name.txt)
254 | else
255 | currentuser=$(awk '{print $3}' /var/tmp/primemover/source-user-name.txt)
256 | fi
257 |
258 | currentuser=$(echo $currentuser|tr -d '\n')
259 | echo "System User Name for this App is $currentuser"
260 |
261 | }
262 |
263 | PushToSP() {
264 |
265 | #echo "Creating New System User $currentuser on Target Server $targetserver..."
266 |
267 | targetID=$(serverpilot find servers lastaddress=$targetserver id)
268 |
269 | if [[ $currentuser == "serverpilot" ]]
270 | then
271 | echo "Default serverpilot user already exists on remote system..."
272 | serverpilot find sysusers serverid=$targetID > /var/tmp/primemover/new-server-users.txt
273 | sed -r -n -e /$currentuser/p /var/tmp/primemover/new-server-users.txt > /var/tmp/primemover/new-user-details.txt
274 |
275 | newuserIDCOL=$(awk -v name='id' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/new-server-users.txt)
276 | #echo "New User ID Column is $newuserIDCOL"
277 |
278 | if [[ $newuserIDCOL -eq 1 ]]
279 | then
280 | newuserID=$(awk '{print $1}' /var/tmp/primemover/new-user-details.txt)
281 | elif [[ $newuserIDCOL -eq 2 ]]
282 | then
283 | newuserID=$(awk '{print $2}' /var/tmp/primemover/new-user-details.txt)
284 | else
285 | newuserID=$(awk '{print $3}' /var/tmp/primemover/new-user-details.txt)
286 | fi
287 | else
288 |
289 | MakeSPUser
290 |
291 | fi
292 |
293 | echo "Packaging up site..."
294 |
295 | #TARBALL THE SITE
296 |
297 | PackageSite
298 |
299 | echo "Default WP admin credentials are user $admin_user with email address $admin_email with pass $admin_password..."
300 |
301 | echo "Getting ready to build site $appdomain for application $appname for user ID $newuserID on PHP version $php ..."
302 |
303 | serverpilot apps create $appname $newuserID $php '["'$appdomain'","www.'$appdomain'"]' '{"site_title":"'$appname'","admin_user":"'$admin_user'","admin_password":"'$admin_password'","admin_email":"'$admin_email'"}'
304 |
305 | echo "Waiting for remote site build to complete..." #Add error checking here by routing that ^^^ output to a variable and checking it
306 |
307 | sleep 5
308 |
309 | scp $sitepack root@$remote_IP:/srv/users/$currentuser/apps/$appname/primemover-$appname-migration-file.gz
310 |
311 | sleep 1
312 |
313 | echo "Running remote restoration process..."
314 |
315 | if [[ $run == "1" ]]
316 | then
317 | ssh root@$remote_IP "sleep 3 && wget https://www.dropbox.com/s/1wpxv8kr9bfqz8i/primemover.sh && mv primemover.sh /usr/local/bin/primemover && chmod +x /usr/local/bin/primemover && sleep 1 && tar -xzf /srv/users/$currentuser/apps/$appname/primemover-$appname-migration-file.gz -C /srv/users/$currentuser/apps/$appname/public/ --overwrite && cd /srv/users/$currentuser/apps/$appname/public && echo $finaldomain > source.domain && primemover restore" < /dev/null
318 | else
319 | ssh root@$remote_IP "sleep 3 && wget https://www.dropbox.com/s/1wpxv8kr9bfqz8i/primemover.sh && mv primemover.sh /usr/local/bin/primemover && chmod +x /usr/local/bin/primemover && sleep 1 && tar -xzf /srv/users/$currentuser/apps/$appname/primemover-$appname-migration-file.gz -C /srv/users/$currentuser/apps/$appname/public/ --overwrite && cd /srv/users/$currentuser/apps/$appname/public && echo $finaldomain > source.domain && primemover restore" < /dev/null
320 | fi
321 |
322 | sleep 1
323 |
324 | echo "Remote restoration done... right?"
325 |
326 | }
327 |
328 | GetSPApps() {
329 |
330 | echo "These are all of the local apps we'll be moving..."
331 |
332 | echo ""
333 |
334 | cat /var/tmp/primemover/source-applications.txt
335 |
336 | sysuserCOL=$(awk -v name='sysuserid' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
337 |
338 | runtimeCOL=$(awk -v name='runtime' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
339 |
340 | appnameCOL=$(awk -v name='name' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
341 |
342 | serveridCOL=$(awk -v name='serverid' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
343 |
344 | datecreatedCOL=$(awk -v name='name' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
345 |
346 | appidCOL=$(awk -v name='id' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/source-applications.txt)
347 |
348 | }
349 |
350 | PickTargetSP() {
351 |
352 | serverpilot servers > /var/tmp/primemover/server-list.txt
353 |
354 | echo "Here's our raw SP Server details for all connected nodes..."
355 |
356 | cat /var/tmp/primemover/server-list.txt
357 |
358 | serverCOL=$(awk -v name='name' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/server-list.txt)
359 | #echo "Server Column is located: Column $serverCOL..."
360 |
361 | ipaddressCOL=$(awk -v name='lastaddress' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/server-list.txt)
362 | #echo "IP Address Column is located: Column $ipaddressCOL..."
363 |
364 | idCOL=$(awk -v name='id' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/server-list.txt)
365 | #echo "ID Column is located: Column $idCOL..."
366 |
367 | awk -v col=name 'NR==1{for(i=1;i<=NF;i++){if($i==col){c=i;break}} print $c} NR>1{print $c}' /var/tmp/primemover/server-list.txt > /var/tmp/primemover/server-names.txt
368 |
369 | awk -v col=lastaddress 'NR==1{for(i=1;i<=NF;i++){if($i==col){c=i;break}} print $c} NR>1{print $c}' /var/tmp/primemover/server-list.txt > /var/tmp/primemover/server-ips.txt
370 |
371 | awk -v col=id 'NR==1{for(i=1;i<=NF;i++){if($i==col){c=i;break}} print $c} NR>1{print $c}' /var/tmp/primemover/server-list.txt > /var/tmp/primemover/server-ids.txt
372 |
373 | echo ""
374 | echo "Please keep in mind: THIS CAN POTENTIALLY BE DESTRUCTIVE!!!"
375 | echo ""
376 | echo "###########################################################"
377 | echo "######## Beginning Migration and Provisioning... #########"
378 | echo "######## Here are your available Servers #########"
379 | echo "###########################################################"
380 | echo ""
381 | rownumber=0
382 | cp /var/tmp/primemover/server-names.txt /var/tmp/primemover/server-names.tmp
383 | sed -i -e "1d" /var/tmp/primemover/server-names.tmp
384 | sed -i -e "1d" /var/tmp/primemover/server-ips.txt
385 | sed -i -e "1d" /var/tmp/primemover/server-ids.txt
386 | while IFS=" " read -r entrydetail
387 | do
388 | rownumber=$((rownumber+1))
389 | currentIP=$(cat /var/tmp/primemover/server-ips.txt | awk '{print $"$ipaddressCOL"; exit}')
390 | currentID=$(cat /var/tmp/primemover/server-ids.txt | awk '{print $"$idCOL"; exit}')
391 | if [[ $currentIP == $ipaddress ]]
392 | then
393 |
394 | #Don't display this machine... it's obviously the source.
395 | sourcerow=$((rownumber+1))
396 | sourceserver=$entrydetail
397 | sourceID=$currentID
398 | sourceIP=$currentIP
399 |
400 | else
401 |
402 | echo "Server #$rownumber ... Named: $entrydetail ... with IP Address of $currentIP"
403 |
404 | fi
405 |
406 | sed -i -e "1d" /var/tmp/primemover/server-ips.txt
407 |
408 | done < "/var/tmp/primemover/server-names.tmp"
409 | echo ""
410 | echo "Enter Target Server By Number..."
411 | read targetServer
412 |
413 | #targetServer=$((targetServer+1)) #Increment the server line number by 1 to accomodate the heading line within the source output
414 |
415 | serveridsource=$(cat /var/tmp/primemover/server-ids.txt)
416 |
417 | servernames=$(cat /var/tmp/primemover/server-names.txt)
418 |
419 | targetID=$(echo "$serveridsource" | sed -n "$targetServer"p)
420 | remote_IP=$(serverpilot find servers id=$targetID lastaddress)
421 | echo ""
422 | echo ""
423 | echo "The target server has an ID of... $targetID... with IP Address $remote_IP"
424 | echo ""
425 | echo "The source server has an ID of... $sourceID... with IP Address $sourceIP"
426 | echo ""
427 | echo "These are all of the Source Applications on $sourceserver..."
428 | echo ""
429 |
430 | serverpilot find apps serverid=$(serverpilot find servers name=$sourceserver id) > /var/tmp/primemover/source-applications.txt
431 |
432 | GetSPApps
433 |
434 | # echo "systemuserid Column: $sysuserCOL - runtime Column: $runtimeCOL - AppName Column: $appnameCOL - ServerID Column: $serveridCOL - Date Column: $datecreatedCOL - AppID Column is $appidCOL"
435 |
436 | echo ""
437 | echo "To begin initializing ALL apps press ENTER... NOTE: User passwords will be reset on target node!"
438 |
439 | read desiredapps
440 |
441 | }
442 |
443 | SPtoSP() {
444 |
445 | # The intention here is to move sites from a ServerPilot node to another ServerPilot node
446 |
447 | PickTargetSP
448 |
449 | if [ -z "$desiredapps" ]
450 | then
451 |
452 | sed '1d' /var/tmp/primemover/source-applications.txt > /var/tmp/primemover/tmpfile; mv /var/tmp/primemover/tmpfile /var/tmp/primemover/source-applications.txt
453 | echo "Copying ServerPilot Sites..."
454 | run=0
455 | while IFS=" " read -r word1 word2 word3 word4 word5 word6
456 | do
457 |
458 | ((run++))
459 |
460 | GetSPUserAppDetails
461 |
462 | cd /srv/users/$currentuser/apps/$appname/public
463 |
464 | if ! $(wp core is-installed --allow-root);
465 | then
466 |
467 | echo "This is not a valid WordPress install, skipping this app!"
468 |
469 | else
470 |
471 | echo "Proceeding..."
472 |
473 | SingleSPDomain
474 |
475 | echo "The Final Domain for this application is $finaldomain"
476 |
477 | appdomain=$finaldomain
478 |
479 | PushToSP
480 |
481 | fi
482 |
483 | done < "/var/tmp/primemover/source-applications.txt"
484 |
485 | fi
486 | }
487 |
488 | MakeSPUser() {
489 |
490 |
491 | echo "Creating New System User $currentuser on Target Server $targetserver..."
492 |
493 | serverpilot sysusers create $targetserver $currentuser
494 | serverpilot find sysusers serverid=$SPRemoteIP > /var/tmp/primemover/new-server-users.txt
495 | sed -r -n -e /$currentuser/p /var/tmp/primemover/new-server-users.txt > /var/tmp/primemover/new-user-details.txt
496 |
497 | newuserIDCOL=$(awk -v name='id' '{for (i=1;i<=NF;i++) if ($i==name) print i; exit}' /var/tmp/primemover/new-server-users.txt)
498 | #echo "New User ID Column is $newuserIDCOL"
499 |
500 | if [[ $newuserIDCOL -eq 1 ]]
501 | then
502 | newuserID=$(awk '{print $1}' /var/tmp/primemover/new-user-details.txt)
503 | elif [[ $newuserIDCOL -eq 2 ]]
504 | then
505 | newuserID=$(awk '{print $2}' /var/tmp/primemover/new-user-details.txt)
506 | else
507 | newuserID=$(awk '{print $3}' /var/tmp/primemover/new-user-details.txt)
508 | fi
509 |
510 | randpass=$(openssl rand -base64 12)
511 | echo "New User $currentuser on Server $targetserver has ID $newuserID"
512 | serverpilot sysusers update $newuserID password $randpass
513 | echo "... and now has new random password $randpass"
514 |
515 | }
516 |
517 | BuildSPSite() {
518 |
519 | #MEH... This is gonna go.
520 |
521 | serverpilot apps create $appname $newuserID $php '["'$appdomain'","www.'$appdomain'"]' '{"site_title":"'$appname'","admin_user":"'$admin_user'","admin_password":"'$admin_password'","admin_email":"'$admin_email'"}'
522 |
523 | }
524 |
525 | RCtoSP() {
526 |
527 | echo "Confirming that we have the ServerPilot shell tools..."
528 | ServerPilotShell
529 |
530 | echo "Getting all local RunCloud site domains..."
531 | rcDomains
532 |
533 | echo ""
534 | echo "Are we moving all of these sites to the same server? Please enter YES or NO..."
535 |
536 | read SameSPforAll < /dev/tty
537 |
538 | if [[ $SameSPforAll == "YES" ]] || [[ $SameSPforAll == "yes" ]] || [[ $SameSPforAll == "Yes" ]] || [[ $SameSPforAll == "Y" ]] || [[ $SameSPforAll == "y" ]]
539 | then
540 | SameServer="yes"
541 |
542 | echo "What is the remote IP of the target ServerPilot server?"
543 |
544 | read targetserver < /dev/tty
545 |
546 | #remote_IP="$targetserver"
547 |
548 | DoSSH $targetserver
549 |
550 | else
551 | echo "We'll gather a different IP address for each site during the migration..."
552 | fi
553 |
554 |
555 | while read -r appname site_to_clone username rootfolder count
556 | do
557 |
558 | echo "Starting with site $site_to_clone from $rootfolder..."
559 |
560 | dots=$(echo "$site_to_clone" | awk -F. '{ print NF - 1 }')
561 |
562 | if [[ $site_to_clone == "staging."* ]] && [[ $dots -ge 2 ]]
563 | then
564 | echo "This is a staging site..."
565 | ShipOnly
566 |
567 | # NEED WORK HERE!!!
568 |
569 | elif [[ $site_to_clone == "canary."* ]] && [[ $dots -ge 2 ]]
570 | then
571 | echo "This is a UpdateSafely site, skipping..."
572 | else
573 |
574 | # FIND PHP HERE!!!
575 |
576 | if [ -f "/etc/php56rc/fpm.d/$appname.conf" ]
577 | then
578 | echo "PHP56RC file found... setting PHP to verison 5.6"
579 | php="php5.6"
580 | elif [ -f "/etc/php70rc/fpm.d/$appname.conf" ]
581 | then
582 | echo "PHP70RC file found... setting PHP to verison 7.0"
583 | php="php7.0"
584 | elif [ -f "/etc/php71rc/fpm.d/$appname.conf" ]
585 | then
586 | echo "PHP71RC file found... setting PHP to verison 7.1"
587 | php="php7.1"
588 | else
589 | echo "No PHP file found... defaulting to PHP7.0"
590 | php="php7.0"
591 | fi
592 |
593 | if [[ $SameServer == "yes" ]]
594 | then
595 | echo "We're using the same IP address $targetserver for all sites..."
596 | else
597 | echo "What is the remote IP of the target ServerPilot server for site $site_to_clone?"
598 |
599 | echo "You'll need the root password for the remote ServerPilot system and root password login access will need to be ON."
600 |
601 | read targetserver < /dev/tty
602 |
603 | #remote_IP="$targetserver"
604 |
605 | DoSSH $targetserver
606 |
607 | fi
608 |
609 | currentuser=$username
610 |
611 | if [[ $currentuser = "runcloud" ]]
612 | then
613 | echo "Current user is runcloud, switching to serverpilot..."
614 | currentuser=serverpilot
615 | else
616 | echo "We'll need to build this user $currentuser on the remote ServerPilot system..."
617 | fi
618 |
619 | #Make sure we don't have any underscores...
620 | echo $appname > tempfile
621 | appname=$(sed 's/\_/-/g' tempfile)
622 | rm tempfile
623 |
624 | appdomain=$site_to_clone
625 |
626 | PushToSP
627 |
628 | sleep 1
629 |
630 | echo "Running remote restoration process..."
631 |
632 |
633 | fi
634 |
635 | #echo "Getting next site..."
636 |
637 | done <"/var/tmp/primemover.domains.tmp2"
638 |
639 | echo "All sites processed!"
640 |
641 | }
642 |
643 | StartDomainLogging() {
644 |
645 | if [ -f /var/tmp/primemover.domains.tmp ]
646 | then
647 | rm /var/tmp/primemover.domains.tmp
648 | fi
649 | touch /var/tmp/primemover.domains.tmp
650 |
651 | echo ""
652 | echo "The following sites have been located on this server..."
653 | echo "************************************************************************************************************************"
654 | printf '%-20s %-40s %-20s %-30s %-30s\n' "APPLICATION" "DOMAIN" "USER" "LOCATION"
655 | echo "************************************************************************************************************************"
656 |
657 | }
658 |
659 | SingleRCDomain() {
660 |
661 | sourcedomain=$(awk '/server_name/,/;/' /etc/nginx-rc/conf.d/$appname.d/main.conf)
662 | sourcedomain=$(echo "$sourcedomain" | sed 's/\S*\_name\S*//g')
663 | sourcedomain=$(echo "${sourcedomain//;}") # Drop trailing semicolon
664 | sourcedomain2=$(echo "$sourcedomain" | sed 's/\S*\www\S*//g')
665 |
666 | rootfolder=$(awk '/root/,/;/' /etc/nginx-rc/conf.d/$appname.d/main.conf) # Grab root folder location
667 | rootfolder=$(echo $rootfolder | awk '{print $2;}')
668 | rootfolder=$(echo "${rootfolder//;}") # Drop trailing semicolon
669 |
670 | if [ ${#sourcedomain2} -lt 4 ]
671 | then
672 | finaldomain=$sourcedomain
673 | else
674 | finaldomain=$sourcedomain2
675 | fi
676 |
677 | if [ ${#finaldomain} -lt 3 ]
678 | then
679 |
680 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "NO DOMAIN!!!" "UNKNOWN" "$rootfolder ****SKIPPING****"
681 |
682 | else
683 | if [ -d $rootfolder ]
684 | then
685 | cd $rootfolder
686 | cd ../..
687 | username=$(basename $PWD)
688 |
689 | domaincount=$(echo $finaldomain | wc -w)
690 |
691 | if [ $domaincount == "1" ]
692 | then
693 | grid=work
694 | else
695 | #echo "This site has more than one domain! We're only able to process the first URL..."
696 | finaldomain=$(echo $finaldomain | awk '{print $1;}')
697 | fi
698 |
699 | finaldomain=$(echo "$finaldomain" | sed "s/ //g")
700 |
701 | dots=$(echo "$finaldomain" | awk -F. '{ print NF - 1 }')
702 |
703 | if [ $dots -ge 2 ]
704 | then
705 |
706 | if [[ $finaldomain == "staging."* ]]
707 | then
708 | if [[ $restore == "yes" ]]
709 | then
710 | echo "Final domain for this site: $finaldomain"
711 | else
712 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (STAGING)" $username $rootfolder
713 | fi
714 | else
715 | if [[ $restore == "yes" ]]
716 | then
717 | echo "Final domain for this site: $finaldomain"
718 | else
719 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (SUBDOMAIN)" $username $rootfolder
720 | fi
721 | fi
722 | else
723 | if [[ $restore == "yes" ]]
724 | then
725 | echo "Final domain for this site: $finaldomain"
726 | else
727 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain $username $rootfolder
728 | fi
729 | fi
730 |
731 | echo "$appname $finaldomain $username $rootfolder ${#finaldomain}" >> /var/tmp/primemover.domains.tmp
732 |
733 | else
734 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain "UNKNOWN!!!" "SITE ROOT FOLDER DAMAGED OR MISSING! ****SKIPPING****"
735 | fi
736 | fi
737 |
738 | }
739 |
740 | rcDomains() {
741 |
742 | search_dir="/etc/nginx-rc/conf.d"
743 |
744 | StartDomainLogging
745 |
746 | for entry in "$search_dir"/*
747 | do
748 |
749 | if [[ $entry == *".conf" ]]
750 | then
751 | # Skipping app .conf file...
752 | grid=work
753 | else
754 | #echo "Entry is $entry..."
755 | appname=$(basename $entry)
756 | appname=$(echo "${appname//.d}")
757 | SingleRCDomain
758 | fi
759 | done
760 |
761 | echo "************************************************************************************************************************"
762 | echo ""
763 | echo ""
764 | echo "PLEASE CONFIRM THIS LIST OF SITES LOOKS CORRECT... PRESS CTRL-Z to CANCEL if there is an error!!!"
765 | echo ""
766 | echo ""
767 | read -t 10 -n 1 -s -r -p "Press any key to confirm or wait ten seconds..." ;
768 | echo ""
769 |
770 | sort -k5 -n /var/tmp/primemover.domains.tmp > /var/tmp/primemover.domains.tmp2
771 |
772 | }
773 |
774 | SingleSPDomain() {
775 |
776 | sourcedomain=$(awk '/server_name/,/;/' /etc/nginx-sp/vhosts.d/$appname.conf)
777 | sourcedomain=$(echo "$sourcedomain" | sed '/server_name/d')
778 | sourcedomain=$(echo "$sourcedomain" | sed '/server-/d')
779 | sourcedomain=$(echo "$sourcedomain" | sed '/;/d')
780 | sourcedomain=$(echo "$sourcedomain" | awk '!a[$0]++')
781 | sourcedomain=$(echo "$sourcedomain" | sed "s/ //g")
782 | sourcedomain2=$(echo "$sourcedomain" | sed '/www./d')
783 |
784 | rootfolder=$(awk '/root/,/;/' /etc/nginx-sp/vhosts.d/$appname.conf) # Grab root folder location
785 | rootfolder=$(echo "${rootfolder//;}") # Drop trailing semicolon
786 | rootfolder=$(echo "${rootfolder//root }") # Drop root descriptor
787 |
788 | if [ ${#sourcedomain2} -lt 4 ]
789 | then
790 | finaldomain=$sourcedomain
791 | else
792 | finaldomain=$sourcedomain2
793 | fi
794 |
795 | if [ ${#finaldomain} -lt 3 ]
796 | then
797 |
798 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "NO DOMAIN!!!" "UNKNOWN" "$rootfolder ****SKIPPING****"
799 |
800 | else
801 | if [ -d $rootfolder ]
802 | then
803 | cd $rootfolder
804 | cd ../../..
805 | username=$(basename $PWD)
806 |
807 | domaincount=$(echo $finaldomain | wc -w)
808 |
809 | if [ $domaincount == "1" ]
810 | then
811 | grid=work
812 | else
813 | #echo "This site has more than one domain! We're only able to process the first URL..."
814 | finaldomain=$(echo $finaldomain | awk '{print $1;}')
815 | fi
816 |
817 | finaldomain=$(echo "$finaldomain" | sed "s/ //g")
818 |
819 | dots=$(echo "$finaldomain" | awk -F. '{ print NF - 1 }')
820 |
821 | if [ $dots -ge 2 ]
822 | then
823 | if [[ $finaldomain == "staging."* ]]
824 | then
825 | if [[ $restore == "yes" ]]
826 | then
827 | echo "Final domain for this site: $finaldomain"
828 | else
829 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (STAGING)" $username $rootfolder
830 | fi
831 | else
832 | if [[ $restore == "yes" ]]
833 | then
834 | echo "Final domain for this site: $finaldomain"
835 | else
836 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (SUBDOMAIN)" $username $rootfolder
837 | fi
838 | fi
839 | else
840 | if [[ $restore == "yes" ]]
841 | then
842 | echo "Final domain for this site: $finaldomain"
843 | else
844 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain $username $rootfolder
845 | fi
846 | fi
847 |
848 | echo "$appname $finaldomain $username $rootfolder ${#finaldomain}" >> /var/tmp/primemover.domains.tmp
849 |
850 | else
851 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain "UNKNOWN!!!" "SITE ROOT FOLDER DAMAGED OR MISSING! ****SKIPPING****"
852 | fi
853 | fi
854 |
855 | }
856 |
857 | spDomains() {
858 |
859 | search_dir="/etc/nginx-sp/vhosts.d"
860 |
861 | StartDomainLogging
862 |
863 | for entry in "$search_dir"/*
864 | do
865 |
866 | if [[ $entry != *".conf" ]]
867 | then
868 | grid=work
869 | else
870 | appname=$(basename $entry)
871 | appname=$(echo "${appname//.conf}")
872 | SingleSPDomain
873 | fi
874 | done
875 |
876 | echo "************************************************************************************************************************"
877 | echo ""
878 | echo ""
879 | echo "PLEASE CONFIRM THIS LIST OF SITES LOOKS CORRECT... PRESS CTRL-Z to CANCEL if there is an error!!!"
880 | echo ""
881 | echo ""
882 | read -t 10 -n 1 -s -r -p "Press any key to confirm or wait ten seconds..." ;
883 | echo ""
884 |
885 |
886 | sort -k5 -n /var/tmp/primemover.domains.tmp > /var/tmp/primemover.domains.tmp2
887 |
888 | }
889 |
890 | cpDomains() {
891 |
892 | search_dir="/home"
893 |
894 | StartDomainLogging
895 |
896 | for entry in "$search_dir"/*
897 | do
898 |
899 | if [[ -d "$entry"/etc ]]
900 | then
901 | cd $entry/etc/*/
902 | appname=$(basename $PWD)
903 |
904 | SingleCPDomain
905 | else
906 | echo "This doesn't appear to be a live Apache site..."
907 | fi
908 | done
909 |
910 | echo "************************************************************************************************************************"
911 | echo ""
912 | echo ""
913 | echo "PLEASE CONFIRM THIS LIST OF SITES LOOKS CORRECT... PRESS CTRL-Z to CANCEL if there is an error!!!"
914 | echo ""
915 | echo ""
916 | read -t 10 -n 1 -s -r -p "Press any key to confirm or wait ten seconds..." ;
917 | echo ""
918 |
919 |
920 | sort -k5 -n /var/tmp/primemover.domains.tmp > /var/tmp/primemover.domains.tmp2
921 |
922 | }
923 |
924 | SingleCPDomain() {
925 |
926 | sourcedomain="$appname"
927 |
928 | rootfolder="$entry/public_html/" # Grab root folder location
929 |
930 | finaldomain="$appname"
931 |
932 | if [ ${#finaldomain} -lt 3 ]
933 | then
934 |
935 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "NO DOMAIN!!!" "UNKNOWN" "$rootfolder ****SKIPPING****"
936 |
937 | else
938 | if [ -d $rootfolder ]
939 | then
940 | cd $rootfolder
941 | cd ..
942 | username=$(basename $PWD)
943 |
944 | dots=$(echo "$finaldomain" | awk -F. '{ print NF - 1 }')
945 |
946 | if [ $dots -ge 2 ]
947 | then
948 | if [[ $finaldomain == "staging."* ]]
949 | then
950 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (STAGING)" $username $rootfolder
951 | else
952 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (SUBDOMAIN)" $username $rootfolder
953 | fi
954 | else
955 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain $username $rootfolder
956 | fi
957 |
958 | echo "$appname $finaldomain $username $rootfolder ${#finaldomain}" >> /var/tmp/primemover.domains.tmp
959 |
960 | else
961 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain "UNKNOWN!!!" "SITE ROOT FOLDER DAMAGED OR MISSING! ****SKIPPING****"
962 | fi
963 | fi
964 |
965 | }
966 |
967 | SingleGPDomain() {
968 |
969 | sourcedomain=$(awk '/server_name/,/;/' /etc/nginx/sites-available/$appname)
970 | sourcedomain=$(echo "${sourcedomain//;}") # Drop trailing semicolon
971 | finaldomain=$(echo $sourcedomain | awk '{ $1=""; print}')
972 | domaincount=$(echo $finaldomain | wc -w)
973 |
974 | if [ $domaincount == "1" ]
975 | then
976 | grid=work
977 | else
978 | #echo "This site has more than one domain! We're only able to process the first URL..."
979 | finaldomain=$(echo $finaldomain | awk '{print $1;}')
980 | fi
981 |
982 | rootfolder="/var/www/$appname/htdocs"
983 | username="www-data"
984 |
985 | if [ ${#finaldomain} -lt 3 ]
986 | then
987 |
988 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "NO DOMAIN!!!" "UNKNOWN" "$rootfolder ****SKIPPING****"
989 |
990 | else
991 | if [ -d $rootfolder ]
992 | then
993 |
994 | domaincount=$(echo $finaldomain | wc -w)
995 |
996 | if [ $domaincount == "1" ]
997 | then
998 | grid=work
999 | else
1000 | #echo "This site has more than one domain! We're only able to process the first URL..."
1001 | finaldomain=$(echo $finaldomain | awk '{print $1;}')
1002 | fi
1003 |
1004 | finaldomain=$(echo "$finaldomain" | sed "s/ //g")
1005 |
1006 | dots=$(echo "$finaldomain" | awk -F. '{ print NF - 1 }')
1007 |
1008 | if [ $dots -ge 2 ]
1009 | then
1010 | if [[ $finaldomain == "staging."* ]]
1011 | then
1012 | if [[ $restore == "yes" ]]
1013 | then
1014 | echo "Final domain for this site: $finaldomain"
1015 | else
1016 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (STAGING)" $username $rootfolder
1017 | fi
1018 | else
1019 | if [[ $restore == "yes" ]]
1020 | then
1021 | echo "Final domain for this site: $finaldomain"
1022 | else
1023 | printf '%-20s %-40s %-20s %-30s %-30s\n' $appname "$finaldomain (SUBDOMAIN)" $username $rootfolder
1024 | fi
1025 | fi
1026 | else
1027 | if [[ $restore == "yes" ]]
1028 | then
1029 | echo "Final domain for this site: $finaldomain"
1030 | else
1031 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain $username $rootfolder
1032 | fi
1033 | fi
1034 |
1035 | echo "$appname $finaldomain $username $rootfolder ${#finaldomain}" >> /var/tmp/primemover.domains.tmp
1036 |
1037 | else
1038 | printf '%-20s %-40s %-20s %-30s %-30s\n' "$appname" $finaldomain "UNKNOWN!!!" "SITE ROOT FOLDER DAMAGED OR MISSING! ****SKIPPING****"
1039 | fi
1040 | fi
1041 |
1042 | }
1043 |
1044 | gpDomains() {
1045 |
1046 | search_dir="/etc/nginx/sites-available"
1047 |
1048 | StartDomainLogging
1049 |
1050 | for entry in "$search_dir"/*
1051 | do
1052 | #echo "Entry is $entry..."
1053 | appname=$(basename $entry)
1054 | #echo "Application located: $appname..."
1055 | if [ $appname == "22222" ] || [ $appname == "default" ]
1056 | then
1057 | grid=work
1058 | else
1059 | SingleGPDomain
1060 | fi
1061 |
1062 | done
1063 |
1064 | echo "************************************************************************************************************************"
1065 | echo ""
1066 | echo ""
1067 | echo "PLEASE CONFIRM THIS LIST OF SITES LOOKS CORRECT... PRESS CTRL-Z to CANCEL if there is an error!!!"
1068 | echo ""
1069 | echo ""
1070 | read -t 10 -n 1 -s -r -p "Press any key to confirm or wait ten seconds..." ;
1071 | echo ""
1072 |
1073 |
1074 | sort -k5 -n /var/tmp/primemover.domains.tmp > /var/tmp/primemover.domains.tmp2
1075 |
1076 | }
1077 |
1078 | # Build required site(s) on remote GridPane server
1079 | # Currently works only with GridPane... cool your jets, I'm working on it.
1080 |
1081 | MakeSiteonRemote() {
1082 |
1083 | if [ "$y" = "1" ]
1084 | then
1085 | echo "An error was detected during a previous function, skipping the remote site build step for this site..."
1086 | return 1
1087 | fi
1088 |
1089 | if ssh -n root@$remote_IP [ -d /var/www/$site_to_clone/htdocs/wp-content/plugins/nginx-helper ]
1090 | then
1091 | echo ""
1092 | echo "****************************************************************************"
1093 | echo "***** SITE ALREADY EXISTINGS ON REMOTE - PROCEDING WILL BE DESTRUCTIVE *****"
1094 | echo "****************************************************************************"
1095 | echo ""
1096 | echo "You must press Y (Case Sensitive) to Proceed"
1097 | echo "Otherwise in ten seconds this site migration will be automatically halted..."
1098 | read -t 10 -n 1 -s -r -p "Press Y to continue, anything else will halt this migration!" < /dev/tty
1099 |
1100 | if [[ $REPLY =~ ^[Y]$ ]]
1101 | then
1102 | echo "Proceeding with potentially destructive migration!!!"
1103 | return 0
1104 | fi
1105 |
1106 | exit 187;
1107 |
1108 | fi
1109 |
1110 | if [ $envir == "GP" ]
1111 | then
1112 | echo "Checking for staging and canary sites..."
1113 | if [[ -d "/var/www/staging.$site_to_clone" && -d "/var/www/canary.$site_to_clone" ]]
1114 | then
1115 |
1116 | echo "Site $site_to_clone has staging and updates, building three remote sites on $remote_IP..."
1117 |
1118 | gpcurl=$(curl -d '{"server_ip":"'$remote_IP'", "source_ip":"'$remote_IP'", "url":"'$site_to_clone'", "checkedOptions":["wpfc","php7"], "checkedAdvancedOptions":["staging", "canary"]}' -H "Content-Type: application/json" -X POST https://my.gridpane.com/api/add-site?api_token=$gridpanetoken 2>&1)
1119 |
1120 |
1121 | elif [ -d "/var/www/staging.$site_to_clone" ]
1122 | then
1123 |
1124 | echo "Site $site_to_clone has a staging area, building two remote sites on $remote_IP..."
1125 |
1126 | gpcurl=$(curl -d '{"server_ip":"'$remote_IP'", "source_ip":"'$remote_IP'", "url":"'$site_to_clone'", "checkedOptions":["wpfc","php7"], "checkedAdvancedOptions":["staging"]}' -H "Content-Type: application/json" -X POST https://my.gridpane.com/api/add-site?api_token=$gridpanetoken 2>&1)
1127 |
1128 | elif [ -d "/var/www/canary.$site_to_clone" ]
1129 | then
1130 |
1131 | echo "Site $site_to_clone has automatic updates, building two remote sites on $remote_IP..."
1132 |
1133 | gpcurl=$(curl -d '{"server_ip":"'$remote_IP'", "source_ip":"'$remote_IP'", "url":"'$site_to_clone'", "checkedOptions":["wpfc","php7"], "checkedAdvancedOptions":["canary"]}' -H "Content-Type: application/json" -X POST https://my.gridpane.com/api/add-site?api_token=$gridpanetoken 2>&1)
1134 |
1135 | else
1136 |
1137 | echo "Site $site_to_clone has no staging or updates, building one remote site on $remote_IP..."
1138 |
1139 | gpcurl=$(curl -d '{"server_ip":"'$remote_IP'", "source_ip":"'$remote_IP'", "url":"'$site_to_clone'", "checkedOptions":["wpfc", "php7"]}' -H "Content-Type: application/json" -X POST https://my.gridpane.com/api/add-site?api_token=$gridpanetoken 2>&1)
1140 |
1141 | fi
1142 | else
1143 | echo "Building site $site_to_clone with staging and canary updates on remote GridPane server $remote_IP..."
1144 |
1145 | gpcurl=$(curl -d '{"server_ip":"'$remote_IP'", "source_ip":"'$remote_IP'", "url":"'$site_to_clone'", "checkedOptions":["wpfc","php7"], "checkedAdvancedOptions":["staging", "canary"]}' -H "Content-Type: application/json" -X POST https://my.gridpane.com/api/add-site?api_token=$gridpanetoken 2>&1)
1146 | fi
1147 |
1148 | echo "Waiting on remote server build..."
1149 | sleep 3
1150 |
1151 | }
1152 |
1153 | DBExport() {
1154 |
1155 | if [ "$y" = "1" ]
1156 | then
1157 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1158 | return 1
1159 | fi
1160 |
1161 | echo "Exporting Database..."
1162 | export=$(wp db export database.sql --allow-root 2>&1)
1163 |
1164 | if [[ $export == *"PHP Parse error"* ]]
1165 | then
1166 | echo "We have a config problem and WP-CLI can't run - attempting manual mysqldump..."
1167 | WPDBNAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4`
1168 | WPDBUSER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4`
1169 | WPDBPASS=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
1170 | mysqldump -u$WPDBUSER -p$WPDBPASS $WPDBNAME > database.sql
1171 |
1172 | else
1173 | echo "Automated DB export appear to throw any errors, double checking..."
1174 | fi
1175 |
1176 | if [ -f database.sql ]
1177 | then
1178 | echo "DB Exported successfully..."
1179 | else
1180 | echo "Database failed to export through either method... this site will fail!!!"
1181 | return 1
1182 | fi
1183 |
1184 | chmod 400 database.sql
1185 | }
1186 |
1187 | # Compress and package current site for secure copying
1188 |
1189 | PackageSite() {
1190 |
1191 | if [ "$y" = "1" ]
1192 | then
1193 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1194 | return 1
1195 | fi
1196 |
1197 | if [ $envir == "RC" ]
1198 | then
1199 | echo "Packaging local RunCloud powered site $appname for user $username..."
1200 |
1201 | cd /home/$username/webapps/$appname
1202 | echo "Arrived at directory... $PWD"
1203 |
1204 | DBExport
1205 |
1206 | if [ "$y" = "1" ]
1207 | then
1208 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1209 | return 1
1210 | fi
1211 |
1212 | #Need to get the DB prefix from wp-config...
1213 | tableprefix=$(sed -n -e '/$table_prefix/p' wp-config.php)
1214 | echo $tableprefix > table.prefix
1215 | chmod 400 table.prefix
1216 | echo "Database Table Prefix Exported..."
1217 |
1218 | cp wp-config.php wp-config.last.config
1219 | chmod 400 wp-config.last.config
1220 |
1221 | #tar -czf /home/$username/webapps/primemover-$appname-migration-file.gz . --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php'
1222 |
1223 | tar -cf - . -P --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php' | pv -s $(du -sb . | awk '{print $1}') | gzip > /home/$username/webapps/primemover-$appname-migration-file.gz
1224 |
1225 | echo "Cleaning up..."
1226 | rm database.sql
1227 | rm table.prefix
1228 | rm wp-config.last.config
1229 |
1230 | echo "Site $site_to_clone has been successfully packed up..."
1231 |
1232 | sitepack="/home/$username/webapps/primemover-$appname-migration-file.gz"
1233 |
1234 | elif [ $envir == "SP" ]
1235 | then
1236 | echo "Packaging local ServerPilot powered site $appname for user $D..."
1237 |
1238 | # Get to the choppa...
1239 | cd /srv/users/$username/apps/$appname/public
1240 | echo "Arrived at directory... $PWD"
1241 |
1242 | DBExport
1243 |
1244 | if [ "$y" = "1" ]
1245 | then
1246 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1247 | return 1
1248 | fi
1249 |
1250 | #Need to get the DB prefix from wp-config...
1251 | tableprefix=$(sed -n -e '/$table_prefix/p' wp-config.php)
1252 | echo $tableprefix > table.prefix
1253 | chmod 400 table.prefix
1254 | echo "Database Table Prefix Exported..."
1255 |
1256 | cp wp-config.php wp-config.last.config
1257 | chmod 400 wp-config.last.config
1258 |
1259 | #tar -czf /srv/users/$username/apps/$appname/primemover-$appname-migration-file.gz . --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php'
1260 |
1261 | tar -cf - . -P --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php' | pv -s $(du -sb . | awk '{print $1}') | gzip > /srv/users/$username/apps/$appname/primemover-$appname-migration-file.gz
1262 |
1263 | echo "Cleaning up..."
1264 | rm database.sql
1265 | rm table.prefix
1266 | rm wp-config.last.config
1267 |
1268 | echo "Site $appname has been successfully packed up..."
1269 |
1270 | sitepack="/srv/users/$username/apps/$appname/primemover-$appname-migration-file.gz"
1271 |
1272 | elif [ $envir == "CP" ]
1273 | then
1274 |
1275 | # HIGHLY EXPERIMENTAL!!!
1276 |
1277 | echo "Packaging local CPanel powered site $appname for user $D..."
1278 |
1279 | # Get to the choppa...
1280 | cd /home/$username/public_html/
1281 | echo "Arrived at directory... $PWD"
1282 |
1283 | echo "Exporting DB..."
1284 | DBExport
1285 |
1286 | if [ "$y" = "1" ]
1287 | then
1288 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1289 | return 1
1290 | fi
1291 |
1292 | #Need to get the DB prefix from wp-config...
1293 | tableprefix=$(sed -n -e '/$table_prefix/p' wp-config.php)
1294 | echo $tableprefix > table.prefix
1295 | chmod 400 table.prefix
1296 | echo "Database Table Prefix Exported..."
1297 |
1298 | cp wp-config.php wp-config.last.config
1299 | chmod 400 wp-config.last.config
1300 |
1301 | #tar -czf /home/$username/public_html/primemover-$appname-migration-file.gz . --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php'
1302 |
1303 | tar -cf - . -P --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php' | pv -s $(du -sb . | awk '{print $1}') | gzip > /home/$username/public_html/primemover-$appname-migration-file.gz
1304 |
1305 | echo "Exported site pack..."
1306 |
1307 | echo "Cleaning up..."
1308 | rm database.sql
1309 | rm table.prefix
1310 | rm wp-config.last.config
1311 |
1312 | echo "Site $appname has been successfully packed up..."
1313 |
1314 | sitepack="/home/$username/public_html/primemover-$appname-migration-file.gz"
1315 |
1316 | elif [ $envir == "GP" ] || [ $envir == "EE" ]
1317 | then
1318 | echo "Packaging local GridPane/EasyEngine compatible site $appname..."
1319 | cd /var/www/$appname/htdocs
1320 | echo "Arrived at directory... $PWD"
1321 |
1322 | DBExport
1323 |
1324 | if [ "$y" = "1" ]
1325 | then
1326 | echo "An error was detected during a previous function, skipping the site packaging step for this site..."
1327 | return 1
1328 | fi
1329 |
1330 | #Need to get the DB prefix from wp-config...
1331 | tableprefix=$(sed -n -e '/$table_prefix/p' ../wp-config.php)
1332 | echo $tableprefix > table.prefix
1333 | chmod 400 table.prefix
1334 | echo "Database Table Prefix Exported..."
1335 |
1336 | cp ../wp-config.php wp-config.last.config
1337 | chmod 400 wp-config.last.config
1338 |
1339 | #tar -czf /var/www/$appname/primemover-$appname-migration-file.gz . --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php'
1340 |
1341 | tar -cf - . -P --exclude '*.zip' --exclude '*.gz' --exclude 'wp-config.php' | pv -s $(du -sb . | awk '{print $1}') | gzip > /var/www/$appname/primemover-$appname-migration-file.gz
1342 |
1343 | echo "Cleaning up..."
1344 | rm database.sql
1345 | rm table.prefix
1346 | rm wp-config.last.config
1347 |
1348 | echo "Site $appname has been successfully packed up..."
1349 |
1350 | sitepack="/var/www/$appname/primemover-$appname-migration-file.gz"
1351 |
1352 | fi
1353 |
1354 | }
1355 |
1356 |
1357 | # All of this is only going to work moving things into a GridPane server...
1358 | # Again, I'm working on it.
1359 |
1360 | ShipOnly() {
1361 |
1362 | cd $rootfolder
1363 | if ! $(wp core is-installed --allow-root);
1364 | then
1365 |
1366 | echo "This is not a valid WordPress install, skipping!!!"
1367 |
1368 | else
1369 |
1370 | echo "Packing up site $site_to_clone..."
1371 |
1372 | PackageSite
1373 |
1374 | echo "Migrating site $site_to_clone..."
1375 |
1376 | DoMigrate
1377 |
1378 | fi
1379 |
1380 | echo "Shipped $site_to_clone..."
1381 |
1382 | }
1383 |
1384 | SingleSite() {
1385 |
1386 | cd $rootfolder
1387 | if ! $(wp core is-installed --allow-root);
1388 | then
1389 |
1390 | echo "This is not a valid WordPress install, skipping!!!"
1391 |
1392 | else
1393 |
1394 | MakeSiteonRemote
1395 | ShipOnly
1396 |
1397 | fi
1398 |
1399 | echo "Next site..."
1400 |
1401 | }
1402 |
1403 | CoreSiteLoop() {
1404 |
1405 | while read -r appname site_to_clone username rootfolder count
1406 | do
1407 |
1408 | echo "Building site $site_to_clone from $rootfolder on remote server $remote_IP..."
1409 |
1410 | dots=$(echo "$site_to_clone" | awk -F. '{ print NF - 1 }')
1411 |
1412 | if [[ $site_to_clone == "staging."* ]] && [[ $dots -ge 2 ]]
1413 | then
1414 | echo "This is a staging site..."
1415 | ShipOnly
1416 | elif [[ $site_to_clone == "canary."* ]] && [[ $dots -ge 2 ]]
1417 | then
1418 | echo "This is a UpdateSafely site, skipping..."
1419 | else
1420 | #echo "Doing $appname $site_to_clone $username $rootfolder..."
1421 | SingleSite
1422 | fi
1423 |
1424 | #echo "Getting next site..."
1425 |
1426 | done <"/var/tmp/primemover.domains.tmp2"
1427 |
1428 | echo "All sites processed!"
1429 |
1430 | }
1431 |
1432 | PushToRC() {
1433 |
1434 | echo "What is the IP address of your target RunCloud Server?"
1435 | read targetserver < /dev/tty
1436 |
1437 | echo "You'll need to have a root password for the remote RunCloud."
1438 |
1439 | echo "Getting ready to connect to target server..."
1440 |
1441 | sleep 1
1442 |
1443 | DoSSH "$targetserver"
1444 |
1445 | #example... 45.63.75.240
1446 |
1447 | echo "What is the remote path for this site on your target RunCloud Server?"
1448 | read RCRemotePath < /dev/tty
1449 |
1450 | RCappname=$(basename $RCRemotePath)
1451 |
1452 | RCusername=$(dirname $RCRemotePath)
1453 |
1454 | RCusername=$(dirname $RCusername)
1455 |
1456 | RCusername=$(basename $RCusername)
1457 |
1458 | #example... /home/runcloud/webapps/primemover-test
1459 |
1460 | echo "Packaging up site..."
1461 |
1462 | #TARBALL THE SITE
1463 |
1464 | PackageSite
1465 |
1466 | sleep 2
1467 |
1468 | echo "Copying to remote RunCloud Server..."
1469 |
1470 | scp /srv/users/$username/apps/$appname/primemover-$appname-migration-file.gz root@$remote_IP:/home/$RCusername/webapps/$RCappname/primemover-$RCappname-migration-file.gz
1471 |
1472 | sleep 1
1473 |
1474 | echo "Running remote restoration process..."
1475 |
1476 | if [[ $run == "1" ]]
1477 | then
1478 | ssh root@$remote_IP "sleep 3 && wget https://www.dropbox.com/s/1wpxv8kr9bfqz8i/primemover.sh && mv primemover.sh /usr/local/bin/primemover && chmod +x /usr/local/bin/primemover && sleep 1 && tar -xzf /home/$RCusername/webapps/$RCappname/primemover-$RCappname-migration-file.gz -C /home/$RCusername/webapps/$RCappname/ --overwrite && cd /home/$RCusername/webapps/$RCappname/ && echo $finaldomain > source.domain && primemover restore" < /dev/null
1479 | else
1480 | #ssh root@$remote_IP "sleep 3 && tar -xzf /home/$RCusername/webapps/$RCappname/primemover-$RCappname-migration-file.gz -C /home/$RCusername/webapps/$RCappname/ --overwrite && cd /home/$RCusername/webapps/$RCappname/ && primemover restore" < /dev/null
1481 | ssh root@$remote_IP "sleep 3 && wget https://www.dropbox.com/s/1wpxv8kr9bfqz8i/primemover.sh && mv primemover.sh /usr/local/bin/primemover && chmod +x /usr/local/bin/primemover && sleep 1 && tar -xzf /home/$RCusername/webapps/$RCappname/primemover-$RCappname-migration-file.gz -C /home/$RCusername/webapps/$RCappname/ --overwrite && cd /home/$RCusername/webapps/$RCappname/ && echo $finaldomain > source.domain && primemover restore" < /dev/null
1482 | fi
1483 |
1484 | sleep 1
1485 |
1486 | }
1487 |
1488 | # Secure Copy current packaged site to new server and restore
1489 | # All of this is only going to work moving things into a GridPane server...
1490 |
1491 | DoMigrate() {
1492 |
1493 | if [ "$y" = "1" ]
1494 | then
1495 | echo "An error was detected during a previous function, skipping the migration step for this site..."
1496 | return 1
1497 | fi
1498 |
1499 | echo "Waiting for remote site to completely provision..."
1500 |
1501 | while ssh -n root@$remote_IP [ ! -d /var/www/$site_to_clone/htdocs/wp-content/plugins/nginx-helper ]
1502 | do
1503 | sleep 5
1504 | done
1505 |
1506 | scp $sitepack root@$remote_IP:/var/www/$site_to_clone/GPBUP-$site_to_clone-CLONE.gz
1507 |
1508 | if [[ $y -gt 0 ]]
1509 | then
1510 | echo "The secure copy to the remote server failed for site $site_to_clone! Exiting..."
1511 | return 1
1512 | else
1513 | echo "Successfully copied site pack for $site_to_clone to remote system $remote_IP"
1514 | rm $sitepack
1515 | fi
1516 |
1517 | ssh -n root@$remote_IP "sleep 1 && cd /var/www/$site_to_clone/htdocs && gprestore" < /dev/null
1518 |
1519 | echo "Site $site_to_clone restored on remote system $remote_IP"
1520 |
1521 | echo "Cleaning up..."
1522 |
1523 | sleep 1
1524 |
1525 | }
1526 |
1527 | SPtoRC() {
1528 |
1529 | # The intention here is to move sites from a ServerPilot node to a RunCloud node...
1530 |
1531 | SourceID=$(serverpilot find servers lastaddress=$ipaddress id)
1532 |
1533 | serverpilot find apps serverid=$SourceID > /var/tmp/primemover/source-applications.txt
1534 |
1535 | GetSPApps
1536 |
1537 | echo ""
1538 | echo "To begin initializing ALL apps press ENTER... NOTE: Destination sites must already be built inside of RunCloud!!!"
1539 |
1540 | read desiredapps
1541 |
1542 | if [ -z "$desiredapps" ]
1543 | then
1544 |
1545 | sed '1d' /var/tmp/primemover/source-applications.txt > /var/tmp/primemover/tmpfile; mv /var/tmp/primemover/tmpfile /var/tmp/primemover/source-applications.txt
1546 | echo "Copying ServerPilot Sites..."
1547 | run=0
1548 | while IFS=" " read -r word1 word2 word3 word4 word5 word6
1549 | do
1550 |
1551 | GetSPUserAppDetails
1552 |
1553 | cd /srv/users/$currentuser/apps/$appname/public
1554 |
1555 | if ! $(wp core is-installed --allow-root);
1556 | then
1557 |
1558 | echo "This is not a valid WordPress install, skipping this app!"
1559 |
1560 | else
1561 |
1562 | ((run++))
1563 |
1564 | echo "Proceeding..."
1565 |
1566 | SingleSPDomain
1567 |
1568 | echo "The Final Domain for this application is $finaldomain"
1569 |
1570 | appdomain=$finaldomain
1571 |
1572 | PushToRC
1573 |
1574 | fi
1575 |
1576 | done < "/var/tmp/primemover/source-applications.txt"
1577 |
1578 | fi
1579 |
1580 | }
1581 |
1582 | SimpleSimon() {
1583 |
1584 | echo "###########################################################"
1585 | echo "###### Let's migrate all your sites, shall we? ########"
1586 | echo "###### We need to get some basic information... ########"
1587 | echo "###########################################################"
1588 | echo ""
1589 | echo "Please choose from one of the following options..."
1590 | echo ""
1591 |
1592 | if [[ $envir == "SP" ]]
1593 | then
1594 | echo "1.) Migrate sites all local sites to a GridPane Server"
1595 | echo ""
1596 | echo "2.) Migrate sites all local sites to a RunCloud Server"
1597 | echo ""
1598 | echo "3.) Migrate sites all local sites to another ServerPilot Server"
1599 | echo ""
1600 | elif [[ $envir == "RC" ]]
1601 | then
1602 | echo "A.) Migrate sites all local sites to GridPane Server"
1603 | echo ""
1604 | echo "B.) Migrate sites all local sites to a ServerPilot Server"
1605 | echo ""
1606 | echo "C.) Migrate sites all local sites to another RunCloud Server"
1607 | echo ""
1608 | elif [[ $envir == "GP" ]]
1609 | then
1610 | echo "X.) Migrate sites all local sites to another GridPane Server"
1611 | echo ""
1612 | elif [[ $envir == "EE" ]]
1613 | then
1614 | echo "Y.) Migrate sites all local sites to a GridPane Server"
1615 | echo ""
1616 | elif [[ $envir == "CP" ]]
1617 | then
1618 | echo "Z.) Migrate sites all local sites to a GridPane Server"
1619 | echo ""
1620 | else
1621 | echo "We don't currently support your control panel or you have a non-standard installation."
1622 | echo "Sorry, EXITING!"
1623 | exit 187;
1624 | fi
1625 |
1626 | read MigrateInput < /dev/tty
1627 |
1628 | if [[ $MigrateInput == "1" ]]
1629 | then
1630 | MigrateType=SP2GP
1631 | elif [[ $MigrateInput == "2" ]]
1632 | then
1633 | MigrateType=SP2RC
1634 | elif [[ $MigrateInput == "3" ]]
1635 | then
1636 | MigrateType=SP2SP
1637 | elif [[ $MigrateInput == "A" ]] || [[ $MigrateInput == "a" ]]
1638 | then
1639 | MigrateType=RC2GP
1640 | elif [[ $MigrateInput == "B" ]] || [[ $MigrateInput == "b" ]]
1641 | then
1642 | MigrateType=RC2SP
1643 | elif [[ $MigrateInput == "C" ]] || [[ $MigrateInput == "c" ]]
1644 | then
1645 | MigrateType=RC2RC
1646 | elif [[ $MigrateInput == "X" ]] || [[ $MigrateInput == "x" ]]
1647 | then
1648 | MigrateType=GP2GP
1649 | elif [[ $MigrateInput == "Y" ]] || [[ $MigrateInput == "y" ]]
1650 | then
1651 | MigrateType=EE2CP
1652 | elif [[ $MigrateInput == "Z" ]] || [[ $MigrateInput == "z" ]]
1653 | then
1654 | MigrateType=CP2GP
1655 | else
1656 | echo "You entered something weird - exiting!"
1657 | exit 187;
1658 | fi
1659 |
1660 | CheckMode
1661 |
1662 | }
1663 |
1664 | WhatPlatform() {
1665 |
1666 | if [ -d /opt/gridpane ]
1667 | then
1668 | echo "This is a GridPane provisioned server..."
1669 | envir="GP"
1670 | #gpDomains
1671 | elif [ -d "/etc/nginx-sp" ]
1672 | then
1673 | echo "This is a ServerPilot managed VPS..."
1674 | envir="SP"
1675 | #spDomains
1676 | elif [ -d "/etc/nginx-rc/" ]
1677 | then
1678 | echo "This is a RunCloud managed VPS..."
1679 | envir="RC"
1680 | #rcDomains
1681 | elif [ -f "/usr/local/cpanel/cpanel" ]
1682 | then
1683 | echo "This is a CPanel managed VPS..."
1684 | echo "CPANEL MIGRATIONS ARE HIGHLY EXPERIMENTAL!!!"
1685 | ECHO " YOU'VE BEEN WARNED, HOMESLICE"
1686 | envir="CP"
1687 | #cpDomains
1688 | elif [ -f "/usr/local/bin/ee" ]
1689 | then
1690 | echo "This is a EasyEngine install... "
1691 | envir="EE"
1692 | #gpDomains
1693 | else
1694 | echo "We don't yet have support for Plesk/CPanel or similar shared hosting environments."
1695 | echo "Sorry. Deuces."
1696 | exit 187;
1697 | fi
1698 |
1699 | }
1700 |
1701 | LoopLocalSites() {
1702 |
1703 | if [ $envir == "GP" ]
1704 | then
1705 | echo ""
1706 | echo "Processing local GridPane Sites..."
1707 | CoreSiteLoop
1708 |
1709 | elif [ $envir == "EE" ]
1710 | then
1711 | echo ""
1712 | echo "Processing local EasyEngine Sites..."
1713 | CoreSiteLoop
1714 |
1715 | elif [ $envir == "CP" ]
1716 | then
1717 | echo ""
1718 | echo "Processing local CPanel Sites... even though we probably shouldn't."
1719 | CoreSiteLoop
1720 |
1721 | elif [ $envir == "SP" ]
1722 | then
1723 | echo ""
1724 | echo "Processing local ServerPilot Sites..."
1725 | CoreSiteLoop
1726 |
1727 | elif [ $envir == "RC" ]
1728 | then
1729 | echo ""
1730 | echo "Processing local RunCloud Sites..."
1731 | CoreSiteLoop
1732 | fi
1733 |
1734 | }
1735 |
1736 | SPtoGP() {
1737 |
1738 | spDomains
1739 |
1740 | $site_to_clone="ALL"
1741 |
1742 | DoWork
1743 |
1744 | }
1745 |
1746 | RCtoGP() {
1747 |
1748 | rcDomains
1749 |
1750 | $site_to_clone="ALL"
1751 |
1752 | DoWork
1753 |
1754 | }
1755 |
1756 | GetWPAdmin() {
1757 |
1758 | echo "Before we proceed we need to collect default WP admin details for the new sites we'll be creating."
1759 | echo ""
1760 | echo "If your migrations succeed these account details will obviously be wiped out."
1761 | echo ""
1762 | echo "Your current existing account credentials will overwrite these temporary details."
1763 | echo ""
1764 | echo "These are primarily for testing purposes in the event that a site build fails."
1765 | echo ""
1766 | echo "Please enter default admin username..."
1767 | echo ""
1768 | read admin_user < /dev/tty
1769 | echo "Please enter default admin email..."
1770 | echo ""
1771 | read admin_email < /dev/tty
1772 | echo "Please enter default admin password..."
1773 | echo ""
1774 | read admin_password < /dev/tty
1775 |
1776 | }
1777 |
1778 | ImportDB() {
1779 |
1780 | if [ -f database.sql ]
1781 | then
1782 | wp db import database.sql --allow-root
1783 | elif [ -f database.gz ]
1784 | then
1785 | tar -xzf database.gz
1786 | wp db import database.sql --allow-root
1787 | else
1788 | echo "Error! Database backup file missing!"
1789 | exit 187;
1790 | fi
1791 |
1792 | echo "Database Imported... We Think"
1793 |
1794 | if [ -f database.sql ]
1795 | then
1796 | rm database.sql
1797 | elif [ -f database.gz ]
1798 | then
1799 | rm database.gz
1800 | else
1801 | echo "No DB file to remove!"
1802 | fi
1803 |
1804 | rm table.prefix
1805 |
1806 | }
1807 |
1808 | UpdateURL() {
1809 |
1810 | if [[ $envir == "RC" ]]
1811 | then
1812 | sourceURL=$(awk '{print $1; exit}' /home/$username/webapps/$appname/source.domain)
1813 |
1814 | cd /home/$username/webapps/$appname/
1815 |
1816 | echo "Replacing the source domain $sourceURL with the destination domain of $finaldomain"
1817 |
1818 | PATH=/RunCloud/Packages/php70rc/bin:/RunCloud/Packages/httpd-rc/bin:$PATH
1819 |
1820 | echo "Current path is... $PATH"
1821 |
1822 | URLResult=$(/usr/local/bin/wp search-replace ''$sourceURL'' ''$finaldomain'' --allow-root)
1823 |
1824 | echo "Result of search/replace is $URLResult"
1825 |
1826 | rm /home/$username/webapps/$appname/source.domain
1827 |
1828 | elif [[ $envir == "SP" ]]
1829 | then
1830 | sourceURL=$(awk '{print $1; exit}' /srv/users/$username/apps/$appname/public/source.domain)
1831 |
1832 | cd /srv/users/$username/apps/$appname/public
1833 |
1834 | echo "Replacing the source domain $sourceURL with the destination domain of $finaldomain"
1835 |
1836 | PATH=/RunCloud/Packages/php70rc/bin:/RunCloud/Packages/httpd-rc/bin:$PATH
1837 |
1838 | echo "Current path is... $PATH"
1839 |
1840 | URLResult=$(/usr/local/bin/wp search-replace ''$sourceURL'' ''$finaldomain'' --allow-root)
1841 |
1842 | echo "Result of search/replace is $URLResult"
1843 |
1844 | rm /srv/users/$username/apps/$appname/public/source.domain
1845 |
1846 | elif [[ $envir == "GP" ]]
1847 | then
1848 | sourceURL=$(awk '{print $1; exit}' /var/www/$appname/htdocs/source.domain)
1849 |
1850 | cd /var/www/$appname/htdocs/
1851 |
1852 | echo "Replacing the source domain $sourceURL with the destination domain of $finaldomain"
1853 |
1854 | PATH=/RunCloud/Packages/php70rc/bin:/RunCloud/Packages/httpd-rc/bin:$PATH
1855 |
1856 | echo "Current path is... $PATH"
1857 |
1858 | URLResult=$(/usr/local/bin/wp search-replace ''$sourceURL'' ''$finaldomain'' --allow-root)
1859 |
1860 | echo "Result of search/replace is $URLResult"
1861 |
1862 | rm /var/www/$appname/htdocs/source.domain
1863 |
1864 | else
1865 | echo "We don't know how to update URLs for this control panel...???"
1866 | echo "Sorry, EXITING!!!"
1867 | exit 187;
1868 | fi
1869 |
1870 |
1871 | }
1872 |
1873 | DoWork() {
1874 |
1875 | # Do Work Son...
1876 |
1877 | #WhatPlatform # Now we where we're coming from and we SHOULD know all the domains as well...
1878 |
1879 | if [ "$site_to_clone" == "ALL" ] || [ "$site_to_clone" == "all" ]
1880 | then
1881 | echo ""
1882 | echo "Determining this server's control environment..."
1883 | LoopLocalSites
1884 |
1885 | else
1886 | thedomain=$1 # The domain in question...
1887 | domaindetails=$(sed -n "/$thedomain/p" /var/tmp/primemover.domains.tmp2 | head -1) # Find the first instance of that domain name (avoid staging etc)...
1888 |
1889 | echo $domaindetails | while read -r appname site_to_clone username rootfolder count
1890 | do
1891 | if [ $envir == "GP" ]
1892 | then
1893 | echo ""
1894 | echo "Processing single GridPane Site..."
1895 | SingleSite
1896 |
1897 | elif [ $envir == "EE" ]
1898 | then
1899 | echo ""
1900 | echo "Processing single EasyEngine Site..."
1901 | SingleSite
1902 |
1903 | elif [ $envir == "CP" ]
1904 | then
1905 | echo ""
1906 | echo "Processing single CPanel Site..."
1907 | SingleSite
1908 |
1909 | elif [ $envir == "SP" ]
1910 | then
1911 | echo ""
1912 | echo "Processing single ServerPilot Site..."
1913 | SingleSite
1914 |
1915 | elif [ $envir == "RC" ]
1916 | then
1917 | echo ""
1918 | echo "Processing single RunCloud Site..."
1919 | SingleSite
1920 | fi
1921 |
1922 | done
1923 |
1924 | fi
1925 |
1926 | }
1927 |
1928 | CheckMode() {
1929 |
1930 | if [[ $MigrateType == "restore" ]]
1931 | then
1932 |
1933 | DoRestore
1934 |
1935 | elif [[ $MigrateType == "SP2RC" ]] || [[ $MigrateType == "sp2rc" ]]
1936 | then
1937 |
1938 | echo "Migrating from a ServerPilot Server to a RunCloud Server..."
1939 | envir=SP
1940 | SPtoRC
1941 |
1942 | elif [[ $MigrateType == "SP2SP" ]] || [[ $MigrateType == "sp2sp" ]]
1943 | then
1944 |
1945 | echo "Migrating from a ServerPilot Server to another ServerPilot Server..."
1946 |
1947 | envir=SP
1948 | GetWPAdmin
1949 | ServerPilotShell
1950 | SPtoSP
1951 |
1952 | elif [[ $MigrateType == "RC2RC" ]] || [[ $MigrateType == "rc2rc" ]]
1953 | then
1954 |
1955 | echo "Migrating from a RunCloud server to another RunCloud Server..."
1956 | envir=RC
1957 | RCtoRC
1958 |
1959 | elif [[ $MigrateType == "RC2SP" ]] || [[ $MigrateType == "rc2sp" ]]
1960 | then
1961 |
1962 | echo "Migrating from a RunCloud Server to a ServerPilot Server..."
1963 | envir=RC
1964 | GetWPAdmin
1965 | RCtoSP
1966 |
1967 | elif [[ $MigrateType == "RC2GP" ]] || [[ $MigrateType == "rc2gp" ]]
1968 | then
1969 |
1970 | echo "Migrating from a RunCloud Server to a GridPane Server..."
1971 | envir=RC
1972 | RCtoGP
1973 |
1974 | elif [[ $MigrateType == "SP2GP" ]] || [[ $MigrateType == "sp2gp" ]]
1975 | then
1976 |
1977 | echo "Migrating from a ServerPilot Server to a GridPane Server..."
1978 | envir=SP
1979 | GetWPAdmin
1980 | ServerPilotShell
1981 | SPtoGP
1982 |
1983 | else
1984 |
1985 | echo "No command line input..."
1986 | #echo "I guess I could ask a bunch of Simple Simon Questions..."
1987 |
1988 | WhatPlatform
1989 |
1990 | SimpleSimon
1991 |
1992 | fi
1993 |
1994 | }
1995 |
1996 | DoRestore() {
1997 |
1998 | currdir=$PWD
1999 | appname=$(basename $currdir)
2000 |
2001 | if [[ $appname == "public" ]]
2002 | then
2003 |
2004 | echo "This looks like a ServerPilot server..."
2005 |
2006 | envir=SP
2007 |
2008 | tableprefix=$(cat table.prefix)
2009 | sed -i "/$table_prefix =/c\\$tableprefix" wp-config.php
2010 | echo "Prefixes Fixed"
2011 |
2012 | ImportDB
2013 |
2014 | cd ..
2015 | currdir=$PWD
2016 | appname=$(basename $currdir)
2017 | cd ../..
2018 | username=$PWD
2019 | username=$(basename $username)
2020 |
2021 | SingleSPDomain
2022 |
2023 | UpdateURL
2024 |
2025 | chown -R $username:$username /srv/users/$username/apps/$appname/public/*
2026 |
2027 | elif [[ $appname == "htdocs" ]]
2028 | then
2029 |
2030 | echo "This looks like a GridPane server..."
2031 |
2032 | envir=GP
2033 |
2034 | tableprefix=$(cat table.prefix)
2035 | sed -i "/$table_prefix =/c\\$tableprefix" ../wp-config.php
2036 | echo "Prefixes Fixed"
2037 |
2038 | ImportDB
2039 |
2040 | cd ..
2041 | currdir=$PWD
2042 | appname=$(basename $currdir)
2043 | #GridPane is currently single user...
2044 | username=www-data
2045 |
2046 | SingleGPDomain
2047 |
2048 | UpdateURL
2049 |
2050 | chown -R $username:$username /var/www/$appname/htdocs/*
2051 |
2052 | else
2053 |
2054 | echo "This looks like a RunCloud server..."
2055 |
2056 | envir=RC
2057 |
2058 | tableprefix=$(cat table.prefix)
2059 | sed -i "/$table_prefix =/c\\$tableprefix" wp-config.php
2060 | echo "Prefixes Fixed"
2061 |
2062 | ImportDB
2063 |
2064 | cd ../..
2065 | username=$PWD
2066 | username=$(basename $username)
2067 |
2068 | SingleRCDomain
2069 |
2070 | UpdateURL
2071 |
2072 | chown -R $username:$username /home/$username/webapps/$appname/*
2073 |
2074 | fi
2075 |
2076 | }
2077 |
2078 | CheckMode
2079 | # Copyright 2018 PrimeMover.io - K. Patrick Gallagher
2080 |
--------------------------------------------------------------------------------