-
Notifications
You must be signed in to change notification settings - Fork 0
/
zwp_migrate.sh
2304 lines (1981 loc) · 62.2 KB
/
zwp_migrate.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Migrate WordPress installations via SSH.
# URL: https://github.com/zevilz/zwp-migrate
# Author: Alexandr "zEvilz" Emshanov
# License: MIT
# Version: 1.3.0
# shellcheck disable=SC2046
# shellcheck disable=SC2089
# shellcheck disable=SC2086
# shellcheck disable=SC2090
# shellcheck disable=SC2016
# shellcheck disable=SC2181
#pushToLog()
#{
# if [[ $# -eq 2 ]]; then
# echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $1: $2" >> $SCRIPT_LOGS_DIR/main.log
# if [ -f "$SCRIPT_ERRORS_TMP" ]; then
# cat "$SCRIPT_ERRORS_TMP" >> $SCRIPT_LOGS_DIR/main.log
# rm "$SCRIPT_ERRORS_TMP"
# fi
# else
# $SETCOLOR_FAILURE
# echo "Internal error handling error! Exiting..."
# $SETCOLOR_NORMAL
# exit 1
# fi
#}
checkHostFormat()
{
if [[ "$1" =~ ^localhost(:[0-9]+)?$ ]] || [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(:[0-9]+)?$ ]] || [[ $(echo "$1" | grep -P "(?=^.{4,253}$)(^(?:[a-z0-9](?:(?:[a-z0-9\-]){0,61}[a-z0-9])?\.)+[a-z0-9\-]{2,}(:[0-9]+)?$)") == "$1" ]]; then
echo 1
else
echo 0
fi
}
checkUserFormat()
{
if [[ "$1" =~ ^[A-Za-z0-9_\.][A-Za-z0-9_\.\-]*$ ]]; then
echo 1
else
echo 0
fi
}
checkFullPathFormat()
{
if [[ "$1" =~ ^/ ]]; then
echo 1
else
echo 0
fi
}
checkUrlFormat()
{
if [[ "$1" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(:[0-9]+)?$ ]] || [[ $(echo "$1" | grep -P "(?=^.{4,253}$)(^https?://(?:[a-z0-9](?:(?:[a-z0-9\-]){0,61}[a-z0-9])?\.)+[a-z0-9\-]{2,}$)") == "$1" ]]; then
echo 1
else
echo 0
fi
}
checkDBNameFormat()
{
echo 1
}
checkDBUserFormat()
{
echo 1
}
cleanup()
{
if [ -n "$1" ]; then
echo "$1"
fi
if [ -z "$1" ]; then
echo -n " removing the script temporary files..."
fi
# source tmp errors file
if [ -z "$SOURCE_HOST" ]; then
rm -f "$SOURCE_SCRIPT_ERRORS_TMP" > /dev/null 2>/dev/null
elif [ "$FAIL_REMOTE" -eq 0 ]; then
$SETSID ssh "${SOURCE_USER}"@"${SOURCE_HOST}" -p "${SOURCE_PORT}" "rm -f \"$SOURCE_SCRIPT_ERRORS_TMP\" > /dev/null 2>/dev/null" > /dev/null 2>/dev/null
else
echo -n
fi
SOURCE_RESULT="$?"
# target tmp errors file
if [ -z "$TARGET_HOST" ]; then
rm -f "$TARGET_SCRIPT_ERRORS_TMP" > /dev/null 2>/dev/null
elif [ "$FAIL_REMOTE" -eq 0 ]; then
$SETSID ssh "${TARGET_USER}"@"${TARGET_HOST}" -p "${TARGET_PORT}" "rm -f \"$TARGET_SCRIPT_ERRORS_TMP\" > /dev/null 2>/dev/null" > /dev/null 2>/dev/null
else
echo -n
fi
TARGET_RESULT="$?"
# rsync exclude list file
rm -f "$RSYNC_EXCLUDE_LIST_FILE" > /dev/null 2>/dev/null
RSYNC_EXCLUDE_RESULT="$?"
# result
if [ -z "$1" ]; then
if [ "$SOURCE_RESULT" -eq 0 ] && [ "$TARGET_RESULT" -eq 0 ] && [ "$RSYNC_EXCLUDE_RESULT" -eq 0 ]; then
$SETCOLOR_SUCCESS
echo "[OK]"
$SETCOLOR_NORMAL
else
$SETCOLOR_FAILURE
echo "[FAIL]"
$SETCOLOR_NORMAL
fi
fi
# ssh session file
if [[ -n "$SOURCE_HOST" && "$SOURCE_AUTH_TYPE" == "pass" ]] || [[ -n "$TARGET_HOST" && "$TARGET_AUTH_TYPE" == "pass" ]]; then
if [ -z "$1" ]; then
echo -n " removing files for ssh session..."
fi
rm -f "$SCRIPT_SSH_PASS_TMP" > /dev/null 2>/dev/null
RESULT="$?"
if [ -z "$1" ]; then
if [ "$RESULT" -eq 0 ]; then
$SETCOLOR_SUCCESS
echo "[OK]"
$SETCOLOR_NORMAL
else
$SETCOLOR_FAILURE
echo "[FAIL]"
$SETCOLOR_NORMAL
fi
fi
fi
echo
}
usage()
{
echo
echo "Usage: bash $0 [options]"
echo
echo "Simple tool for right migrate WordPress sites between servers and shared hostings "
echo "with SSH access via rsync and WP-CLI"
echo
echo "Parameters:"
echo
echo " -h, --help Shows this help."
echo
echo " -v, --version Shows script version."
echo
echo " -q, --quiet Automatically confirm migration after checks."
echo " --non-interactive Enable non-interactive mode."
echo
echo " --source-host=<host>:<port> Source host IP/hostname with ssh port (if it not 22) "
echo " separated by colon (don't set it if you run script "
echo " on this host)."
echo
echo " --source-user=<username> System user on source host (source site owner)."
echo
echo " --source-user-pass='<pass>' System user password on source host (password "
echo " of source site owner; don't set it if you run "
echo " script as this user)."
echo
echo " --source-path=<path> Full path to source site root."
echo
echo " --target-host=<host>:<port> Target host IP/hostname with ssh port (if it not 22) "
echo " separated by colon (don't set it if you run script "
echo " on this host)."
echo
echo " --target-user=<username> System user on target host (target site owner)."
echo
echo " --target-user-pass='<pass>' System user password on target host (password "
echo " of target site owner; don't set it if you run "
echo " script as this user)."
echo
echo " --target-path=<path> Full path to target site root."
echo
echo " --target-site-url=<url> Full url of target site with protocol (http/https)."
echo
echo " --target-db-host=<host>:<port> Target site database host with port (if it not "
echo " default 3306) separated by colon (don't set it if "
echo " db server is localhost with default 3306 port)."
echo
echo " --target-db-name=<database> Target site database name."
echo
echo " --target-db-user=<user> Target site database user with full access rights "
echo " to target site database."
echo
echo " --target-db-pass=<pass> Target site database user password."
echo
echo " --target-wpcli-path=<path> Custom WP-CLI path."
echo
echo " --target-php-path=<path> Path to custom PHP binary for running WP-CLI."
echo
echo " --files-exclude=<patterns> File patterns to exclude from files sync separated "
echo " by spaces (pattern `wp-content/cache` already included "
echo " to this list)."
echo
}
# Vars
# script vars
SCRIPT_INSTANCE_KEY=$(tr -cd 'a-zA-Z0-9' < /dev/urandom | head -c 10)
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
SETCOLOR_GREY="echo -en \\033[0;2m"
BOLD_TEXT=$(tput bold)
NORMAL_TEXT=$(tput sgr0)
INTERACTIVE=1
NO_ASK=0
HELP=0
SHOW_VERSION=0
#SCRIPT_LOGS_DIR="/var/log/zwp_migrate"
# errors
ERRORS_CHECK=0
ERRORS_MIGRATE=0
FAIL_BOTH_REMOTE=0
FAIL_USER=0
FAIL_WP=0
FAIL_SOURCE_DB=0
FAIL_REMOTE=0
FAIL_TMP_PATH=0
# source host
SOURCE_HOST=
SOURCE_PORT=22
SOURCE_AUTH_TYPE="key"
SOURCE_USER=
SOURCE_USER_PASS=
SOURCE_PATH=
SOURCE_SITE_URL=
SOURCE_DB_HOST=
SOURCE_DB_PORT=3306
SOURCE_DB_NAME=
SOURCE_DB_USER=
SOURCE_DB_PASS=
SOURCE_TMP_PATH=
SOURCE_SCRIPT_ERRORS_TMP=
# target host
TARGET_HOST=
TARGET_PORT=22
TARGET_AUTH_TYPE="key"
TARGET_USER=
TARGET_USER_PASS=
TARGET_PATH=
TARGET_SITE_URL=
TARGET_DB_HOST=
TARGET_DB_PORT=3306
TARGET_DB_NAME=
TARGET_DB_USER=
TARGET_DB_PASS=
TARGET_TMP_PATH=
TARGET_SCRIPT_ERRORS_TMP=
TARGET_WPCLI_PATH=
TARGET_PHP_PATH=
# migration vars
RSYNC_SOURCE_HOST=
RSYNC_TARGET_HOST=
RSYNC_PORT=
RSYNC_CHOWN=
RSYNC_EXCLUDE_LIST='wp-content/cache'
RSYNC_EXCLUDE_LIST_FILE="${TMPDIR-/tmp}/zwp_migrate.tmp.rsync_exclude.${SCRIPT_INSTANCE_KEY}"
CMD_SOURCE_DB_PASS=
CMD_TARGET_DB_PASS=
#SYNC=0
#SYNC_EXCLUDE=
# ssh pass access
SETSID=
SCRIPT_SSH_PASS_TMP="${TMPDIR-/tmp}/zwp_migrate.tmp.sshpass.${SCRIPT_INSTANCE_KEY}"
# wp-cli
WPCLI=
WPCLI_DOWNLOADED=0
# php
PHP=
# Parse options
while true ; do
if [[ "$1" = "--non-interactive" ]] ; then
INTERACTIVE=0
elif [[ "$1" = "--quiet" || "$1" = "-q" ]] ; then
NO_ASK=1
elif [[ "$1" = "--help" || "$1" = "-h" ]] ; then
HELP=1
elif [[ "$1" = "--version" || "$1" = "-v" ]] ; then
SHOW_VERSION=1
elif [ "${1#--source-host=}" != "$1" ] ; then
SOURCE_HOST="${1#--source-host=}"
elif [ "${1#--source-user=}" != "$1" ] ; then
SOURCE_USER="${1#--source-user=}"
elif [ "${1#--source-user-pass=}" != "$1" ] ; then
SOURCE_USER_PASS="${1#--source-user-pass=}"
SOURCE_AUTH_TYPE="pass"
elif [ "${1#--source-path=}" != "$1" ] ; then
SOURCE_PATH="${1#--source-path=}"
elif [ "${1#--target-host=}" != "$1" ] ; then
TARGET_HOST="${1#--target-host=}"
elif [ "${1#--target-user=}" != "$1" ] ; then
TARGET_USER="${1#--target-user=}"
elif [ "${1#--target-user-pass=}" != "$1" ] ; then
TARGET_USER_PASS="${1#--target-user-pass=}"
TARGET_AUTH_TYPE="pass"
elif [ "${1#--target-path=}" != "$1" ] ; then
TARGET_PATH="${1#--target-path=}"
elif [ "${1#--target-site-url=}" != "$1" ] ; then
TARGET_SITE_URL="${1#--target-site-url=}"
TARGET_SITE_URL=$(echo "$TARGET_SITE_URL" | sed 's/\/$//')
elif [ "${1#--target-db-host=}" != "$1" ] ; then
TARGET_DB_HOST="${1#--target-db-host=}"
elif [ "${1#--target-db-name=}" != "$1" ] ; then
TARGET_DB_NAME="${1#--target-db-name=}"
elif [ "${1#--target-db-user=}" != "$1" ] ; then
TARGET_DB_USER="${1#--target-db-user=}"
elif [ "${1#--target-db-pass=}" != "$1" ] ; then
TARGET_DB_PASS="${1#--target-db-pass=}"
elif [ "${1#--files-exclude=}" != "$1" ] ; then
RSYNC_EXCLUDE_LIST="${RSYNC_EXCLUDE_LIST} ${1#--files-exclude=}"
elif [ "${1#--target-wpcli-path=}" != "$1" ] ; then
TARGET_WPCLI_PATH="${1#--target-wpcli-path=}"
elif [ "${1#--target-php-path=}" != "$1" ] ; then
TARGET_PHP_PATH="${1#--target-php-path=}"
elif [ -z "$1" ] ; then
break
else
echo
$SETCOLOR_FAILURE
echo "Unknown key detected!" 1>&2
$SETCOLOR_NORMAL
usage
exit 1
fi
shift
done
# Show help
if [ "$HELP" -eq 1 ]; then
usage
exit 0
fi
# Show version
if [ $SHOW_VERSION -eq 1 ]; then
CUR_VERSION=$(grep 'Version:\ ' $0 | cut -d ' ' -f3)
echo $CUR_VERSION
exit 0
fi
if [ $INTERACTIVE -eq 1 ]; then
# source host
echo "${BOLD_TEXT}# Source host${NORMAL_TEXT}"
while true; do
echo
echo "IP or hostname of source server (localhost by default)."
echo "Set port after colon if you use custom ssh port (ex.: \"123.123.123.123:2222\")"
echo
echo -n "Type source server IP or hostname (empty value for localhost) > "
read -r SOURCE_HOST
if [ -n "$SOURCE_HOST" ]; then
if [ $(checkHostFormat "$SOURCE_HOST") -eq 1 ]; then
break
else
$SETCOLOR_FAILURE
echo "Wrong server IP or hostname format!"
$SETCOLOR_NORMAL
fi
else
break
fi
done
echo
# source user
echo "${BOLD_TEXT}# Source username${NORMAL_TEXT}"
while true; do
echo
echo "System username on source server."
echo
echo -n "Type username of source server > "
read -r SOURCE_USER
if [ -z "$SOURCE_USER" ]; then
$SETCOLOR_FAILURE
echo "Username is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkUserFormat "$SOURCE_USER") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong username format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
if [ -n "$SOURCE_HOST" ]; then
# remote source auth type
echo "${BOLD_TEXT}# Remote source auth type${NORMAL_TEXT}"
while true; do
echo
echo "Select \"SSH key\" if auth to remote host via SSH key."
echo "Select \"password\" if auth to remote host only by password "
echo "or you don't know about SSH keys."
echo
echo "1. SSH key"
echo "2. password"
echo
echo -n "Choose SSH auth type [1] > "
read -r SOURCE_AUTH_TYPE_KEY
case "$SOURCE_AUTH_TYPE_KEY" in
1) echo -n
SOURCE_AUTH_TYPE="key"
break
;;
2) echo -n
SOURCE_AUTH_TYPE="pass"
break
;;
"") echo -n
SOURCE_AUTH_TYPE="key"
break
;;
*) echo
$SETCOLOR_FAILURE
echo "Type correct value!"
$SETCOLOR_NORMAL
;;
esac
done
echo
if [[ "$SOURCE_AUTH_TYPE" == "pass" ]]; then
# source user password
echo "${BOLD_TEXT}# Source user password${NORMAL_TEXT}"
while true; do
echo
echo -n "Type password for remote user (password not visible) > "
read -r -s SOURCE_USER_PASS
if [ -z "$SOURCE_USER_PASS" ]; then
echo
$SETCOLOR_FAILURE
echo "User pass is empty!"
$SETCOLOR_NORMAL
else
break
fi
done
echo
echo
fi
fi
# source path
echo "${BOLD_TEXT}# Source path${NORMAL_TEXT}"
while true; do
echo
echo "WordPress installation full path."
echo
echo -n "Type WordPress installation path on source server > "
read -r SOURCE_PATH
if [ -z "$SOURCE_PATH" ]; then
$SETCOLOR_FAILURE
echo "Path is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkFullPathFormat "$SOURCE_PATH") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong path format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
if [[ -z "$SOURCE_HOST" ]]; then
# target host
echo "${BOLD_TEXT}# Target host${NORMAL_TEXT}"
while true; do
echo
echo "IP or hostname of target server (localhost by default)."
echo "Set port after colon if you use custom ssh port (ex.: \"123.123.123.123:2222\")"
echo
echo -n "Type target server IP or hostname (empty value for localhost) > "
read -r TARGET_HOST
if [ -n "$TARGET_HOST" ]; then
if [ $(checkHostFormat "$TARGET_HOST") -eq 1 ]; then
break
else
$SETCOLOR_FAILURE
echo "Wrong server IP or hostname format!"
$SETCOLOR_NORMAL
fi
else
break
fi
done
echo
fi
# target user
echo "${BOLD_TEXT}# Target username${NORMAL_TEXT}"
while true; do
echo
echo "System username on target server."
echo
echo -n "Type username of target server > "
read -r TARGET_USER
if [ -z "$TARGET_USER" ]; then
$SETCOLOR_FAILURE
echo "Username is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkUserFormat "$TARGET_USER") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong username format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
if [ -n "$TARGET_HOST" ]; then
# remote target auth type
echo "${BOLD_TEXT}# Remote target auth type${NORMAL_TEXT}"
while true; do
echo
echo "Select \"SSH key\" if auth to remote host via SSH key."
echo "Select \"password\" if auth to remote host only by password "
echo "or you don't know about SSH keys."
echo
echo "1. SSH key"
echo "2. password"
echo
echo -n "Choose SSH auth type [1] > "
read -r TARGET_AUTH_TYPE_KEY
case "$TARGET_AUTH_TYPE_KEY" in
1) echo -n
TARGET_AUTH_TYPE="key"
break
;;
2) echo -n
TARGET_AUTH_TYPE="pass"
break
;;
"") echo -n
TARGET_AUTH_TYPE="key"
break
;;
*) echo
$SETCOLOR_FAILURE
echo "Type correct value!"
$SETCOLOR_NORMAL
;;
esac
done
echo
if [[ "$TARGET_AUTH_TYPE" == "pass" ]]; then
# target user password
echo "${BOLD_TEXT}# Target user password${NORMAL_TEXT}"
while true; do
echo
echo -n "Type password for remote user (password not visible) > "
read -r -s TARGET_USER_PASS
if [ -z "$TARGET_USER_PASS" ]; then
echo
$SETCOLOR_FAILURE
echo "User pass is empty!"
$SETCOLOR_NORMAL
else
break
fi
done
echo
echo
fi
fi
# target path
echo "${BOLD_TEXT}# Target path${NORMAL_TEXT}"
while true; do
echo
echo "WordPress installation full path."
echo
echo -n "Type WordPress installation path on target server > "
read -r TARGET_PATH
if [ -z "$TARGET_PATH" ]; then
$SETCOLOR_FAILURE
echo "Path is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkFullPathFormat "$TARGET_PATH") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong path format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
# target wp url
echo "${BOLD_TEXT}# Target WordPress URL${NORMAL_TEXT}"
while true; do
echo
echo "WordPress full URL (with protocol)."
echo
echo -n "Type WordPress URL from target server > "
read -r TARGET_SITE_URL
if [ -z "$TARGET_SITE_URL" ]; then
$SETCOLOR_FAILURE
echo "URL is empty!"
$SETCOLOR_NORMAL
else
TARGET_SITE_URL=$(echo "$TARGET_SITE_URL" | sed 's/\/$//')
if [ $(checkUrlFormat "$TARGET_SITE_URL") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong url format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
# target db host
echo "${BOLD_TEXT}# Target DB host${NORMAL_TEXT}"
while true; do
echo
echo "WordPress database host on target server (localhost with default 3306 port by default)."
echo "Set port after colon if you use custom port (ex.: \"123.123.123.123:2222\")"
echo
echo -n "Type DB host (empty value for localhost) > "
read -r TARGET_DB_HOST
if [ -n "$TARGET_DB_HOST" ]; then
if [ $(checkHostFormat "$TARGET_DB_HOST") -eq 1 ]; then
break
else
$SETCOLOR_FAILURE
echo "Wrong DB host format!"
$SETCOLOR_NORMAL
fi
else
TARGET_DB_HOST="localhost"
break
fi
done
echo
# target db name
echo "${BOLD_TEXT}# Target DB name${NORMAL_TEXT}"
while true; do
echo
echo "WordPress database name on target server."
echo
echo -n "Type DB name > "
read -r TARGET_DB_NAME
if [ -z "$TARGET_DB_NAME" ]; then
$SETCOLOR_FAILURE
echo "DB name is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkDBNameFormat "$TARGET_DB_NAME") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong DB name format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
# target db user
echo "${BOLD_TEXT}# Target DB user${NORMAL_TEXT}"
while true; do
echo
echo "WordPress database user on target server."
echo
echo -n "Type DB user > "
read -r TARGET_DB_USER
if [ -z "$TARGET_DB_USER" ]; then
$SETCOLOR_FAILURE
echo "DB user is empty!"
$SETCOLOR_NORMAL
else
if [ $(checkDBUserFormat "$TARGET_DB_USER") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong DB user format!"
$SETCOLOR_NORMAL
else
break
fi
fi
done
echo
# target db user pass
echo "${BOLD_TEXT}# Target DB user pass${NORMAL_TEXT}"
while true; do
echo
echo "WordPress database user pass on target server."
echo
echo -n "Type DB user pass (password not visible) > "
read -r -s TARGET_DB_PASS
if [ -z "$TARGET_DB_PASS" ]; then
echo
$SETCOLOR_FAILURE
echo "Target DB pass is empty!"
$SETCOLOR_NORMAL
else
break
fi
done
echo
echo
else
echo
echo -n "Checking input data..."
if [ -n "$SOURCE_HOST" ] && [ $(checkHostFormat "$SOURCE_HOST") -eq 0 ]; then
$SETCOLOR_FAILURE
echo "Wrong source server IP or hostname format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -z "$SOURCE_USER" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Source username not set!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
elif [ $(checkUserFormat "$SOURCE_USER") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Wrong source username format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -n "$SOURCE_HOST" ] && [[ "$SOURCE_AUTH_TYPE" == "pass" ]] && [ -z "$SOURCE_USER_PASS" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Source user password is empty!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -z "$SOURCE_PATH" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Source path not set!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
elif [ $(checkFullPathFormat "$SOURCE_PATH") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Wrong source path format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -n "$TARGET_HOST" ] && [ $(checkHostFormat "$TARGET_HOST") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Wrong target server IP or hostname format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -z "$TARGET_USER" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Target username not set!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
elif [ $(checkUserFormat "$TARGET_USER") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Wrong target username format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -n "$TARGET_HOST" ] && [[ "$TARGET_AUTH_TYPE" == "pass" ]] && [ -z "$TARGET_USER_PASS" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Target user password is empty!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
if [ -z "$TARGET_PATH" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Target path not set!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
elif [ $(checkFullPathFormat "$TARGET_PATH") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Wrong target path format!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
fi
TARGET_SITE_URL=$(echo "$TARGET_SITE_URL" | sed 's/\/$//')
if [ -z "$TARGET_SITE_URL" ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo
fi
$SETCOLOR_FAILURE
echo " Target WP URL not set!" 1>&2
$SETCOLOR_NORMAL
ERRORS_CHECK=1
elif [ $(checkUrlFormat "$TARGET_SITE_URL") -eq 0 ]; then
if [ "$ERRORS_CHECK" -eq 0 ]; then
echo