-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstcms
More file actions
executable file
·2261 lines (2170 loc) · 80.4 KB
/
instcms
File metadata and controls
executable file
·2261 lines (2170 loc) · 80.4 KB
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
#!/bin/bash
# -------------------------------------------------------
# CMS-Installer: Installs choice CMS on a cPanel server
# CMS-Installer Version: 2.4
# URL: http://cms-installer.ml
# Github: https://github.com/InterGenStudios/CMS-Installer
# ---------------------------------------------------
# InterGenStudios: 5-16-15
# Copyright (c) 2015: Christopher 'InterGen' Cork InterGenStudios
# URL: https://intergenstudios.com
# --------------------------------
# License: GPL-2.0+
# URL: http://opensource.org/licenses/gpl-license.php
# ---------------------------------------------------
# CMS-Installer is free software:
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software
# Foundation, either version 2 of the License, or (at your discretion)
# any later version.
# ------------------
#-------------#
# To Do List: #
#-------------#
# 1) Start cPanel plugin gui development
# 2) Identify and integrate additional CMSs
# 3) Everything else
#--------------------------------#
# BEGIN - VARIABLE DOCUMENTATION #
#--------------------------------#
# NEW VARIABLE CHANGES AS OF VERSION 2.4 - NEEDS TO BE UPDATED FOR VERSION 2.4+ (6-3-15)
# 1 - Initially used to hold arguments for flow control in core script, then during checks throughout
# 2 - Initially used to hold arguments for flow control in core script, then during checks throughout
# 3 - Initially used to hold arguments for flow control in core script, then during checks throughout
# API_PASS - Holds root password - used in RPASS_VALIDATE (), PURGE_DATABASE (), PURGE_DATABASE_USER (), INSTALL_DB ()
# API_USER - Placeholder for 'root' (may be redundant) - used in RPASS_VALIDATE (), PURGE_DATABASE (), PURGE_DATABASE_USER (), INSTALL_DB ()
# BACKUP - Holds choice for using backup option, used in BACKUP_OPTION ()
# CMS - Holds full name of target CMS - used in CONFIRM_INSTALL (), CONVERT_CMS_TARGET (), FIRST_FUNCTION ()
# CMS_CHOICE - Holds number ID of target CMS choice for installation - used in CMS_SELECT_2 (), CMS_SELECT ()
# CMS_DB - Flag set during database installation, to trigger purge routines if needed - used in initial variable declarations, PURGE_DATABASE (), PURGE_DATABASE_USER (), INSTALL_DB ()
# CMS_DBU - Flag set during database installation, to trigger purge routines if needed - used in initial variable declarations, PURGE_DATABASE (), PURGE_DATABASE_USER (), INSTALL_DB ()
# CMS_FILES - Flag set during database installation, to trigger purge routines if needed - used in initial variable declarations, PURGE_INSTALL_FILES (), INSTALL_WP (), INSTALL_JM (), INSTALL_DR ()
# CMS_TARGET - Holds target CMS argument/choice flag, used in LIST_ACCTS (), CONFIRM_INSTALL (), CMS_SELECT_2 (), CMS_SELECT (), CONVERT_CMS_TARGET (), FIRST_FUNCTION (), and in core script
# DB_NAME - Holds name of database created with API calls, Used in PURGE_DATABASE (), INSTALL_DB (), INSTALL_WP (), INSTALL_JM (), INSTALL_DR ()
# DB_PREFIX - Sets account name as prefix for database{user}, used in INSTALL_DB ()
# DBU_NAME - Holds database username, used in PURGE_DATABASE_USER (), INSTALL_DB (), INSTALL_WP (), INSTALL_JM (), INSTALL_DR ()
# DBU_PASS - Holds database user password, used in INSTALL_DB (), INSTALL_WP (), INSTALL_JM (), INSTALL_DR ()
# DIR - Used in checking for pre-existing data in target docroot, used in CHECK_EXISTING_DATA ()
# DOMAIN_CHOICE - Holds selection of target domain, used in LIST_ACCTS ()
# EXISTS - Holds name of identified pre-existing CMS installation, used in BACKUP_OPTION (), EXISTING_INSTALL_WARN (), CHECK_EXISTING_INSTALL ()
# expire - Holds paste URL life-span in minutes, used in INSTALL_JM (), INSTALL_DR ()
# FILE - Empty variable used in existing data check, used in CHECK_EXISTING_DATA ()
# FIRST_CHOICE - Holds intial selection of flow control, used in FIRST_FUNCTION ()
# HTACCESS_WARN - Holds flag for an identified htaccess file in maindomain during subdomain installation, used in SUBDOMAIN_HT_CHECK (), HT_CHECK_WARN ()
# name - Holds name of paste URL creator, used in INSTALL_JM (), INSTALL_DR ()
# NC - Holds regex variable for integers, used in initial variable declarations, LIST_ACCTS ()
# OPTION1 - Holds installation confirmation choice, used in CONFIRM_INSTALL ()
# RETRY - Holds re-enter root pass choice , used in RPASS_VALIDATE ()
# SERVER - Holds server IP, used in initial variable declarations, PURGE_DATABASE (), PURGE_DATABASE_USER (), RPASS_VALIDATE (), INSTALL_DB ()
# SUBDOMAIN - Target docroot path-type identifier, used in SUBDOMAIN_HT_CHECK (), INSTALL_{WP,JM,DR,OC,MX} (), TARGET_CHECK ()
# TARGET - Holds name of target Domain/Subdomain, used in
# TARGET_ACCT - Holds target cPanel account name, used in
# TARGET_PATH - Holds target web docroot, used in
# TARGET_TYPE -
# vers - Holds CMS-Installer version number, used in initial variable declarations, HELPTEXT (), HEADER (), VERSION ()
# WP_CV - Holds current WordPress release #, used in GET_CMS_VERS (), HELPTEXT (), INSTALL_WP (), CMS_SELECT_2 (), CMS_SELECT ()
# JM_CV - Holds current Joomla release #, used in GET_CMS_VERS (), HELPTEXT (), INSTALL_JM (), CMS_SELECT_2 (), CMS_SELECT ()
# DR_CV - Holds current Drupal release #, used in GET_CMS_VERS (), HELPTEXT (), INSTALL_DR (), CMS_SELECT_2 (), CMS_SELECT ()
# OC_CV - Holds current ocPortal release #, used in GET_CMS_VERS (), HELPTEXT (), INSTALL_OC (), CMS_SELECT_2 (), CMS_SELECT ()
# MX_CV - Holds current ModXRevolution release #, used in GET_CMS_VERS (), HELPTEXT (), INSTALL_MX (), CMS_SELECT_2 (), CMS_SELECT ()
#------------------------------#
# END - VARIABLE DOCUMENTATION #
#------------------------------#
###########################################
##---------------------------------------##
## BEGIN - INITIAL VARIABLE DECLARATIONS ##
##---------------------------------------##
###########################################
# Regex check for numbers as choices
NC='^[0-9]+$'
# Set server IP for script
SERVER="$(/sbin/ifconfig | grep -A 1 0: | tail -1 | awk '{print $2}' | sed 's/addr://')"
# Flag for purge functions
CMS_FILES=0
# Flag for purge functions
CMS_DB=0
# Flag for purge functions
CMS_DBU=0
# CMS-Installer version
vers=2.4
# Initial root password validation flag
RPASS_VALIDATED=0
# Initial cms version flag
CMS_VERS_FLAG=0
# Initial root access hash flag
HASH=NO
# Sets a timestamp for LOGGING
TIMESTAMP="$(date +"%m-%d-%Y_%T")"
#########################################
##-------------------------------------##
## END - INITIAL VARIABLE DECLARATIONS ##
##-------------------------------------##
#########################################
##############################
##--------------------------##
## BEGIN - SCRIPT FUNCTIONS ##
##--------------------------##
##############################
#----------------------------------#
# BEGIN - DISPLAY LAYOUT FUNCTIONS #
#----------------------------------#
# Colors trailing text Red
RED () {
tput bold
tput setaf 1
}
# Colors trailing text Green
GREEN () {
tput bold
tput setaf 2
}
# Colors trailing text Yellow
YELLOW () {
tput bold
tput setaf 3
}
# Colors trailing text Blue
BLUE () {
tput bold
tput setaf 4
}
# Clears any preceding text color declarations
WHITE () {
tput sgr0
}
# Simple divider
SEPARATOR () {
echo
BLUE
echo "============================================================================"
echo
WHITE
}
# Creates uniform look during script execution when called after any clear command
HEADER () {
echo
GREEN
echo "============================================================================"
WHITE
echo " CMS-INSTALLER v$vers"
GREEN
echo "============================================================================"
WHITE
printf "\n\n"
}
# Clears $ amount of lines when called
CLEARLINE () {
# To use, set CLINES=<$#> before function if you need to clear more than 1 line
if [ -z "$CLINES" ]; then
tput cuu 1 && tput el
else
tput cuu "$CLINES" && tput el
unset CLINES
fi
}
#--------------------------------#
# END - DISPLAY LAYOUT FUNCTIONS #
#--------------------------------#
#-----------------------------------------------#
# BEGIN - CMS & DATABASE INSTALLATION FUNCTIONS #
#-----------------------------------------------#
# Uses DLev's API call engineering to properly create MySQL database and user that cPanel can 'see'
INSTALL_DB () {
clear
HEADER
GREEN
echo Creating CMS Database and DatabaseUser via WHM API...
echo
sleep 2
DB_PREFIX="$(echo "$TARGET_ACCT" | cut -c1-8)"
DB_NAME="$DB_PREFIX"_cmsi"$(date +%s | sha256sum | base64 | head -c 8)" &&
if [ "$(echo "$(mysql -e "show databases;" | awk '{print $1}' | grep -m 1 "$DB_NAME")")" = "$DB_NAME" ]; then
DB_NAME="$DB_NAME"1
fi
DBU_NAME="$DB_PREFIX"_"$(date +%s | sha256sum | base64 | head -c 6)" &&
if [ "$(echo "$(mysql -e "select user from mysql.user;" | awk '{print $1}' | grep -m 1 "$DBU_NAME")")" = "$DBU_NAME" ]; then
DBU_NAME="$DBU_NAME"1
fi
DBU_PASS="$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 16 | head -1)"
WHITE
# API call to create the database, and command to set purge flag
curl -sk -X GET -u root:"$API_PASS" "https://$SERVER:2087/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_user=$TARGET_ACCT&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=createdb&db=$DB_NAME" > dbvalidation && CMS_DB=1
# API call to create the database user and password, command to dump output into a file for error checking, and command to set purge flag
curl -sk -X GET -u root:"$API_PASS" "https://$SERVER:2087/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_user=$TARGET_ACCT&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=createdbuser&dbuser=$DBU_NAME&password=$DBU_PASS" > dbuvalidation && CMS_DBU=1
# API call to associate database user to database in cPanel database cache and map, command to dump output to a file for error checking, and command to set purge flag
curl -sk -X GET -u root:"$API_PASS" "https://$SERVER:2087/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_user=$TARGET_ACCT&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=setdbuserprivileges&db=$DB_NAME&dbuser=$DBU_NAME&privileges=ALL%20PRIVILEGES" > dbivalidation
# Check for errors in database creation
if [ -n "$(grep "error" dbvalidation)" ]; then
RED
echo
echo "dbvalidation error reported"
echo
cat dbvalidation
sleep 1
INSTALL_DB_ERROR
# Check for errors in database user creation
elif [ -n "$(grep "error" dbuvalidation)" ]; then
RED
echo
echo "dbuvalidation error reported"
echo
cat dbuvalidation
sleep 1
INSTALL_DB_ERROR
# Check for errors in user-database association
elif [ -n "$(grep "error" dbivalidation)" ]; then
RED
echo
echo "dbivalidation error reported"
echo
cat dbivalidation
sleep 1
INSTALL_DB_ERROR
else
clear
HEADER
GREEN
echo "ALL WHM API calls completed successfully."
sleep 1
fi
# Remove database/user creation error-checking logs
rm -rf ./*validation
}
# Installs the WordPress CMS, and provides URL for customer to finalize the installation
INSTALL_WP () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching WordPress files..."
echo
wget -q https://wordpress.org/latest.tar.gz && CMS_FILES=1
echo "Moving WordPress files into place..."
sleep 2
tar xf latest.tar.gz &&
mv "$TARGET_PATH"wordpress/* "$TARGET_PATH"
INSTALL_DB
cp wp-config-sample.php wp-config.php
# Load up key and salt variables - added head and tail functions to force variation
IT1=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 9 | tail -1)
IT2=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 8 | tail -1)
IT3=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 7 | tail -1)
IT4=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 6 | tail -1)
IT5=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 5 | tail -1)
IT6=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 4 | tail -1)
IT7=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 3 | tail -1)
IT8=$(tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' < /dev/urandom | fold -w 64 | head -n 2 | tail -1)
sed -i -e "s/database_name_here/$DB_NAME/" -e "s/username_here/$DBU_NAME/" -e "s/password_here/$DBU_PASS/" -e "45 s/put your unique phrase here/$IT1/" -e "46 s/put your unique phrase here/$IT2/" -e "47 s/put your unique phrase here/$IT3/" -e "48 s/put your unique phrase here/$IT4/" -e "49 s/put your unique phrase here/$IT5/" -e "50 s/put your unique phrase here/$IT6/" -e "51 s/put your unique phrase here/$IT7/" -e "52 s/put your unique phrase here/$IT8/" wp-config.php
sed -i -e "s/put your unique phrase here//g" wp-config.php
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
/usr/local/cpanel/scripts/restartsrv_httpd
clear
HEADER
GREEN
printf "WordPress Version %s" "$WP_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the following URL to your customer"
echo
echo "so they can finalize their installation:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"
printf "\n\n\n"
rm -rf wordpress/ latest.tar.gz
SET_CMSLOG
}
# Installs the Joomla CMS, and provides both domain URL and database info URL for customer to finalize the installation
INSTALL_JM () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
if [[ "$(php -v | awk '{print $2}' | grep 5)" < "5.3.1" ]]; then
clear
HEADER
RED
echo
echo "WARNING!"
echo
WHITE
echo "Joomla requires PHP Version 5.3.1 or higher."
echo
echo "Please check the additional requirements here"
echo "prior to running the installer again: https://docs.joomla.org/J3.x:Installing_Joomla"
echo
echo "Installation cannot continue."
echo
echo "Exiting..."
sleep 3
exit 1
fi
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching Joomla files..."
echo
wget -q https://github.com/joomla/joomla-cms/releases/download/"$JM_CV"/Joomla_"$JM_CV"-Stable-Full_Package.zip && CMS_FILES=1
echo "Moving Joomla files into place..."
unzip -q Joomla_"$JM_CV"-Stable-Full_Package.zip &&
rm -rf Joomla_"$JM_CV"-Stable-Full_Package.zip
INSTALL_DB
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
/usr/local/cpanel/scripts/restartsrv_httpd
## Fetching pastefile template for database information presentation to customer
wget -q https://raw.githubusercontent.com/InterGenStudios/CMS-Installer/master/jdbinfo
# Adds database info into template
sed -i -e "s/DOMAIN/$TARGET/" -e "s/JM_CV/$JM_CV/" -e "s/TARGET/$TARGET/" -e "s/DBU/$DBU_NAME/" -e "s/PASS/$DBU_PASS/" -e "s/DB/$DB_NAME/" jdbinfo
# Creates paste for database info using 'stikked'
curl -d name=JoomlaInstaller -d expire=120 -d private=1 --data-urlencode text@jdbinfo -s http://nobits.ml/api/create > tempaste
# converts 'stikked' paste to raw output URL
sed -i -e 's/view/view\/raw/' tempaste
clear
HEADER
GREEN
printf "The %s" "$CMS"
printf " CMS Version %s" "$JM_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the Database Info URL to your customer"
GREEN
echo "(needed for finalizing installation)"
echo
printf "==> "
WHITE
printf "%s" "$(cat tempaste)"
printf "\n\n"
printf "Provide the following %s" "$CMS"
printf " URL to your customer"
printf "\n"
echo "and advise them to finalize their installation:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"
printf "\n\n\n"
# Remove PASTE URL tempfiles
rm -rf jdbinfo tempaste
SET_CMSLOG
}
# Installs the Drupal CMS, and provides both domain URL and database info URL for customer to finalize the installation
INSTALL_DR () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching Drupal files..."
echo
wget -q http://ftp.drupal.org/files/projects/drupal-"$DR_CV".tar.gz && CMS_FILES=1
echo "Moving Drupal files into place..."
tar xf drupal-"$DR_CV".tar.gz &&
mv drupal-"$DR_CV"/* . && mv drupal-"$DR_CV"/.h* . && mv drupal-"$DR_CV"/.g* .
INSTALL_DB
cp sites/default/default.settings.php sites/default/settings.php
mkdir -p sites/default/files && chmod 755 sites/default/files
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
chown -R "$TARGET_ACCT":"$TARGET_ACCT" ./*
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
/usr/local/cpanel/scripts/restartsrv_httpd
## Fetching pastefile template for database information presentation to customer
wget -q https://raw.githubusercontent.com/InterGenStudios/CMS-Installer/master/ddbinfo
# Adds database info into template
sed -i -e "s/DOMAIN/$TARGET/" -e "s/DR_CV/$DR_CV/" -e "s/TARGET/$TARGET/" -e "s/DBU/$DBU_NAME/" -e "s/PASS/$DBU_PASS/" -e "s/DB/$DB_NAME/" ddbinfo
# Creates paste for database info using 'stikked'
curl -d name=DrupalInstaller -d expire=120 -d private=1 --data-urlencode text@ddbinfo -s http://nobits.ml/api/create > tempaste
# converts 'stikked' paste to raw output URL
sed -i -e 's/view/view\/raw/' tempaste
clear
HEADER
GREEN
printf "The %s" "$CMS"
printf " CMS Version %s" "$DR_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the Database Info URL to your customer"
GREEN
echo "(needed for finalizing installation)"
echo
printf "==> "
WHITE
printf "%s" "$(cat tempaste)"
printf "\n\n"
printf "Provide the following %s" "$CMS"
printf " URL to your customer"
printf "\n"
echo "and advise them to finalize their installation:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"
printf "\n\n\n"
# Remove PASTE URL tempfiles
rm -rf drupal-"$DR_CV"/ drupal-"$DR_CV".tar.gz ddbinfo tempaste
SET_CMSLOG
}
# Installs the ocPortal CMS, and provides both domain URL and database info URL for customer to finalize the installation
INSTALL_OC () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching ocPortal files..."
echo
wget -q http://ocportal.com/site/dload.php?id=1037 && CMS_FILES=1
echo "Moving ocPortal files into place..."
mv dload.php\?id\=1037 ocportal.zip
unzip -q ocportal.zip &&
rm -rf ocportal.zip
INSTALL_DB
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
/usr/local/cpanel/scripts/restartsrv_httpd
## Fetching pastefile template for database information presentation to customer
wget -q https://raw.githubusercontent.com/InterGenStudios/CMS-Installer/master/ocdbinfo
# Adds database info into template
sed -i -e "s/DOMAIN/$TARGET/" -e "s/OC_CV/$OC_CV/" -e "s/TARGET/$TARGET/" -e "s/DBU/$DBU_NAME/" -e "s/PASS/$DBU_PASS/" -e "s/DB/$DB_NAME/" ocdbinfo
# Creates paste for database info using 'stikked'
curl -d name=ocPortalInstaller -d expire=120 -d private=1 --data-urlencode text@ocdbinfo -s http://nobits.ml/api/create > tempaste
# converts 'stikked' paste to raw output URL
sed -i -e 's/view/view\/raw/' tempaste
clear
HEADER
GREEN
printf "The %s" "$CMS"
printf " CMS Version %s" "$OC_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the Database Info URL to your customer"
GREEN
echo "(needed for finalizing installation)"
echo
printf "==> "
WHITE
printf "%s" "$(cat tempaste)"
printf "\n\n"
printf "Provide the following %s" "$CMS"
printf " URL to your customer"
printf "\n"
echo "and advise them to finalize their installation:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"
printf "/install.php"
printf "\n\n\n"
# Remove PASTE URL tempfiles
rm -rf ocdbinfo tempaste
SET_CMSLOG
}
# Installs the ModXRevolution CMS, and provides both Admin Login Info URL and Admin Login URL for customer
INSTALL_MX () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching ModXRevolution files..."
echo
wget -q http://modx.com/download/direct/modx-"$MX_CV"-pl.zip && CMS_FILES=1
echo "Moving ModXRevolution files into place..."
unzip -q modx-"$MX_CV"-pl.zip
mv mv modx-"$MX_CV"-pl/* . &&
rm -rf modx-"$MX_CV"-pl.zip
cp setup/config.dist.new.xml setup/config.xml
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$TARGET_PATH"*
INSTALL_DB
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
MODX_ADMIN="$DB_PREFIX"-admin
MODX_PASS="$(date +%s | sha256sum | base64 | head -c 10)"
MODX_CORE="$TARGET_PATH"core/
MODX_MANAGER="$TARGET_PATH"manager/
MODX_CONNECTORS="$TARGET_PATH"connectors/
# Yes, this is ONE sed command
sed -i -e "s|<database>modx_modx</database>|<database>$DB_NAME</database>|" -e "s|<database_user>db_username</database_user>|<database_user>$DBU_NAME</database_user>|" -e "s|<database_password>db_password</database_password>|<database_password>$DBU_PASS</database_password>|" -e "s|<cmsadmin>username</cmsadmin>|<cmsadmin>$MODX_ADMIN</cmsadmin>|" -e "s|<cmspassword>password</cmspassword>|<cmspassword>$MODX_PASS</cmspassword>|" -e "s|email@address.com|admin@$TARGET|" -e "s|<core_path>/www/modx/core/</core_path>|<core_path>$MODX_CORE</core_path>|" -e "s|<context_mgr_path>/www/modx/manager/</context_mgr_path>|<context_mgr_path>$MODX_MANAGER</context_mgr_path>|" -e "s|<context_mgr_url>/modx/manager/</context_mgr_url>|<context_mgr_url>/manager/</context_mgr_url>|" -e "s|<context_connectors_path>/www/modx/connectors/</context_connectors_path>|<context_connectors_path>$MODX_CONNECTORS</context_connectors_path>|" -e "s|<context_connectors_url>/modx/connectors/</context_connectors_url>|<context_connectors_url>/connectors/</context_connectors_url>|" -e "s|<context_web_path>/www/modx/</context_web_path>|<context_web_path>$TARGET_PATH</context_web_path>|" -e "s|<context_web_url>/modx/</context_web_url>|<context_web_url>/</context_web_url>|" "$TARGET_PATH"setup/config.xml
clear
HEADER
GREEN
echo "Running ModXRevolution Installer..."
sleep 1
echo "(this may take a minute...or two..)"
echo
cd "$TARGET_PATH"
cd setup
php index.php --installmode=new
cd "$TARGET_PATH"
## Fetching pastefile template for database information presentation to customer
wget -q https://raw.githubusercontent.com/InterGenStudios/CMS-Installer/master/mxdbinfo
# Adds database info into template
sed -i -e "s/DOMAIN/$TARGET/" -e "s/MX_CV/$MX_CV/" -e "s/TARGET/$TARGET/g" -e "s/ADMIN_NAME/$MODX_ADMIN/" -e "s/ADMIN_PASS/$MODX_PASS/" mxdbinfo
# Creates paste for database info using 'stikked'
curl -d name=ModXRevoInstaller -d expire=120 -d private=1 --data-urlencode text@mxdbinfo -s http://nobits.ml/api/create > tempaste
# converts 'stikked' paste to raw output URL
sed -i -e 's/view/view\/raw/' tempaste
clear
HEADER
GREEN
printf "The %s" "$CMS"
printf " CMS Version %s" "$MX_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the Admin Login URL to your customer"
GREEN
echo
printf "==> "
WHITE
printf "%s" "$(cat tempaste)"
printf "\n\n"
printf "Provide the following %s" "$CMS"
printf " URL to your customer"
printf "\n"
echo "and advise them to change the admin email on login:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"
printf "/manager"
printf "\n\n\n"
# Remove PASTE URL tempfiles
rm -rf mxdbinfo tempaste
SET_CMSLOG
}
# Installs the ownCloud Personal Cloud Storage Management System, and provides both domain URL and database info URL for customer to finalize the installation
INSTALL_OWN () {
CHECK_EXISTING_INSTALL
CHECK_EXISTING_DATA
SUBDOMAIN_HT_CHECK
cd "$TARGET_PATH"
clear
HEADER
GREEN
echo "Fetching ownCloud files..."
echo
wget -q https://download.owncloud.com/download/community/setup-owncloud.php && CMS_FILES=1
echo "Moving ownCloud files into place..."
chown "$TARGET_ACCT":"$TARGET_ACCT" "$TARGET_PATH"setup-owncloud.php
INSTALL_DB
# Begin fixperms style corrections- making sure all files are owned properly, with correct permissions
chown -R "$TARGET_ACCT":"$TARGET_ACCT" ./*
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
find /home/"$TARGET_ACCT"/public_html -type d -exec chmod 755 {} \;
find /home/"$TARGET_ACCT"/public_html -type f | xargs -d$'\n' -r chmod 644
find /home/"$TARGET_ACCT"/public_html -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" /home/"$TARGET_ACCT"/public_html/*
find /home/"$TARGET_ACCT"/* -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
else
for SUBDOMAIN in $(grep -i document /var/cpanel/userdata/"$TARGET_ACCT"/* | awk '{print $2}' | grep home | grep -v public_html)
do
find "$SUBDOMAIN" -type d -exec chmod 755 {} \;
find "$SUBDOMAIN" -type f | xargs -d$'\n' -r chmod 644
find "$SUBDOMAIN" -name '*.cgi' -o -name '*.pl' | xargs -r chmod 755
chown -R "$TARGET_ACCT":"$TARGET_ACCT" "$SUBDOMAIN"
find "$SUBDOMAIN" -name .htaccess -exec chown "$TARGET_ACCT"."$TARGET_ACCT" {} \;
# End fixperms style corrections- making sure all files are owned properly, with correct permissions
done
fi
/usr/local/cpanel/scripts/restartsrv_httpd
## Fetching pastefile template for database information presentation to customer
wget -q https://raw.githubusercontent.com/InterGenStudios/CMS-Installer/master/owndbinfo
# Adds database info into template
sed -i -e "s/TARGET/$TARGET/g" -e "s/OWN_CV/$OWN_CV/" -e "s/DBU/$DBU_NAME/" -e "s/PASS/$DBU_PASS/" -e "s/DB/$DB_NAME/" owndbinfo
# Creates paste for database info using 'stikked'
curl -d name=ownCloudInstaller -d expire=120 -d private=1 --data-urlencode text@owndbinfo -s http://nobits.ml/api/create > tempaste
# converts 'stikked' paste to raw output URL
sed -i -e 's/view/view\/raw/' tempaste
clear
HEADER
GREEN
printf "The %s" "$CMS"
printf " Personal Cloud Storage Management System\n"
printf " Version %s" "$OWN_CV"
printf " has been installed for"
WHITE
echo " $TARGET"
echo
WHITE
# Prints htaccess warning if flag was set by SUBDOMAIN_HT_CHECK
HT_CHECK_WARN
echo
echo "Provide the Database Info URL to your customer"
GREEN
echo "(needed for finalizing installation)"
echo
printf "==> "
WHITE
printf "%s" "$(cat tempaste)"
printf "\n\n"
printf "Provide the following %s" "$CMS"
printf " URL to your customer"
printf "\n"
echo "and advise them to finalize their installation:"
echo
GREEN
printf "==> "
WHITE
printf "http://%s" "$TARGET"/setup-owncloud.php
printf "\n\n\n"
# Remove PASTE URL tempfiles
rm owndbinfo tempaste
SET_CMSLOG
}
#---------------------------------------------#
# END - CMS & DATABASE INSTALLATION FUNCTIONS #
#---------------------------------------------#
#------------------------------------#
# BEGIN - LOGGING & BACKUP FUNCTIONS #
#------------------------------------#
# Puts cms log into place with timestamp
SET_CMSLOG () {
if [ -f /var/log/CMS-Installer_logs/cmslog ]; then
sed -i -e 's/[\x01-\x1F\x7F]//g' -e 's|\[1m\[32m||g' -e 's|(B\[m||g' -e 's|\[1m\[32m||g' -e 's|\[H\[2J||g' -e 's|\[1m\[31m||g' -e 's|\[1m\[34m||g' -e 's|\[5A\[K||g' -e 's|\[1m\[33m||g' /var/log/CMS-Installer_logs/cmslog
mv /var/log/CMS-Installer_logs/cmslog /var/log/CMS-Installer_logs/instcms_log-"$TARGET"-"$TIMESTAMP"
exit 0
else
exit 0
fi
}
SET_CMSLOG_1 () {
if [ -f /var/log/CMS-Installer_logs/cmslog ]; then
sed -i -e 's/[\x01-\x1F\x7F]//g' -e 's|\[1m\[32m||g' -e 's|(B\[m||g' -e 's|\[1m\[32m||g' -e 's|\[H\[2J||g' -e 's|\[1m\[31m||g' -e 's|\[1m\[34m||g' -e 's|\[5A\[K||g' -e 's|\[1m\[33m||g' /var/log/CMS-Installer_logs/cmslog
mv /var/log/CMS-Installer_logs/cmslog /var/log/CMS-Installer_logs/instcms_log-"$TARGET"-"$TIMESTAMP"
exit 1
else
exit 1
fi
}
# DLev said I had to make this, so here it is- backup support.
BACKUP_OPTION () {
echo
WHITE
echo "Would you like to make a backup of"
echo
GREEN
echo "$TARGET_PATH"
echo
WHITE
echo "move it to "
echo
BLUE
echo "/var/log/CMS-Installer_backups/"
echo
WHITE
echo -n "and run the installer again [y/N]? "
read BACKUP
if [ "$BACKUP" = "y" ] || [ "$BACKUP" = "Y" ]; then
clear
HEADER
GREEN
echo "Backing up $TARGET_PATH..."
# Set up the backup directory
mkdir -p /var/log/CMS-Installer_backups
WHITE
echo "(this may take a moment)"
if [ "$EXISTS" = "WORDPRESS" ]; then
# Grabs the wordpress database for the backup
mysqldump "$(grep DB "$TARGET_PATH"wp-config.php | cut -d "'" -f 4 | head -1)" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
elif [ "$EXISTS" = "DRUPAL" ]; then
# Grabs the drupal database for the backup
mysqldump "$(grep -A 5 '$databases = array (' "$TARGET_PATH"sites/default/settings.php | grep "'database'" | awk '{print $3}' | sed -e "s/'//g" -e "s/,//")" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
elif [ "$EXISTS" = "JOOMLA" ]; then
# Grabs the joomla database for the backup
mysqldump "$(grep "public \$db =" "$TARGET_PATH"configuration.php | awk '{print $4}' | sed -e "s/'//g" -e "s/;//")" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
elif [ "$EXISTS" = "OCPORTAL" ]; then
# Grabs the ocportal database for the backup
mysqldump "$(grep -m 1 db_site "$TARGET_PATH"info.php | cut -d "'" -f 4)" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
elif [ "$EXISTS" = "MODXREVO" ]; then
# Grabs the mxrevolution database for the backup
mysqldump "$(grep '$dbase =' "$TARGET_PATH"core/config/config.inc.php | sed -e "s|\$dbase = '||" -e "s|';||")" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
else
# Grabs the owncloud database for the backup
mysqldump "$(grep dbname "$TARGET_PATH"owncloud/config/config.php | sed -e "s/'/ /g" | awk '{print $3}')" > "$TARGET_PATH""$TARGET_ACCT"_"$EXISTS".sql
fi
tar zcf "$TARGET_ACCT"_"$EXISTS"_"$TIMESTAMP"_backup.tar.gz "$TARGET_PATH" &&
# Put the backup away for safe-keeping
mv "$TARGET_ACCT"_"$EXISTS"_"$TIMESTAMP"_backup.tar.gz /var/log/CMS-Installer_backups/ &&
echo
clear
HEADER
GREEN
echo "Backup of the $EXISTS installation in $TARGET_PATH complete."
echo
echo "Clearing $TARGET_PATH for new installation..."
rm -rf "$TARGET_PATH"* && rm -rf "$TARGET_PATH".??* &&
mkdir "$TARGET_PATH"cgi-bin && chown "$TARGET_ACCT":"$TARGET_ACCT" "$TARGET_PATH"cgi-bin
echo
echo "$TARGET_PATH cleared."
echo
echo "Restarting installer..."
sleep 2
unset EXISTS
# Loop once the backup is completed
CONFIRM_INSTALL
else
clear
HEADER
WHITE
echo "Without backing up and moving the current data in"
echo "$TARGET_PATH the installer cannot continue."
echo
RED
echo "Exiting..."
sleep 1
clear
printf "\n\n\n"
# Backup or get out
WHITE
SET_CMSLOG_1
fi
}
EXISTING_DATA_BACKUP () {
clear
HEADER
YELLOW
echo "--------"
RED
echo "WARNING!"
YELLOW
echo "--------"
RED
echo
echo "Data exists in $TARGET_PATH."
echo
WHITE
echo "Would you like to make a backup of"
echo
GREEN
echo "$TARGET_PATH"
echo
WHITE
echo "move it to "
echo
BLUE
echo "/var/log/CMS-Installer_backups/"
echo
WHITE
echo -n "and run the installer again [y/N]? "
read BACKUP
if [ "$BACKUP" = "y" ] || [ "$BACKUP" = "Y" ]; then
clear
HEADER
GREEN
echo "Backing up $TARGET_PATH..."
WHITE
echo "(this may take a moment)"
sleep 1
mkdir -p /var/log/CMS-Installer_backups
tar zcf "$TARGET"_"$TIMESTAMP"_backup.tar.gz "$TARGET_PATH" &&
mv "$TARGET"_"$TIMESTAMP"_backup.tar.gz /root/support/scripts/CMS-Installer_backups/ &&
echo
clear
HEADER
GREEN
echo "Backup of the data in $TARGET_PATH complete."
echo
echo "Clearing $TARGET_PATH for new installation..."
rm -rf "$TARGET_PATH"* && rm -rf "$TARGET_PATH".??* &&
mkdir "$TARGET_PATH"cgi-bin && chown "$TARGET_ACCT":"$TARGET_ACCT" "$TARGET_PATH"cgi-bin
echo
echo "$TARGET_PATH cleared."
echo
echo "Restarting installer..."
sleep 2
CONFIRM_INSTALL
else
clear
HEADER
WHITE
echo "Without backing up and moving the current data in"
echo "$TARGET_PATH the installer cannot continue."
echo
RED
echo "Exiting..."
sleep 1
clear
printf "\n\n\n"
WHITE
SET_CMSLOG_1
fi
}
# Same routine as the installation check and backup, but for data other than CMS installations. Need to have it generically look for database info and grab it if it's there
CHECK_EXISTING_DATA () {
FILE=""
DIR="$TARGET_PATH"
if [ "$TARGET_TYPE" = "MAINDOMAIN" ]; then
for SUBDOMAIN_ENTRY in $(grep $TARGET /etc/userdomains | cut -d ':' -f 1 | sed -e 's/\./ /g' | awk '{print $1}' | grep -v $TARGET_ACCT); do
if [ "$(grep "$SUBDOMAIN_ENTRY" /usr/local/apache/conf/httpd.conf | head -3 | tail -1 | awk '{print $2}')" = /home/"$TARGET_ACCT"/public_html/"$SUBDOMAIN_ENTRY" ]; then
echo "$SUBDOMAIN_ENTRY" | cut -d '.' -f 1 >> VALID_SUBDOMAINS
else
echo "$SUBDOMAIN_ENTRY" | cut -d '.' -f 1 >> SUBDOMAINS_OUTSIDE_PUBLIC_HTML
fi
done
BEGINNING_ENTRY="$(head -1 < VALID_SUBDOMAINS)"
echo cgi-bin >> VALID_SUBDOMAINS
sed -i -e ':a;N;$!ba;s/\n/\\|/g' VALID_SUBDOMAINS
mv VALID_SUBDOMAINS /home/"$TARGET_ACCT"/
mv SUBDOMAINS_OUTSIDE_PUBLIC_HTML /home/"$TARGET_ACCT"/
if [ "$(ls -A "$DIR" | grep -v $(cat /home/"$TARGET_ACCT"/VALID_SUBDOMAINS))" ]; then
rm /home/"$TARGET_ACCT"/VALID_SUBDOMAINS /home/"$TARGET_ACCT"/SUBDOMAINS_OUTSIDE_PUBLIC_HTML
EXISTING_DATA_BACKUP
else
rm /home/"$TARGET_ACCT"/VALID_SUBDOMAINS /home/"$TARGET_ACCT"/SUBDOMAINS_OUTSIDE_PUBLIC_HTML
echo "Existing data belongs to subdomains, no backup needed"
printf "\n\n"
echo "Target Directory clear for installation..."
sleep 1
fi
else
if [ "$(ls -A "$DIR" | grep -v cgi)" ]; then
EXISTING_DATA_BACKUP
else
echo "Target Directory clear for installation..."
sleep 1
fi
fi
}
#----------------------------------#
# END - LOGGING & BACKUP FUNCTIONS #
#----------------------------------#