SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. ###Saved as /usr/local/bin/wp-config.sh on dev server. Dont forget to chmod +x it###
  4.  
  5. #Dev Server Deploy configs AKA BASH MAGIC
  6. #Setting proper format of name and user for db to set wp-config.php
  7. db_name=$(echo $VIRTUALSERVER_USER | sed -r 's/[.,-]+/_/g')
  8. db_user=$(echo $VIRTUALSERVER_USER | cut -c -32)
  9.  
  10. #SED of wp-config AKA ".gsub" for rubyist
  11. #All master themes must have a wp-config1.php file with placeholder variables
  12. #Replace "wpuser123" with "WP_SITEURL" and save to a tmp_file
  13. sed 's/wpruser123/'WP_SITEURL'/g' $VIRTUALSERVER_HOME/public_html/wp-config1.php > tmp_file
  14.  
  15. #That temp file we just created in the last step lets rename it to wo-config2.php
  16. mv tmp_file $VIRTUALSERVER_HOME/public_html/wp-config2.php
  17.  
  18. #Now in wp-config2.php lets replace "wprpass123" with the Virtual domains global variable of "$VIRTUALSERVER_PASS" and save this file as a #tmp file once again.
  19. sed 's/wprpass123/'$VIRTUALSERVER_PASS'/g' $VIRTUALSERVER_HOME/public_html/wp-config2.php > tmp_file
  20.  
  21. #Rename that tmp file to wp-config.php which deletes any other files if exist named wp-config.php
  22. mv tmp_file "$VIRTUALSERVER_HOME/public_html/wp-config.php"
  23.  
  24. #In our newly created wp-config.php lets set our final values by using SED to replace line 35 and 38
  25. #If lines in the original wp-config1.php are ever altered the following SEDs will not work and lead to DB connection errors
  26. sed -i '35s/.*/define('"'DB_NAME'"', '"'$db_name'"');/' $VIRTUALSERVER_HOME/public_html/wp-config.php
  27. sed -i '38s/.*/define('"'DB_USER'"', '"'$db_user'"');/' $VIRTUALSERVER_HOME/public_html/wp-config.php
  28.  
  29. #Clean up after ourselves a bit and delete wp-config1.php and wp-config2.php
  30. rm $VIRTUALSERVER_HOME/public_html/wp-config1.php
  31. rm $VIRTUALSERVER_HOME/public_html/wp-config2.php
  32.  
  33. ###NOTE ### In order find template identification number ssh into server and execute `virtualmin list-templates`
  34. #More BASH MAGIC the following code DEPENDING ON TEMPLATE/THEME will accordingly grab a copy of the master template sql of the live site so this is always current and will install it into the new domain we are creating.
  35. if [ $VIRTUALSERVER_TEMPLATE -eq 149505982215162 ]; then
  36.  
  37. #Mysql dump of master template
  38. mysqldump polishedpro > $VIRTUALSERVER_HOME/public_html/wprb.sql
  39. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  40.  
  41. #Upload of mysql dump
  42. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  43.  
  44. #Final wp-config.php SETTING removing placeholder and setting final values
  45. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  46. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  47.  
  48. #Set ownership of public_html folder to virtual domain owner because when these scripts are ruuning they are under root so any file changes #are saved as root and will be blocked from any other user. For example if root owns this folder then U are not allowed to edit or upload #anything from wp backend and all sorts of other funky things.
  49. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  50.  
  51. ###From here down is mostly repetition depending on theme depending where it pulls sql from and so on###
  52. ### Could use refactoring but if not broke dont fix it
  53. elif [ $VIRTUALSERVER_TEMPLATE -eq 149505993915397 ]; then
  54. mysqldump luminous > $VIRTUALSERVER_HOME/public_html/wprb.sql
  55. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  56. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  57. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  58. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  59. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  60.  
  61.  
  62. #elif [ $VIRTUALSERVER_TEMPLATE -eq 149505993915397 ] && [ $VIRTUALSERVER_FIELD_BRAND -eq 2 ]; then
  63. #mysqldump luminous_ruudwebsuite_com > $VIRTUALSERVER_HOME/public_html/wprb.sql
  64. #chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  65. #mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  66. #sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  67. #sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  68. #echo $VIRTUALSERVER_FIELD_BRAND > /usr/local/bin/data.txt
  69.  
  70. elif [ $VIRTUALSERVER_TEMPLATE -eq 150187886622300 ]; then
  71. mysqldump trueblue > $VIRTUALSERVER_HOME/public_html/wprb.sql
  72. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  73. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  74. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  75. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  76. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  77.  
  78. elif [ $VIRTUALSERVER_TEMPLATE -eq 150187895023070 ]; then
  79. mysqldump cleanco > $VIRTUALSERVER_HOME/public_html/wprb.sql
  80. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  81. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  82. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  83. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  84. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  85.  
  86. elif [ $VIRTUALSERVER_TEMPLATE -eq 150187900723227 ]; then
  87. mysqldump fpolishedpro_rheemwebsuite_com > $VIRTUALSERVER_HOME/public_html/wprb.sql
  88. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  89. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  90. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  91. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  92. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  93.  
  94. elif [ $VIRTUALSERVER_TEMPLATE -eq 149505987915222 ]; then
  95. mysqldump steadyscroll > $VIRTUALSERVER_HOME/public_html/wprb.sql
  96. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  97. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  98. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  99. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  100. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  101.  
  102. elif [ $VIRTUALSERVER_TEMPLATE -eq 149505991515361 ]; then
  103. mysqldump evenkeel > $VIRTUALSERVER_HOME/public_html/wprb.sql
  104. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  105. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  106. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  107. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  108. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  109.  
  110. elif [ $VIRTUALSERVER_TEMPLATE -eq 149505977015116 ]; then
  111. mysqldump anode_rheemwebsuite_com > $VIRTUALSERVER_HOME/public_html/wprb.sql
  112. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  113. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  114. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  115. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  116. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  117.  
  118.  
  119. elif [ $VIRTUALSERVER_TEMPLATE -eq 150121566419292 ]; then
  120. mysqldump express_rheemwebsuite_com > $VIRTUALSERVER_HOME/public_html/wprb.sql
  121. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  122. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  123. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  124. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  125. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  126.  
  127. elif [ $VIRTUALSERVER_TEMPLATE -eq 150121571719377 ]; then
  128. mysqldump flux_rheemwebsuite_com > $VIRTUALSERVER_HOME/public_html/wprb.sql
  129. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  130. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  131. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  132. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  133. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  134.  
  135. elif [ $VIRTUALSERVER_TEMPLATE -eq 150169773920859 ]; then
  136. mysqldump jovial > $VIRTUALSERVER_HOME/public_html/wprb.sql
  137. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  138. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  139. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  140. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  141. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  142. else
  143. mysqldump cleanslate > $VIRTUALSERVER_HOME/public_html/wprb.sql
  144. chmod +x $VIRTUALSERVER_HOME/public_html/wprb.sql
  145. mysql --user=$db_user --password=$VIRTUALSERVER_PASS --database=$db_name < $VIRTUALSERVER_HOME/public_html/wprb.sql
  146. sed -i -e 's/wphome/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  147. sed -i -e 's/wpsiteurl/'$VIRTUALSERVER_USER'/g' $VIRTUALSERVER_HOME/public_html/wp-config.php
  148. chown -R $VIRTUALSERVER_USER:$VIRTUALSERVER_USER $VIRTUALSERVER_HOME/public_html/
  149. fi
  150.  
  151. #Installs ssl on domain and auto renew every 2 months
  152. sudo virtualmin generate-letsencrypt-cert --domain $VIRTUALSERVER_DOM --host $VIRTUALSERVER_DOM --renew 2
  153.  
  154. #clean up after ourselves and delete old sql files lingering around
  155. rm $VIRTUALSERVER_HOME/public_html/wprb.sql
  156. rm $VIRTUALSERVER_HOME/public_html/wprb2.sql
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top