├── .gitignore ├── README.md ├── LICENSE └── WPStager.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear in the root of a volume 14 | .DocumentRevisions-V100 15 | .fseventsd 16 | .Spotlight-V100 17 | .TemporaryItems 18 | .Trashes 19 | .VolumeIcon.icns 20 | .com.apple.timemachine.donotpresent 21 | 22 | # Directories potentially created on remote AFP share 23 | .AppleDB 24 | .AppleDesktop 25 | Network Trash Folder 26 | Temporary Items 27 | .apdisk 28 | 29 | debug.sh 30 | test 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](http://i.imgur.com/KNVcUyG.png) 2 | 3 | WPStager 4 | ======== 5 | 6 | WordPress Provisioning and Staging Simplified 7 | 8 | What does this do? This script automates the task of creating a local, as well as a staging WordPress installation requiring only [MAMP](https://www.mamp.info/). It can also pull an existing WordPress installation onto your local dev environment. It's packed with nifty little features, like for example automatic configuration of MAMP to listen on port 80 and setting MAMP's config to use pretty domain names like http://testinstall.test. It automatically downloads the latest version of WordPress and installs it into your MAMP htdocs folder. It even creates the wp-config.php file for you, so you don't have to. It's a true 1-minute install. 9 | 10 | But it doesn't stop there. A thing I always hated, was the setup of a WordPress staging installation on my webserver. Fiddling around with Apache's vhosts, changing DNS records to use subdomains and creating the MySQL database. By utilizing [CloudFlare](https://www.cloudflare.com/)'s DNS API and with the use of [Wordmove](https://github.com/welaika/wordmove), the staging provisioning process is now invoked through a single command. 11 | 12 | ## Note: If you find any issues, please file them [here](https://github.com/kLOsk/WPStager/issues)! 13 | 14 | ![](http://i.imgur.com/Wp5qQVR.gif) 15 | 16 | ## Features 17 | 18 | - NEW: Ability to pull in existing WordPress installations from a production server! 19 | - Uncomplicated Bash script 20 | - Stupidly easy to use 21 | - Uses MAMP so you don't have to mess around with VM's 22 | - Optionally creates an online staging environment via SSH 23 | - Automatic local .dev domain generation 24 | - Automatic CloudFlare Subdomain DNS provisioning 25 | - Apache vhost configuration on the staging server using [virtualhost](https://github.com/RoverWire/virtualhost) 26 | - Automatic configuration of [Wordmove](https://github.com/welaika/wordmove) for command line deploying and pulling 27 | 28 | ## Requirements 29 | 30 | - Mac OSX (10.10 or higher) 31 | - Xcode Command Line Tools (will automatically install if not available) 32 | - Homebrew [http://brew.sh/](http://brew.sh/) (will automatically install if not available) 33 | - MAMP (Free Version) [https://www.mamp.info/](https://www.mamp.info/) 34 | - [Wordmove](https://github.com/welaika/wordmove) (will automatically install if not available) 35 | - CloudFlare DNS [https://www.cloudflare.com/](https://www.cloudflare.com/) (Optional: Only needed for remote staging server) 36 | - Apache and MySQL on a root staging server 37 | - [virtualhost](https://github.com/RoverWire/virtualhost) (will automatically install if not available) 38 | - Public SSH Keys (will automatically install if not available) 39 | 40 | ## Version 41 | 42 | 1.1.0 43 | 44 | ### Changelog 45 | 46 | #### 1.1.0 47 | 48 | * NEW FEATURE: You can now pull in production server sites into your local dev environment. WPStager will configure the Movefile for you! 49 | * Fix: Changed .dev to .test recommendation for local dev environment domain 50 | 51 | #### 1.0.2 52 | 53 | * Fixed remote creation of databases, that contain hyphens in their name 54 | * Added support for future remote configuration files 55 | 56 | #### 1.0.1 57 | 58 | * Small fixes 59 | 60 | #### 1.0.0 61 | 62 | * Initial public release 63 | 64 | ## Installation 65 | 66 | ### Using Terminal 67 | 68 | #### Local Installation 69 | 70 | ```bash 71 | $ cd ~ 72 | $ curl -o wpstager https://raw.githubusercontent.com/kLOsk/WPStager/master/WPStager.sh 73 | $ chmod +x wpstager 74 | ``` 75 | 76 | #### Global Installation 77 | 78 | Simply follow the local installation and then move the script 79 | 80 | ```bash 81 | $ sudo mv wpstager /usr/local/bin/wpstager 82 | ``` 83 | 84 | ## Usage 85 | 86 | ### Local Installation 87 | 88 | ```bash 89 | $ ./wpstager 90 | ``` 91 | 92 | ### Global Installation 93 | 94 | ```bash 95 | $ wpstager 96 | ``` 97 | 98 | ## What does the script do? 99 | 100 | The script has two main features: 101 | 102 | 1. Setup a local WordPress Installation with a pretty http://xxxx.dev local domain 103 | 2. Generate an identical Staging copy on a remote server including CloudFlare DNS adjustment and Apache vhost configuration 104 | 105 | Basically you run one command, answer a few questions and have a local Wordpress installation as well as an identical staging server copy with full push/pull deployment capabilities. 106 | 107 | ### How to use the local WordPress Installation Feature 108 | 109 | It is perfectly fine to not use the Staging Server function and only use the tool to install WordPress locally. 110 | 111 | The script will install all it's dependencies automatically and only requires the use of a Mac and the installation of the MAMP webserver to begin with. 112 | 113 | It will automatically configure MAMP to work like a "real" webserver so the WordPress installation can be accessed via http://yourwpdevdomain.dev. 114 | 115 | It will then download the latest WordPress version from WordPress.org, setup the MySQL database and generate the wp-config.php file. Once this is finished the browser will open and you will be presented with a new vanilla WordPress installation. 116 | 117 | 118 | ### How to use the Staging Server Feature 119 | 120 | The script expects that the (remote) staging server is running a LAMP stack. NGINX is currently not supported. 121 | 122 | It is required to have root access to the staging server via SSH, to set the file ownership (www-data), as well as file permissions for WordPress to function properly. 123 | 124 | The script makes use of a tool called virtualhost to adjust Apache's vhost and add the newly created site to point to the installation folder. The installation folder can be set manually but it is recommended to use either /var/www or /var/www/html as per Apache's 2.2/2.4 spec. 125 | 126 | The script can optionally use CloudFlare to setup the DNS redirection to a nely created subdomain (think http://staging.yourdomain.com) 127 | 128 | Please note that in order to use CloudFlare's DNS API, it is required to have a (free) account with them and that your staging domain is pointing to your staging server. Have a look at this tutorial on [How to setup CloudFlare CDN](http://blog.daniel-klose.com/wordpress/setup-free-cloudflare-cdn-wordpress/). You will also require a [CloudFlare API key](https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-CloudFlare-API-key-) so the script can modify your DNS records! The script will ask you for these credentials during installation, or you can preset them manually by editing the script. 129 | 130 | After the script is finished, it is important to first finish the local WP installation, by setting up an admin user in the browser. After that run Wordmove to sync the local installation with your staging server. You can then log into your staging WordPress installation with the same credentials as your local installation. 131 | 132 | Make yourself comfortable with [Wordmove](https://github.com/welaika/wordmove) as this will be your main tool for syncing the local dev environment and the staging server afterwards. 133 | 134 | 135 | ## To Do 136 | 137 | - Support for NGINX 138 | - Auto config and options 139 | 140 | ## Credits 141 | 142 | - Homebrew [http://brew.sh/](http://brew.sh/) 143 | - MAMP [https://www.mamp.info/](https://www.mamp.info/) 144 | - [Wordmove](https://github.com/welaika/wordmove) 145 | - CloudFlare CDN [https://www.cloudflare.com/](https://www.cloudflare.com/) 146 | - [virtualhost](https://github.com/RoverWire/virtualhost) 147 | - [Nate Landau](http://natelandau.com/bash-scripting-utilities/) 148 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /WPStager.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | ################################################################################ 4 | ## WPStager - WordPress Provisioning and Staging Simplified ## 5 | ################################################################################ 6 | # 7 | # https://github.com/kLOsk/WPStager 8 | # http://www.daniel-klose.com 9 | # Made in Japan with <3 10 | # Licensed under GPL2 (https://github.com/kLOsk/WPStager/blob/master/LICENSE) 11 | # 12 | ############################## SpeedUp Config ################################## 13 | ## Feel free to change these variables to speed up the provisioning process. 14 | ## It is perfectly fine to not change these, or just change the ones you feel like presetting. 15 | ## If a config is not preset the script will automatically query during its execution. 16 | MYSQLUSER="change_me" # Your MAMP MySQL user. Default "root" 17 | MYSQLPWD="change_me" # Your MAMP MySQL password. Default "root" 18 | CFAPI="change_me" # Your CloudFlare v4 Api Zone ID (eg: a34ea34aeaea424ae25352) https://api.cloudflare.com/#getting-started-resource-ids (Can be found in Domain Summary when selecting a domain in CloudFlare) 19 | CFSECRET="change_me" # Your CloudFlare Api key. Can be found here: https://www.cloudflare.com/a/account/my-account 20 | CFEMAIL="change_me" # Your CloudFlare e-mail account (e.g. howdy@wordpress.org) 21 | CFDOMAIN="change_me" # The second level domain which is managed by CloudFlare (e.g. stageserver.com) 22 | CFSERVER="change_me" # The IP address of your staging server CF should point the new subdomain to (e.g. 134.12.34.56) 23 | SSWEBDIR="change_me" # The root directory of your webserver. With Apache 2.2 that used to be /var/www but now with 2.4 this is /var/www/html - No trailing slash at the end! 24 | SSMYSQLSERVER="change_me" # Your MySQL Staging Server IP (e.g. localhost (if run on the staging webserver) or e.g. 56.137.45.23) 25 | SSMYSQLUSER="change_me" # Your MySQL Staging Server user 26 | SSMYSQLPWD="change_me" # Your MySQL Staging Server password 27 | SSSSH="change_me" # Your Staging Server SSH address (e.g. 34.23.56.12 or e.g. stageserver.com) 28 | SSSSHUSER="change_me" # Only change this to root. If you use another account rsync won't be able to set the correct permissions for the staging WordPress installation :-/ 29 | 30 | ################################################################################ 31 | ## All Done! Don't change anything below this line, or hell will break loose! ## 32 | ################################################################################ 33 | 34 | # 35 | #Set Colors (http://natelandau.com/bash-scripting-utilities/) 36 | # 37 | 38 | bold=$(tput bold) 39 | underline=$(tput sgr 0 1) 40 | reset=$(tput sgr0) 41 | 42 | purple=$(tput setaf 171) 43 | red=$(tput setaf 1) 44 | green=$(tput setaf 76) 45 | tan=$(tput setaf 3) 46 | blue=$(tput setaf 38) 47 | 48 | # 49 | # Headers and Logging 50 | # 51 | 52 | e_header() { printf "\n${bold}${purple}========== %s ==========${reset}\n" "$@" 53 | } 54 | e_arrow() { printf "➜ $@\n" 55 | } 56 | e_success() { printf "${green}✔ %s${reset}\n" "$@" 57 | } 58 | e_error() { printf "${red}✖ %s${reset}\n" "$@" 59 | } 60 | e_warning() { printf "${tan}➜ %s${reset}\n" "$@" 61 | } 62 | e_underline() { printf "${underline}${bold}%s${reset}\n" "$@" 63 | } 64 | e_bold() { printf "${bold}%s${reset}\n" "$@" 65 | } 66 | e_note() { printf "${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" 67 | } 68 | 69 | ##Check for packages and OS 70 | 71 | type_exists() { 72 | if [ $(type -P $1) ]; then 73 | return 0 74 | fi 75 | return 1 76 | } 77 | 78 | is_os() { 79 | if [[ "${OSTYPE}" == $1* ]]; then 80 | return 0 81 | fi 82 | return 1 83 | } 84 | 85 | clear 86 | 87 | e_header "WPStager - WordPress Provisioning and Staging Simplified" 88 | e_underline "Please keep in mind, that this script makes heavy use of third party software." 89 | 90 | if is_os "darwin"; then 91 | e_success "Mac OSX detected" 92 | else 93 | e_error "You are not using a Mac. Please understand that WPStager currently only works on Mac OSX! https://github.com/kLOsk/WPStager" 94 | exit 1 95 | fi 96 | 97 | ## Check if config file exists 98 | if [ -f "$HOME/.wpstager.cfg" ] 99 | then 100 | e_success "WPStager configuration file found." 101 | e_warning "Reading configuration..." 102 | source $HOME/.wpstager.cfg 103 | else 104 | e_error "WPStager configuration file not found." 105 | fi 106 | 107 | if [ -d "/Applications/MAMP/MAMP.app" ] 108 | then 109 | e_success "MAMP installed at /Applications/MAMP/" 110 | e_warning "Please make sure to use the default MAMP htdocs directory at /Applications/MAMP/htdocs" 111 | else 112 | e_error "Error: MAMP is not installed. Please install MAMP from https://www.mamp.info/" 113 | exit 1 114 | fi 115 | 116 | # install Xcode Command Line Tools 117 | xcode-select -p &> /dev/null 118 | if [ $? -eq 0 ]; then 119 | e_success "Xcode Command Line Tools installed" 120 | else 121 | e_error "Xcode Command Line Tools not installed" 122 | e_warning "Installing now... (This might take a while)" 123 | # https://github.com/timsutton/osx-vm-templates/blob/ce8df8a7468faa7c5312444ece1b977c1b2f77a4/scripts/xcode-cli-tools.sh 124 | touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress; 125 | PROD=$(softwareupdate -l | 126 | grep "\*.*Command Line" | 127 | head -n 1 | awk -F"*" '{print $2}' | 128 | sed -e 's/^ *//' | 129 | tr -d '\n') 130 | softwareupdate -i "$PROD" -v; 131 | fi 132 | 133 | # Check for HomeBrew 134 | if type_exists 'brew'; then 135 | e_success "Homebrew detected" 136 | else 137 | e_error "Homebrew has not been installed yet." 138 | printf "Do you want WPStager to install Homebrew for you (http://brew.sh/)? (Y/n)" 139 | read HB 140 | HB=${HB:-y} 141 | if [ "$HB" = "y" ] || [ "$HB" = "Y" ]; then 142 | e_warning "Installing Homebrew..." 143 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 144 | if [ $? -eq 0 ]; then 145 | e_success "Homebrew installed" 146 | else 147 | e_error "Something went wrong Please visit http://brew.sh/ or get in touch at https://github.com/kLOsk/WPStager" 148 | exit 1 149 | fi 150 | else 151 | e_error "WPStager requires Homebrew to work. Please install it manually from http://brew.sh/" 152 | exit 1 153 | fi 154 | fi 155 | 156 | e_warning "Installing rsync and gnu-sed since OSX ships with outdated versions" 157 | brew tap homebrew/dupes &> /dev/null 158 | brew install rsync gnu-sed &> /dev/null 159 | if [ $? -eq 0 ]; then 160 | e_success "rsync and gnu-sed successfully updated" 161 | else 162 | e_error "Something went wrong with homebrew. Please get in touch at https://github.com/kLOsk/WPStager" 163 | exit 1 164 | fi 165 | 166 | # Add MAMP MySQL bins to PATH 167 | if type_exists 'mysql'; then 168 | e_success "mysql bin detected" 169 | else 170 | e_warning "Adding MAMP mysql to /usr/local/bin" 171 | sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql 172 | fi 173 | 174 | if type_exists 'mysqlcheck'; then 175 | e_success "mysqlcheck bin detected" 176 | else 177 | e_warning "Adding MAMP mysqlcheck to /usr/local/bin" 178 | sudo ln -s /Applications/MAMP/Library/bin/mysqlcheck /usr/local/bin/mysqlcheck 179 | fi 180 | 181 | if type_exists 'mysqldump'; then 182 | e_success "mysqldump bin detected" 183 | else 184 | e_warning "Adding MAMP mysqldump to /usr/local/bin" 185 | sudo ln -s /Applications/MAMP/Library/bin/mysqldump /usr/local/bin/mysqldump 186 | fi 187 | 188 | # Check for Wordmove 189 | if type_exists 'wordmove'; then 190 | e_success "Wordmove detected" 191 | else 192 | e_error "Wordmove has not been installed yet." 193 | e_note "WPStager can install Wordmove for you (globally with sudo). If you want your Ruby Gems to be installed locally only, please install Wordmove manually (https://github.com/welaika/wordmove)" 194 | printf "Install Wordmove globally? (Y/n)" 195 | read WM 196 | WM=${WM:-y} 197 | if [ "$WM" = "y" ] || [ "$WM" = "Y" ]; then 198 | e_warning "Installing Wordmove..." 199 | sudo gem install wordmove 200 | if [ $? -eq 0 ]; then 201 | e_success "Wordmove installed" 202 | else 203 | e_error "Something went wrong. Please visit https://github.com/welaika/wordmove or https://github.com/kLOsk/WPStager" 204 | exit 1 205 | fi 206 | else 207 | e_error "WPStager requires Wordmove to work. Please install it manually from https://github.com/welaika/wordmove" 208 | exit 1 209 | fi 210 | fi 211 | 212 | ## Sanity check for programs existence 213 | #Global declaration area 214 | declare -r T_CMDS="curl wordmove" 215 | 216 | #Sanity check: Test if commands are in $PATH 217 | for t_cmd in $T_CMDS 218 | do 219 | type -P "$t_cmd" >> /dev/null && : || { 220 | echo -e "$t_cmd not found in PATH ." >&2 221 | e_error "Please get in touch at https://github.com/kLOsk/WPStager" 222 | exit 1 223 | } 224 | done 225 | 226 | ## Check if Apache and MySQL are running 227 | WEBSERVER='httpd' 228 | 229 | if ps ax | grep -v grep | grep $WEBSERVER > /dev/null 230 | then 231 | e_success "$WEBSERVER service running, everything is fine" 232 | else 233 | e_error "$WEBSERVER is not running" 234 | e_note "Make sure to start MAMP before running WPStager" 235 | open "/Applications/MAMP/MAMP.app" 236 | exit 237 | fi 238 | 239 | DBSERVER='mysql' 240 | if ps ax | grep -v grep | grep $DBSERVER > /dev/null 241 | then 242 | e_success "$DBSERVER service running, everything is fine" 243 | else 244 | e_error "$DBSERVER is not running" 245 | e_note "Make sure to start MAMP before running WPStager" 246 | open "/Applications/MAMP/MAMP.app" 247 | exit 248 | fi 249 | 250 | ## Fix Apache config for automatic pretty domains http://xxxx.dev 251 | if grep -Fxq "Listen 80" /Applications/MAMP/conf/apache/httpd.conf 252 | then 253 | e_success "Apache listening on port 80" 254 | else 255 | e_error "Apache not configured to listen on port 80" 256 | e_note "Fixing Apache to listen on port 80" 257 | gsed -i.bak '/Listen 8888/i Listen 80' /Applications/MAMP/conf/apache/httpd.conf 258 | if [ $? -eq 0 ]; then 259 | e_success "Apache configured to listen on port 80" 260 | SERVERRESTART="1" 261 | else 262 | e_error "Something went wrong when changing the Apache configuration" 263 | exit 1 264 | fi 265 | fi 266 | 267 | if grep -Fxq "#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf" /Applications/MAMP/conf/apache/httpd.conf 268 | then 269 | e_error "Apache not configured to include dynamic vhosts" 270 | e_note "Fixing Apache to include vhosts" 271 | gsed -i.bak '/httpd-vhosts\.conf/s/^#//g' /Applications/MAMP/conf/apache/httpd.conf 272 | if [ $? -eq 0 ]; then 273 | e_success "Apache configured to include dynamic vhosts" 274 | SERVERRESTART="1" 275 | else 276 | e_error "Something went wrong when changing the Apache configuration" 277 | exit 1 278 | fi 279 | else 280 | e_success "Apache includes dynamic vhosts conf" 281 | fi 282 | 283 | if grep -Fxq "#Dynamic Vhost" /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 284 | then 285 | e_success "Apache configured for dynamic vhosts" 286 | else 287 | e_error "Apache not configured for dynamic vhosts" 288 | e_note "Fixing Apache to support dynamic vhosts" 289 | mv /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf.bak 290 | touch /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 291 | echo "NameVirtualHost *:80" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 292 | echo $'\n' >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 293 | echo "#Dynamic Vhost" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 294 | echo "" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 295 | echo " UseCanonicalName Off" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 296 | echo " VirtualDocumentRoot /Applications/MAMP/htdocs/%0" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 297 | echo "" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 298 | if [ $? -eq 0 ]; then 299 | e_success "Apache configured for dynamic vhosts." 300 | SERVERRESTART="1" 301 | else 302 | e_error "Something went wrong when changing the Apache configuration" 303 | exit 1 304 | fi 305 | fi 306 | 307 | if [ "$SERVERRESTART" = "1" ]; then 308 | e_warning "Apache configuration was changed. Restarting Apache now" 309 | sudo /Applications/MAMP/Library/bin/apachectl stop 310 | sleep 10 311 | sudo /Applications/MAMP/Library/bin/apachectl start 312 | fi 313 | 314 | # 315 | ## Switch to MAMP htdocs directory 316 | # 317 | cd /Applications/MAMP/htdocs 318 | printf "What would you like to name your new WordPress development domain (i.e. devsite.test)? " 319 | read LOCALDOMAIN 320 | 321 | # 322 | ## Add the new local development domain name to /etc/hosts 323 | # 324 | sudo sh -c "echo \"127.0.0.1 $LOCALDOMAIN\" >> /etc/hosts" 325 | 326 | e_warning "Downloading WordPress Stable, see http://wordpress.org/" 327 | curl -L -O https://wordpress.org/latest.tar.gz 328 | tar -xf latest.tar.gz 329 | mv wordpress "$LOCALDOMAIN" 330 | rm latest.tar.gz 331 | 332 | if [ "$MYSQLUSER" = "change_me" ]; then 333 | printf "\nLocal MySQL User: (root)" 334 | read MYSQLUSER 335 | MYSQLUSER=${MYSQLUSER:-root} 336 | fi 337 | 338 | if [ "$MYSQLPWD" = "change_me" ]; then 339 | printf "Local MySQL Password: (root)" 340 | read MYSQLPWD 341 | MYSQLPWD=${MYSQLPWD:-root} 342 | fi 343 | 344 | printf "What would you like to name your new database? (%s)" "${LOCALDOMAIN%%.*}" 345 | read NEWDB 346 | NEWDB=${NEWDB:-${LOCALDOMAIN%%.*}} 347 | echo "CREATE DATABASE \`$NEWDB\`; GRANT ALL ON \`$NEWDB\`.* TO '$MYSQLUSER'@'localhost';" | /Applications/MAMP/Library/bin/mysql -u"$MYSQLUSER" -p"$MYSQLPWD" 348 | 349 | cd "$LOCALDOMAIN" 350 | 351 | e_warning "Setup Wordmove for local environment" 352 | 353 | # Create the Movefile for Wordmove 354 | 355 | touch movefile.yml 356 | cat <> movefile.yml 357 | global: 358 | sql_adapter: "default" 359 | 360 | local: 361 | vhost: "http://$LOCALDOMAIN" 362 | wordpress_path: "/Applications/MAMP/htdocs/$LOCALDOMAIN" # use an absolute path here 363 | 364 | database: 365 | name: "$NEWDB" 366 | user: "$MYSQLUSER" 367 | password: "$MYSQLPWD" 368 | host: "localhost" 369 | 370 | EOT 371 | 372 | ## Big Staging Block 373 | 374 | printf "Do you want to use an online Staging Environment? (y/N)" 375 | read STAGING 376 | STAGING=${STAGING:-n} 377 | if [ "$STAGING" = "y" ] || [ "$STAGING" = "Y" ]; then 378 | 379 | printf "Do you want to use CloudFlare DNS for automatic subdomain provisioning? (Y/n)" 380 | read CF 381 | CF=${CF:-y} 382 | if [ "$CF" = "y" ] || [ "$CF" = "Y" ]; then 383 | # 384 | #Require a cloudflare account 385 | # 386 | if [ "$CFEMAIL" = "change_me" ]; then 387 | printf "CloudFlare E-Mail Account (i.e. daniel@wpstager.com): " 388 | read CFEMAIL 389 | fi 390 | if [ "$CFAPI" = "change_me" ]; then 391 | printf "CloudFlare Api Zone ID: " 392 | read CFAPI 393 | fi 394 | if [ "$CFSECRET" = "change_me" ]; then 395 | printf "CloudFlare Api Key: " 396 | read CFSECRET 397 | fi 398 | if [ "$CFDOMAIN" = "change_me" ]; then 399 | printf "CloudFlare administrated Staging Domain (i.e. WPStager.com): " 400 | read CFDOMAIN 401 | fi 402 | if [ "$CFSERVER" = "change_me" ]; then 403 | printf "The IP address CloudFlare will route the new subdomain to (i.e. 34.23.1.34): " 404 | read CFSERVER 405 | fi 406 | 407 | printf "What's your staging domain? (%s.%s)" "${LOCALDOMAIN%%.*}" "$CFDOMAIN" 408 | read FULLDOMAIN 409 | FULLDOMAIN=${FULLDOMAIN:-${LOCALDOMAIN%%.*}.$CFDOMAIN} 410 | SUBDOMAIN=${FULLDOMAIN%%.*} 411 | 412 | e_warning "Generating DNS Entry with Cloudflare" 413 | curl -X POST 'https://api.cloudflare.com/client/v4/zones/'$CFAPI'/dns_records' \ 414 | -H 'X-Auth-Email: '$CFEMAIL \ 415 | -H 'X-Auth-Key: '$CFSECRET \ 416 | -H 'Content-Type: application/json' \ 417 | --data '{ 418 | "type": "A", 419 | "name": "'$SUBDOMAIN.$CFDOMAIN'", 420 | "content": "'$CFSERVER'", 421 | "service_mode": "1", 422 | "ttl": "1" 423 | }' 424 | else 425 | printf "What's your staging subdomain (i.e. clientsite.WPStager.com)? " 426 | read FULLDOMAIN 427 | fi 428 | 429 | # Requesting Apache webdir. Would be great to automate this! 430 | if [ "$SSWEBDIR" = "change_me" ]; then 431 | printf "\nWhere is the web root directory of your staging server? (/var/www)" 432 | read SSWEBDIR 433 | SSWEBDIR=${SSWEBDIR:-/var/www} 434 | fi 435 | 436 | if [ "$SSMYSQLSERVER" = "change_me" ]; then 437 | printf "Staging Server MySQL Host Address (Hit enter if MySQL server runs locally on the staging server): (localhost)" 438 | read SSMYSQLSERVER 439 | SSMYSQLSERVER=${SSMYSQLSERVER:-localhost} 440 | fi 441 | 442 | if [ "$SSMYSQLUSER" = "change_me" ]; then 443 | printf "Staging Server MySQL User: (root)" 444 | read SSMYSQLUSER 445 | SSMYSQLUSER=${SSMYSQLUSER:-root} 446 | fi 447 | 448 | if [ "$SSMYSQLPWD" = "change_me" ]; then 449 | printf "Staging Server MySQL Password: " 450 | read SSMYSQLPWD 451 | fi 452 | 453 | if [ "$SSSSH" = "change_me" ]; then 454 | if [ "$CFSERVER" = "change_me" ]; then 455 | printf "Staging Server SSH Host/IP Address (i.e. 1.2.3.4): " 456 | read SSSSH 457 | else 458 | printf "Staging Server SSH Host Address: (%s)" "$CFSERVER" #Needs fix as %s is change_me with default config and no cloudflare use 459 | read SSSSH 460 | SSSSH=${SSSSH:-$CFSERVER} 461 | fi 462 | fi 463 | 464 | if [ "$SSSSHUSER" = "change_me" ]; then 465 | e_warning "SSH user root is required for proper Apache permissions." 466 | e_warning "Permissions need to be fixed manually when not using root :-/" 467 | printf "Staging Server SSH user: (root)" 468 | read SSSSHUSER 469 | SSSSHUSER=${SSSSHUSER:-root} 470 | fi 471 | 472 | ## Setup Public Keys 473 | ## Check if local ssh keys exist 474 | e_warning "Check if public SSH key exists" 475 | if [ -f ~/.ssh/id_rsa.pub ]; then 476 | e_success "Public SSH key exists" 477 | ## If it exists check if its added on server. If not add it. 478 | KEY=$(cat ~/.ssh/id_rsa.pub) 479 | ssh -o StrictHostKeyChecking=no -l ${SSSSHUSER} ${SSSSH} "if [ -z \"\$(grep \"$KEY\" ~/.ssh/authorized_keys )\" ]; then echo $KEY >> ~/.ssh/authorized_keys; echo Public SSH key added to staging server; fi;" 480 | else 481 | ## If not create 482 | e_error "Public SSH key doesn't exist. Generating now" 483 | ssh-keygen -t rsa 484 | ##Copy key to staging server 485 | cat ~/.ssh/id_rsa.pub | ssh -o StrictHostKeyChecking=no -l ${SSSSHUSER} ${SSSSH} "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" 486 | fi 487 | 488 | ## Install virtualhost on staging Server 489 | e_warning "Check if virtualhost is installed on staging server" 490 | if ssh -t $SSSSHUSER@$SSSSH "stat /usr/local/bin/virtualhost &> /dev/null"; then 491 | e_success "Virtualhost installed on staging server" 492 | else 493 | e_error "Virtualhost not installed on staging server" 494 | e_warning "Installing virtualhost on staging server" 495 | ssh -t $SSSSHUSER@$SSSSH "cd /usr/local/bin ; wget -O virtualhost https://raw.githubusercontent.com/RoverWire/virtualhost/master/virtualhost.sh ; chmod +x virtualhost ;" 496 | fi 497 | 498 | e_warning "Setup Wordmove for staging environment" 499 | 500 | # Append Movefile with staging block 501 | 502 | cat <> movefile.yml 503 | staging: 504 | vhost: "http://$FULLDOMAIN" 505 | wordpress_path: "$SSWEBDIR/$FULLDOMAIN" # use an absolute path here 506 | 507 | database: 508 | name: "$NEWDB" 509 | user: "$SSMYSQLUSER" 510 | password: "$SSMYSQLPWD" 511 | host: "$SSMYSQLSERVER" 512 | # port: "3308" # Use just in case you have exotic server config 513 | 514 | exclude: 515 | - ".git/" 516 | - ".gitignore" 517 | - ".sass-cache/" 518 | - "bin/" 519 | - "tmp/*" 520 | - "Gemfile*" 521 | - "Movefile" 522 | - "movefile.yml" 523 | - ".DS_Store" 524 | - "wp-config.php" 525 | - "wp-content/*.sql" 526 | 527 | # paths: # you can customize wordpress internal paths 528 | # wp_content: "wp-content" 529 | # uploads: "wp-content/uploads" 530 | # plugins: "wp-content/plugins" 531 | # themes: "wp-content/themes" 532 | # languages: "wp-content/languages" 533 | # themes: "wp-content/themes" 534 | 535 | ssh: 536 | host: "$SSSSH" 537 | user: "$SSSSHUSER" 538 | # password: "password" # password is optional, will use public keys if available. 539 | # port: 22 # Port is optional 540 | rsync_options: "-og --chown=www-data:www-data --no-perms --chmod=ugo=rwX" 541 | # gateway: # Gateway is optional 542 | # host: "host" 543 | # user: "user" 544 | # password: "password" # password is optional, will use public keys if available. 545 | 546 | # ftp: 547 | # user: "user" 548 | # password: "password" 549 | # host: "host" 550 | # passive: true 551 | 552 | # production: # multiple environments can be specified 553 | # [...] 554 | EOT 555 | 556 | #Virtualhost creation for Apache on staging server 557 | e_warning "Create Remote Database and setup Virtual Hosts" 558 | ssh -t $SSSSHUSER@$SSSSH "echo 'CREATE DATABASE \`$NEWDB\`; GRANT ALL ON \`$NEWDB\`.* TO $SSMYSQLUSER@$SSMYSQLSERVER;' | /usr/bin/mysql -u$SSMYSQLUSER -p$SSMYSQLPWD ; sudo /usr/local/bin/virtualhost create $FULLDOMAIN $FULLDOMAIN ; sudo chown -R www-data:www-data $SSWEBDIR/$FULLDOMAIN ; sudo chmod -R g+w $SSWEBDIR/$FULLDOMAIN ; sudo rm $SSWEBDIR/$FULLDOMAIN/phpinfo.php ; " 559 | 560 | #Create staging wp-config.php as Wordmove doesn't sync wp-config.php 561 | e_warning "Create Staging wp-config.php" 562 | cp -n ./wp-config-sample.php ./wp-config-staging.php 563 | SECRETKEYS=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/) 564 | EXISTINGKEYS='put your unique phrase here' 565 | printf '%s\n' "g/$EXISTINGKEYS/d" a "$SECRETKEYS" . w | ed -s wp-config-staging.php 566 | DBUSER=$"username_here" 567 | DBPASS=$"password_here" 568 | DBNAME=$"database_name_here" 569 | DBSERVER=$"localhost" 570 | sed -i '' -e "s/${DBUSER}/${SSMYSQLUSER}/g" wp-config-staging.php 571 | sed -i '' -e "s/${DBPASS}/${SSMYSQLPWD}/g" wp-config-staging.php 572 | sed -i '' -e "s/${DBNAME}/${NEWDB}/g" wp-config-staging.php 573 | sed -i '' -e "s/${DBSERVER}/${SSMYSQLSERVER}/g" wp-config-staging.php 574 | rsync -og --chown=www-data:www-data --no-perms --chmod=ugo=rwX wp-config-staging.php $SSSSHUSER@$SSSSH:$SSWEBDIR/$FULLDOMAIN/wp-config.php 575 | rm wp-config-staging.php 576 | fi 577 | 578 | ## Big Production Pull Block 579 | 580 | e_warning "Note: Public key SSH access must be enabled." 581 | e_warning "WPStager will try to generate them for you, but sometimes this does not work" 582 | printf "Do you want to pull data from a production server? (y/N)" 583 | read PRODUCTION 584 | PRODUCTION=${PRODUCTION:-n} 585 | if [ "$PRODUCTION" = "y" ] || [ "$PRODUCTION" = "Y" ]; then 586 | 587 | e_warning "Make sure to include http:// OR https://" 588 | printf "What's your production domain (i.e. https://WPStager.com)?" 589 | read PFULLDOMAIN 590 | 591 | printf "\nWhere is the root directory of your production server WordPress installation? (e.g. /var/www/sitename)" 592 | read PSWEBDIR 593 | 594 | printf "Production Server MySQL Host Address (Hit enter if MySQL server runs locally on the production server): (localhost)" 595 | read PSMYSQLSERVER 596 | PSMYSQLSERVER=${PSMYSQLSERVER:-localhost} 597 | 598 | printf "Production Server MySQL Database Name: " 599 | read PSMYSQLDB 600 | 601 | printf "Production Server MySQL User: (root) " 602 | read PSMYSQLUSER 603 | PSMYSQLUSER=${PSMYSQLUSER:-root} 604 | 605 | printf "Production Server MySQL Password: " 606 | read PSMYSQLPWD 607 | 608 | printf "Production Server MySQL Port: (3306) " 609 | read PSMYSQLPORT 610 | PSMYSQLPORT=${PSMYSQLPORT:-3306} 611 | 612 | printf "Production Server SSH Host/IP Address (i.e. 1.2.3.4): " 613 | read PSSSH 614 | 615 | printf "Production Server SSH User: (root) " 616 | read PSSSHUSER 617 | PSSSHUSER=${PSSSHUSER:-root} 618 | 619 | printf "Production Server SSH Port: (22) " 620 | read PSSSHPORT 621 | PSSSHPORT=${PSSSHPORT:-22} 622 | 623 | ## Setup Public Keys 624 | ## Check if local ssh keys exist 625 | e_warning "Check if public SSH key exists" 626 | if [ -f ~/.ssh/id_rsa.pub ]; then 627 | e_success "Public SSH key exists" 628 | ## If it exists check if its added on server. If not add it. 629 | KEY=$(cat ~/.ssh/id_rsa.pub) 630 | ssh -o StrictHostKeyChecking=no -l ${PSSSHUSER} ${PSSSH} "if [ -z \"\$(grep \"$KEY\" ~/.ssh/authorized_keys )\" ]; then echo $KEY >> ~/.ssh/authorized_keys; echo Public SSH key added to staging server; fi;" 631 | else 632 | ## If not create 633 | e_error "Public SSH key doesn't exist. Generating now" 634 | ssh-keygen -t rsa 635 | ##Copy key to production server 636 | cat ~/.ssh/id_rsa.pub | ssh -o StrictHostKeyChecking=no -l ${PSSSHUSER} ${PSSSH} "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" 637 | fi 638 | 639 | e_warning "Setup Wordmove for production environment" 640 | 641 | # Append Movefile with production block 642 | 643 | cat <> movefile.yml 644 | production: 645 | vhost: "$PFULLDOMAIN" 646 | wordpress_path: "$PSWEBDIR" # use an absolute path here 647 | 648 | database: 649 | name: "$PSMYSQLDB" 650 | user: "$PSMYSQLUSER" 651 | password: "$PSMYSQLPWD" 652 | host: "$PSMYSQLSERVER" 653 | port: "$PSMYSQLPORT" 654 | 655 | exclude: 656 | - ".git/" 657 | - ".gitignore" 658 | - ".sass-cache/" 659 | - "bin/" 660 | - "tmp/*" 661 | - "Gemfile*" 662 | - "Movefile" 663 | - "movefile.yml" 664 | - ".DS_Store" 665 | - "wp-config.php" 666 | - "wp-content/*.sql" 667 | 668 | # paths: # you can customize wordpress internal paths 669 | # wp_content: "wp-content" 670 | # uploads: "wp-content/uploads" 671 | # plugins: "wp-content/plugins" 672 | # themes: "wp-content/themes" 673 | # languages: "wp-content/languages" 674 | # themes: "wp-content/themes" 675 | 676 | ssh: 677 | host: "$PSSSH" 678 | user: "$PSSSHUSER" 679 | # password: "password" # password is optional, will use public keys if available. 680 | port: $PSSSHPORT # Port is optional 681 | # rsync_options: "-og --chown=www-data:www-data --no-perms --chmod=ugo=rwX" 682 | # gateway: # Gateway is optional 683 | # host: "host" 684 | # user: "user" 685 | # password: "password" # password is optional, will use public keys if available. 686 | 687 | # ftp: 688 | # user: "user" 689 | # password: "password" 690 | # host: "host" 691 | # passive: true 692 | 693 | # production2: # multiple environments can be specified 694 | # [...] 695 | EOT 696 | 697 | fi 698 | 699 | # Create the local wp-config.php in case it doesn't exist yet (which it never should) 700 | if [ -f ./wp-config.php ]; then 701 | open http://"$LOCALDOMAIN"/wp-admin/install.php 702 | else 703 | cp -n ./wp-config-sample.php ./wp-config.php 704 | SECRETKEYS=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/) 705 | EXISTINGKEYS='put your unique phrase here' 706 | printf '%s\n' "g/$EXISTINGKEYS/d" a "$SECRETKEYS" . w | ed -s wp-config.php 707 | DBUSER=$"username_here" 708 | DBPASS=$"password_here" 709 | DBNAME=$"database_name_here" 710 | sed -i '' -e "s/${DBUSER}/${MYSQLUSER}/g" wp-config.php 711 | sed -i '' -e "s/${DBPASS}/${MYSQLPWD}/g" wp-config.php 712 | sed -i '' -e "s/${DBNAME}/${NEWDB}/g" wp-config.php 713 | open http://"$LOCALDOMAIN"/wp-admin/install.php 714 | fi 715 | 716 | if [ "$STAGING" = "y" ] || [ "$STAGING" = "Y" ] || [ "$PRODUCTION" = "y" ] || [ "$PRODUCTION" = "Y" ]; then 717 | clear 718 | e_bold "All done! Now finish your local WordPress installation in the browser (http://$LOCALDOMAIN/wp-admin/install.php)!" 719 | echo 720 | e_bold "After that you can invoke your first Staging, or Production sync! To do so use the following commands from the command line:" 721 | echo 722 | e_bold "For Staging" 723 | e_warning "cd /Applications/MAMP/htdocs/$LOCALDOMAIN" 724 | e_warning "wordmove push --all -e staging" 725 | e_bold "Your new staging site can be accessed at http://$FULLDOMAIN after the first sync." 726 | e_underline "Keep in mind that you need to manually change your DNS server setting when not using the CloudFlare feature!" 727 | echo 728 | e_bold "For Production" 729 | e_warning "wordmove pull --all -e production" 730 | e_underline "This will make an exact copy of your production site in your local dev environment!" 731 | echo 732 | e_note "For more information on how to use Wordmove make sure to visit https://github.com/welaika/wordmove" 733 | else 734 | clear 735 | e_success "All done! Now finish your local WordPress installation in the browser (http://$LOCALDOMAIN/wp-admin/install.php)!" 736 | e_note "For more information on how to use Wordmove make sure to visit https://github.com/welaika/wordmove" 737 | fi 738 | # 739 | # Livereload app seems to have bugs. Can't get it started from bash... 740 | # 741 | # open "livereload:add?path=/Applications/MAMP/htdocs/$LOCALDOMAIN/wp-content" 742 | --------------------------------------------------------------------------------