diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..e96e64a99 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at vvv@tomjn.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 000000000..750464d4d --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,67 @@ +# Configuration for update-docs - https://github.com/behaviorbot/update-docs + +# Comment to be posted to on PRs that don't update documentation +updateDocsComment: > + Thanks for opening this pull request! Make sure `CHANGELOG.md` gets updated with this change, additionally any docs that need updated can be found at https://github.com/Varying-Vagrant-Vagrants/varyingvagrantvagrants.org + +targetFiles: + - CHANGELOG.md + +# Comment to be posted to on first time issues +newIssueWelcomeComment: > + Thanks for opening your first issue here! Be sure to follow the issue template and include your OS/Vagrant/VVV versions! Don't forget you can get support in the VVV slack at https://varyingvagrantvagrants.org/docs/en-US/slack/ + +# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome + +# Comment to be posted to on PRs from first time contributors in your repository +newPRWelcomeComment: false + +# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge + +# Comment to be posted to on pull requests merged by a first time user +firstPRMergeComment: > + Congrats on merging your first pull request! + + +# Configuration for request-info - https://github.com/behaviorbot/request-info + +# *OPTIONAL* Comment to reply with +# Can be either a string : +requestInfoReplyComment: > + Thanks for contributing, it would be a help if you can provide us with more info! + +# Or an array: +# requestInfoReplyComment: +# - Ah no! young blade! That was a trifle short! +# - Tell me more ! +# - I am sure you can be more effusive + + +# *OPTIONAL* default titles to check against for lack of descriptiveness +# MUST BE ALL LOWERCASE +requestInfoDefaultTitles: + - update readme.md + - updates + +# *OPTIONAL* Label to be added to Issues and Pull Requests with insufficient information given +requestInfoLabelToAdd: needs-more-info + +# *OPTIONAL* Require Issues to contain more information than what is provided in the issue templates +# Will fail if the issue's body is equal to a provided template +checkIssueTemplate: true + +# *OPTIONAL* Require Pull Requests to contain more information than what is provided in the PR template +# Will fail if the pull request's body is equal to the provided template +checkPullRequestTemplate: true + +# *OPTIONAL* Only warn about insufficient information on these events type +# Keys must be lowercase. Valid values are 'issue' and 'pullRequest' +requestInfoOn: + pullRequest: true + issue: true + +# *OPTIONAL* Add a list of people whose Issues/PRs will not be commented on +# keys must be GitHub usernames +requestInfoUserstoExclude: + - hiimbex + - bexo diff --git a/.github/lock.yml b/.github/lock.yml new file mode 100644 index 000000000..f9e7e29c3 --- /dev/null +++ b/.github/lock.yml @@ -0,0 +1,38 @@ +# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app + +# Number of days of inactivity before a closed issue or pull request is locked +daysUntilLock: 20 + +# Skip issues and pull requests created before a given timestamp. Timestamp must +# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable +skipCreatedBefore: false + +# Issues and pull requests with these labels will be ignored. Set to `[]` to disable +exemptLabels: [] + +# Label to add before locking, such as `outdated`. Set to `false` to disable +lockLabel: false + +# Comment to post before locking. Set to `false` to disable +lockComment: > + This thread has been automatically locked since there has not been + any recent activity after it was closed. Please open a new issue for + related bugs. + +# Assign `resolved` as the reason for locking. Set to `false` to disable +setLockReason: false + +# Limit to only `issues` or `pulls` +only: issues + +# Optionally, specify configuration settings just for `issues` or `pulls` +# issues: +# exemptLabels: +# - help-wanted +# lockLabel: outdated + +# pulls: +# daysUntilLock: 30 + +# Repository to extend settings from +# _extends: repo diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b64cc97..a24c5af8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,40 @@ permalink: /docs/en-US/changelog/ # Changelog -## 3.3.0 ( WIP ) +## 3.4.1 ( 2020 June 4th ) + +### Enhancements + +* Improved the log folder names from `20200225-182126` to `2020.02.25-18-21-26` ( #2078 ) +* Added a `switch_php_debugmod` to replace the `xdebug_on` `tideways_off` style scripts ( #2084 ) +* Checks the default password for MySQL root user during provision ( #2077, #2085 ) +* Remove NVM support entirely ( #2088 ) +* Improved the provider examples in `default-config.yml` ( #2091 ) +* Run rubocop on Vagrantfile in a move towards more idiomatic ruby ( #2093 ) +* Improved network checks to test more domains ( #2099 ) +* ack-grep is now installed via `apt` rather than `beyondgrep.com` ( #2100 ) +* Refactor site provisioners ( #2102 ) +* Added new bears to the various vagrant trigger scripts ( #2105, #2108 ) +* Removed Ubuntu news MOTD ( #2105 ) +* Improve network checks wording ( #2106 ) +* Support for vagrant-hostmanager ( #2112 ) +* Bumped MariaDB sources from 10.3 to 10.4 ( #2140 ) +* Improve compatibility with globally installed gems on the guest ( #2138 ) +* Add LFTP tool ( #2137 ) +* List relevant log files when provisioners fail ( #2161 ) + +### Bug Fixes + +* Fix check for utility installed that prevented SSL certificates to be generated ( #2073 ) +* Fix SSL issue on the base Ubuntu image ( #2074 ) +* Don't spider and recurse domains when checking for network connections ( #2103 ) +* Always set the database root user password to avoid having the default invalid password on fresh installs ( #2104 ) +* Swap the MariaDB apt mirror used for a more reliable source ( partially #2140 and in a217369 ) +* Fixed an issue with the dpkg lock file not being cleaned up sometimes ( #2151 ) +* Fix issues with the sad bear showing at the end of provisioning despite provisioners being succesful ( #2161 ) +* Fix provisioners printing all output to console (not just errors) ( #2174 ) + +## 3.3.0 ( 2020 Feb 26th ) ### Enhancements @@ -18,7 +51,7 @@ permalink: /docs/en-US/changelog/ * Fixes an issue with the ntpsec package by removing it * Fixed the use of dots in site names breaking provisioning -## 3.2.0 ( 2019 ) +## 3.2.0 ( 2019 Nov 5th ) ### Enhancements @@ -68,7 +101,7 @@ This is primarily a reliability update. Note that updating to v3.1 requires a `v ### Enhancements -* The vagrant box can now be overriden using the `box` parameter in `vvv-custom.yml` under the `vm_config` section. This requires a `vagrant destroy` followed by a `vagrant up --provision` to recreate the VM using the new box +* The vagrant box can now be overridden using the `box` parameter in `vvv-custom.yml` under the `vm_config` section. This requires a `vagrant destroy` followed by a `vagrant up --provision` to recreate the VM using the new box * The main provisioner now only fetches the apt keys once rather than on every key check * The TTY fix shell provisioner and the `/vagrant` setup shell provisioner were merged for a minor reduction in provisioning time. * Allow `db_backup` script to be run manually regardless if automatic DB backups are disabled @@ -138,7 +171,7 @@ In the near future, we expect to use a box with PHP/etc preinstalled, this will * Auto download plugin for vagrant, supported vagrant 2.2.0+ * Autoset the locale inside the virtual machine to avoid errors in the console * Added a `vagrant_provision` and `vagrant_provision_custom` script to the homebin folder that run post-provision -* Improved the messaging to tell the user at the end of a `vagrant up` or `vagrant provision` that it was succesful +* Improved the messaging to tell the user at the end of a `vagrant up` or `vagrant provision` that it was successful * Added friendly splashes at the end of vagrant up and provision to make it obvious to end users when they've finished * The VVV install path is now in the splash screen, making it easier to debug GH issues * Added a `wordcamp_contributor_day_box` flag to the `vm_config` section of `vvv-config.yml` so that contributor day setup scripts are simpler @@ -227,7 +260,7 @@ Note that to update to 2.2.1, you must remove the Vagrant triggers plugin and in * PHP 7.2 is now the default PHP version * Added the TLS CA authority, making HTTPS TLS/SSL connections to VVV sites easier, see [our docs on how to set this up](https://varyingvagrantvagrants.org/docs/en-US/references/https/) * The VVV terminal splash is now smaller, with better support for lighter colour schemes. -* The dashboard is now a separate git repo cloned on provision, that can be overriden in `vvv-custom.yml` +* The dashboard is now a separate git repo cloned on provision, that can be overridden in `vvv-custom.yml` * PHPCompatibility PHPCS standards are now installed * VVV now has a `version` file * Private network IP can now be changed via `vvv-custom.yml`, see [#1407](https://github.com/Varying-Vagrant-Vagrants/VVV/pull/1407) diff --git a/README.md b/README.md index e1ee364bc..ffa3b03a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # VVV ( Varying Vagrant Vagrants ) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/206b06167aaf48aab24422cd417e8afa)](https://www.codacy.com/gh/Varying-Vagrant-Vagrants/VVV?utm_source=github.com&utm_medium=referral&utm_content=Varying-Vagrant-Vagrants/VVV&utm_campaign=Badge_Grade) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/206b06167aaf48aab24422cd417e8afa)](https://www.codacy.com/gh/Varying-Vagrant-Vagrants/VVV?utm_source=github.com&utm_medium=referral&utm_content=Varying-Vagrant-Vagrants/VVV&utm_campaign=Badge_Grade) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/varying-vagrant-vagrants/vvv.svg)](http://isitmaintained.com/project/varying-vagrant-vagrants/vvv "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/varying-vagrant-vagrants/vvv.svg)](http://isitmaintained.com/project/varying-vagrant-vagrants/vvv "Percentage of issues still open") VVV is a local developer environment, mainly aimed at [WordPress](https://wordpress.org) developers. It uses [Vagrant](https://www.vagrantup.com) and VirtualBox, and can be used to build sites, and contribute to WordPress. @@ -22,8 +22,8 @@ The online documentation contains more detailed [installation instructions](http ## Minimum System requirements -* [Vagrant](https://www.vagrantup.com) 2.2.6 or below. -* [Virtualbox](https://www.virtualbox.org) 6.0.x or below. +* [Vagrant](https://www.vagrantup.com) 2.2.7 or below. +* [Virtualbox](https://www.virtualbox.org) 6.1.x or below. * 8GB+ of RAM * Virtualisation ( VT-X ) enabled in the BIOS ( Windows/Linux ) * Hyper-V turned off ( Windows ) diff --git a/Vagrantfile b/Vagrantfile index c6ba971e1..1c41eaf5a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,124 +1,123 @@ +# frozen_string_literal: true + # -*- mode: ruby -*- # vi: set ft=ruby ts=2 sw=2 et: -Vagrant.require_version ">= 2.2.4" +Vagrant.require_version '>= 2.2.4' require 'yaml' require 'fileutils' -def virtualbox_path() - @vboxmanage_path = nil - if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.cygwin? - @vboxmanage_path = Vagrant::Util::Which.which("VBoxManage") - - # On Windows, we use the VBOX_INSTALL_PATH environmental - # variable to find VBoxManage. - if !@vboxmanage_path && (ENV.key?("VBOX_INSTALL_PATH") || - ENV.key?("VBOX_MSI_INSTALL_PATH")) - - # Get the path. - path = ENV["VBOX_INSTALL_PATH"] || ENV["VBOX_MSI_INSTALL_PATH"] - - # There can actually be multiple paths in here, so we need to - # split by the separator ";" and see which is a good one. - path.split(";").each do |single| - # Make sure it ends with a \ - single += "\\" unless single.end_with?("\\") - - # If the executable exists, then set it as the main path - # and break out - vboxmanage = "#{single}VBoxManage.exe" - if File.file?(vboxmanage) - @vboxmanage_path = Vagrant::Util::Platform.cygwin_windows_path(vboxmanage) - break - end - end +def virtualbox_path + @vboxmanage_path = nil + if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.cygwin? + @vboxmanage_path = Vagrant::Util::Which.which('VBoxManage') + + # On Windows, we use the VBOX_INSTALL_PATH environmental + # variable to find VBoxManage. + if !@vboxmanage_path && (ENV.key?('VBOX_INSTALL_PATH') || + ENV.key?('VBOX_MSI_INSTALL_PATH')) + + # Get the path. + path = ENV['VBOX_INSTALL_PATH'] || ENV['VBOX_MSI_INSTALL_PATH'] + + # There can actually be multiple paths in here, so we need to + # split by the separator ";" and see which is a good one. + path.split(';').each do |single| + # Make sure it ends with a \ + single += '\\' unless single.end_with?('\\') + + # If the executable exists, then set it as the main path + # and break out + vboxmanage = "#{single}VBoxManage.exe" + if File.file?(vboxmanage) + @vboxmanage_path = Vagrant::Util::Platform.cygwin_windows_path(vboxmanage) + break end + end + end - # If we still don't have one, try to find it using common locations - drive = ENV["SYSTEMDRIVE"] || "C:" - [ - "#{drive}/Program Files/Oracle/VirtualBox", - "#{drive}/Program Files (x86)/Oracle/VirtualBox", - "#{ENV["PROGRAMFILES"]}/Oracle/VirtualBox" - ].each do |maybe| - path = File.join(maybe, "VBoxManage.exe") - if File.file?(path) - @vboxmanage_path = path - break - end - end - elsif Vagrant::Util::Platform.wsl? - unless Vagrant::Util::Platform.wsl_windows_access? - raise Vagrant::Errors::WSLVirtualBoxWindowsAccessError - end - @vboxmanage_path = Vagrant::Util::Which.which("VBoxManage") || Vagrant::Util::Which.which("VBoxManage.exe") - unless @vboxmanage_path - # If we still don't have one, try to find it using common locations - drive = "/mnt/c" - [ - "#{drive}/Program Files/Oracle/VirtualBox", - "#{drive}/Program Files (x86)/Oracle/VirtualBox" - ].each do |maybe| - path = File.join(maybe, "VBoxManage.exe") - if File.file?(path) - @vboxmanage_path = path - break - end - end + # If we still don't have one, try to find it using common locations + drive = ENV['SYSTEMDRIVE'] || 'C:' + [ + "#{drive}/Program Files/Oracle/VirtualBox", + "#{drive}/Program Files (x86)/Oracle/VirtualBox", + "#{ENV['PROGRAMFILES']}/Oracle/VirtualBox" + ].each do |maybe| + path = File.join(maybe, 'VBoxManage.exe') + if File.file?(path) + @vboxmanage_path = path + break + end + end + elsif Vagrant::Util::Platform.wsl? + unless Vagrant::Util::Platform.wsl_windows_access? + raise Vagrant::Errors::WSLVirtualBoxWindowsAccessError + end + + @vboxmanage_path = Vagrant::Util::Which.which('VBoxManage') || Vagrant::Util::Which.which('VBoxManage.exe') + unless @vboxmanage_path + # If we still don't have one, try to find it using common locations + drive = '/mnt/c' + [ + "#{drive}/Program Files/Oracle/VirtualBox", + "#{drive}/Program Files (x86)/Oracle/VirtualBox" + ].each do |maybe| + path = File.join(maybe, 'VBoxManage.exe') + if File.file?(path) + @vboxmanage_path = path + break end + end end + end - # Fall back to hoping for the PATH to work out - @vboxmanage_path ||= "VBoxManage" - return @vboxmanage_path + # Fall back to hoping for the PATH to work out + @vboxmanage_path ||= 'VBoxManage' + @vboxmanage_path end -def get_virtualbox_version() - vboxmanage = virtualbox_path() - s = Vagrant::Util::Subprocess.execute(vboxmanage, '--version') - return s.stdout.strip! +def get_virtualbox_version + vboxmanage = virtualbox_path + s = Vagrant::Util::Subprocess.execute(vboxmanage, '--version') + s.stdout.strip! end -vagrant_dir = File.expand_path(File.dirname(__FILE__)) +vagrant_dir = __dir__ show_logo = false -branch_c = "\033[38;5;6m"#111m" -red="\033[38;5;9m"#124m" -green="\033[1;38;5;2m"#22m" -blue="\033[38;5;4m"#33m" -purple="\033[38;5;5m"#129m" -docs="\033[0m" -yellow="\033[38;5;3m"#136m" -yellow_underlined="\033[4;38;5;3m"#136m" -url=yellow_underlined -creset="\033[0m" - -version = "?" -File.open("#{vagrant_dir}/version", "r") do |f| +branch_c = "\033[38;5;6m" # 111m" +red = "\033[38;5;9m" # 124m" +green = "\033[1;38;5;2m" # 22m" +blue = "\033[38;5;4m" # 33m" +purple = "\033[38;5;5m" # 129m" +docs = "\033[0m" +yellow = "\033[38;5;3m" # 136m" +yellow_underlined = "\033[4;38;5;3m" # 136m" +url = yellow_underlined +creset = "\033[0m" + +version = '?' +File.open("#{vagrant_dir}/version", 'r') do |f| version = f.read - version = version.gsub("\n",'') + version = version.gsub("\n", '') end # whitelist when we show the logo, else it'll show on global Vagrant commands -if [ 'up', 'resume', 'status', 'provision', 'reload' ].include? ARGV[0] - show_logo = true -end -if ENV['VVV_SKIP_LOGO'] - show_logo = false -end +show_logo = true if %w[up resume status provision reload].include? ARGV[0] +show_logo = false if ENV['VVV_SKIP_LOGO'] # Show the initial splash screen if show_logo - git_or_zip = "zip-no-vcs" + git_or_zip = 'zip-no-vcs' branch = '' if File.directory?("#{vagrant_dir}/.git") - git_or_zip = "git::" + git_or_zip = 'git::' branch = `git --git-dir="#{vagrant_dir}/.git" --work-tree="#{vagrant_dir}" rev-parse --abbrev-ref HEAD` - branch = branch.chomp("\n"); # remove trailing newline so it doesnt break the ascii art + branch = branch.chomp("\n"); # remove trailing newline so it doesn't break the ascii art end - splashfirst = <<-HEREDOC -\033[1;38;5;196m#{red}__ #{green}__ #{blue}__ __ -#{red}\\ V#{green}\\ V#{blue}\\ V / #{red}Varying #{green}Vagrant #{blue}Vagrants -#{red} \\_/#{green}\\_/#{blue}\\_/ #{purple}v#{version}#{creset}-#{branch_c}#{git_or_zip}#{branch}#{creset} + splashfirst = <<~HEREDOC + \033[1;38;5;196m#{red}__ #{green}__ #{blue}__ __ + #{red}\\ V#{green}\\ V#{blue}\\ V / #{red}Varying #{green}Vagrant #{blue}Vagrants + #{red} \\_/#{green}\\_/#{blue}\\_/ #{purple}v#{version}#{creset}-#{branch_c}#{git_or_zip}#{branch}#{creset} HEREDOC puts splashfirst @@ -128,58 +127,53 @@ end # Perform file migrations from older versions vvv_config_file = File.join(vagrant_dir, 'config/config.yml') -unless File.file?( vvv_config_file ) +unless File.file?(vvv_config_file) old_vvv_config = File.join(vagrant_dir, 'vvv-custom.yml') - if File.file?( old_vvv_config ) + if File.file?(old_vvv_config) puts "#{yellow}Migrating #{red}vvv-custom.yml#{yellow} to #{green}config/config.yml#{yellow}\nIMPORTANT NOTE: Make all modifications to #{green}config/config.yml#{yellow}.#{creset}\n\n" - FileUtils.mv( old_vvv_config, vvv_config_file ) + FileUtils.mv(old_vvv_config, vvv_config_file) else puts "#{yellow}Copying #{red}config/default-config.yml#{yellow} to #{green}config/config.yml#{yellow}\nIMPORTANT NOTE: Make all modifications to #{green}config/config.yml#{yellow} in future so that they are not lost when VVV updates.#{creset}\n\n" - FileUtils.cp( File.join(vagrant_dir, 'config/default-config.yml'), vvv_config_file ) + FileUtils.cp(File.join(vagrant_dir, 'config/default-config.yml'), vvv_config_file) end end -old_db_backup_dir = File.join(vagrant_dir, 'database/backups/' ) -new_db_backup_dir = File.join(vagrant_dir, 'database/sql/backups/' ) -if ( File.directory?( old_db_backup_dir ) == true ) && ( File.directory?( new_db_backup_dir ) == false ) - puts "Moving db backup directory into database/sql/backups" - FileUtils.mv( old_db_backup_dir, new_db_backup_dir ) +old_db_backup_dir = File.join(vagrant_dir, 'database/backups/') +new_db_backup_dir = File.join(vagrant_dir, 'database/sql/backups/') +if (File.directory?(old_db_backup_dir) == true) && (File.directory?(new_db_backup_dir) == false) + puts 'Moving db backup directory into database/sql/backups' + FileUtils.mv(old_db_backup_dir, new_db_backup_dir) end begin vvv_config = YAML.load_file(vvv_config_file) - unless vvv_config['sites'].kind_of? Hash - vvv_config['sites'] = Hash.new + unless vvv_config['sites'].is_a? Hash + vvv_config['sites'] = {} puts "#{red}config/config.yml is missing a sites section.#{creset}\n\n" end - rescue StandardError => e puts "#{red}config/config.yml isn't a valid YAML file.#{creset}\n\n" puts "#{red}VVV cannot be executed!#{creset}\n\n" - STDERR.puts e.message + warn e.message exit end -unless vvv_config['hosts'].kind_of? Hash - vvv_config['hosts'] = Array.new -end +vvv_config['hosts'] = [] unless vvv_config['hosts'].is_a? Hash vvv_config['hosts'] += ['vvv.test'] vvv_config['sites'].each do |site, args| - if args.kind_of? String - repo = args - args = Hash.new - args['repo'] = repo + if args.is_a? String + repo = args + args = {} + args['repo'] = repo end - unless args.kind_of? Hash - args = Hash.new - end + args = {} unless args.is_a? Hash - defaults = Hash.new + defaults = {} defaults['repo'] = false defaults['vm_dir'] = "/srv/www/#{site}" defaults['local_dir'] = File.join(vagrant_dir, 'www', site) @@ -187,12 +181,12 @@ vvv_config['sites'].each do |site, args| defaults['skip_provisioning'] = false defaults['allow_customfile'] = false defaults['nginx_upstream'] = 'php' - defaults['hosts'] = Array.new + defaults['hosts'] = [] vvv_config['sites'][site] = defaults.merge(args) unless vvv_config['sites'][site]['skip_provisioning'] - site_host_paths = Dir.glob(Array.new(4) {|i| vvv_config['sites'][site]['local_dir'] + '/*'*(i+1) + '/vvv-hosts'}) + site_host_paths = Dir.glob(Array.new(4) { |i| vvv_config['sites'][site]['local_dir'] + '/*' * (i + 1) + '/vvv-hosts' }) vvv_config['sites'][site]['hosts'] += site_host_paths.map do |path| lines = File.readlines(path).map(&:chomp) lines.grep(/\A[^#]/) @@ -203,48 +197,40 @@ vvv_config['sites'].each do |site, args| vvv_config['sites'][site].delete('hosts') end -unless vvv_config['utility-sources'].kind_of? Hash - vvv_config['utility-sources'] = Hash.new -else +if vvv_config['utility-sources'].is_a? Hash vvv_config['utility-sources'].each do |name, args| - if args.kind_of? String - repo = args - args = Hash.new - args['repo'] = repo - args['branch'] = 'master' + next unless args.is_a? String - vvv_config['utility-sources'][name] = args - end + repo = args + args = {} + args['repo'] = repo + args['branch'] = 'master' + + vvv_config['utility-sources'][name] = args end +else + vvv_config['utility-sources'] = {} end -unless vvv_config['dashboard'] - vvv_config['dashboard'] = Hash.new -end -dashboard_defaults = Hash.new +vvv_config['dashboard'] = {} unless vvv_config['dashboard'] +dashboard_defaults = {} dashboard_defaults['repo'] = 'https://github.com/Varying-Vagrant-Vagrants/dashboard.git' dashboard_defaults['branch'] = 'master' vvv_config['dashboard'] = dashboard_defaults.merge(vvv_config['dashboard']) unless vvv_config['utility-sources'].key?('core') - vvv_config['utility-sources']['core'] = Hash.new + vvv_config['utility-sources']['core'] = {} vvv_config['utility-sources']['core']['repo'] = 'https://github.com/Varying-Vagrant-Vagrants/vvv-utilities.git' vvv_config['utility-sources']['core']['branch'] = 'master' end -unless vvv_config['utilities'].kind_of? Hash - vvv_config['utilities'] = Hash.new -end +vvv_config['utilities'] = {} unless vvv_config['utilities'].is_a? Hash -unless vvv_config['vm_config'].kind_of? Hash - vvv_config['vm_config'] = Hash.new -end +vvv_config['vm_config'] = {} unless vvv_config['vm_config'].is_a? Hash -unless vvv_config['general'].kind_of? Hash - vvv_config['general'] = Hash.new -end +vvv_config['general'] = {} unless vvv_config['general'].is_a? Hash -defaults = Hash.new +defaults = {} defaults['memory'] = 2048 defaults['cores'] = 1 defaults['provider'] = 'virtualbox' @@ -254,9 +240,7 @@ defaults['private_network_ip'] = '192.168.50.4' vvv_config['vm_config'] = defaults.merge(vvv_config['vm_config']) vvv_config['hosts'] = vvv_config['hosts'].uniq -unless vvv_config['vagrant-plugins'] - vvv_config['vagrant-plugins'] = Hash.new -end +vvv_config['vagrant-plugins'] = {} unless vvv_config['vagrant-plugins'] # Create a global variable to use in functions and classes $vvv_config = vvv_config @@ -264,92 +248,68 @@ $vvv_config = vvv_config # Show the second splash screen section if show_logo - platform = 'platform-' + Vagrant::Util::Platform.platform + ' ' + platform = ['platform-' + Vagrant::Util::Platform.platform] if Vagrant::Util::Platform.windows? - platform = platform + 'windows ' - if Vagrant::Util::Platform.wsl? - platform = platform + 'wsl ' - end - if Vagrant::Util::Platform.msys? - platform = platform + 'msys ' - end - if Vagrant::Util::Platform.cygwin? - platform = platform + 'cygwin ' - end + platform << 'windows ' + platform << 'wsl ' if Vagrant::Util::Platform.wsl? + platform << 'msys ' if Vagrant::Util::Platform.msys? + platform << 'cygwin ' if Vagrant::Util::Platform.cygwin? if Vagrant::Util::Platform.windows_hyperv_enabled? - platform = platform + 'HyperV-Enabled ' - end - if Vagrant::Util::Platform.windows_hyperv_admin? - platform = platform + 'HyperV-Admin ' - end - if Vagrant::Util::Platform.windows_admin? - platform = platform + 'HasWinAdminPriv ' + platform << 'HyperV-Enabled ' end + platform << 'HyperV-Admin ' if Vagrant::Util::Platform.windows_hyperv_admin? + platform << 'HasWinAdminPriv ' if Vagrant::Util::Platform.windows_admin? else - - if ENV['SHELL'] - platform = platform + "shell:" + ENV['SHELL'] + ' ' - end - if Vagrant::Util::Platform.systemd? - platform = platform + 'systemd ' - end - end - - if Vagrant.has_plugin?('vagrant-hostsupdater') - platform = platform + 'vagrant-hostsupdater ' - end - - if Vagrant.has_plugin?('vagrant-vbguest') - platform = platform + 'vagrant-vbguest ' + platform << 'shell:' + ENV['SHELL'] if ENV['SHELL'] + platform << 'systemd ' if Vagrant::Util::Platform.systemd? end - if Vagrant.has_plugin?('vagrant-disksize') - platform = platform + 'vagrant-disksize ' - end + platform << 'vagrant-hostmanager' if Vagrant.has_plugin?('vagrant-hostmanager') + platform << 'vagrant-hostsupdater' if Vagrant.has_plugin?('vagrant-hostsupdater') + platform << 'vagrant-vbguest' if Vagrant.has_plugin?('vagrant-vbguest') + platform << 'vagrant-disksize' if Vagrant.has_plugin?('vagrant-disksize') - if Vagrant::Util::Platform.fs_case_sensitive? - platform = platform + 'CaseSensitiveFS ' - end + platform << 'CaseSensitiveFS' if Vagrant::Util::Platform.fs_case_sensitive? unless Vagrant::Util::Platform.terminal_supports_colors? - platform = platform + 'NoColour ' + platform << 'NoColour' end if defined? vvv_config['vm_config']['wordcamp_contributor_day_box'] if vvv_config['vm_config']['wordcamp_contributor_day_box'] == true - platform = platform + 'contributor_day_box ' + platform << 'contributor_day_box' end end if defined? vvv_config['vm_config']['box'] unless vvv_config['vm_config']['box'].nil? - puts "Custom Box: Box overriden via config/config.yml , this won't take effect until a destroy + reprovision happens" - platform = platform + 'box_override:' + vvv_config['vm_config']['box'] + ' ' + puts "Custom Box: Box overridden via config/config.yml , this won't take effect until a destroy + reprovision happens" + platform << 'box_override:' + vvv_config['vm_config']['box'] end end if defined? vvv_config['general']['db_share_type'] if vvv_config['general']['db_share_type'] != true - platform = platform + 'shared_db_folder_disabled ' + platform << 'shared_db_folder_disabled' else - platform = platform + 'shared_db_folder_enabled ' + platform << 'shared_db_folder_enabled' end else - platform = platform + 'shared_db_folder_default ' + platform << 'shared_db_folder_default' end - virtualbox_version = "N/A" + virtualbox_version = 'N/A' - unless vvv_config['vm_config']['provider'] != 'virtualbox' - virtualbox_version = get_virtualbox_version() + if vvv_config['vm_config']['provider'] == 'virtualbox' + virtualbox_version = get_virtualbox_version end -splashsecond = <<-HEREDOC -#{yellow}Platform: #{yellow}#{platform}, #{purple}VVV Path: "#{vagrant_dir}" -#{green}Vagrant: #{green}v#{Vagrant::VERSION}, #{blue}VirtualBox: #{blue}v#{virtualbox_version} + splashsecond = <<~HEREDOC + #{yellow}Platform: #{yellow}#{platform.join(' ')}, #{purple}VVV Path: "#{vagrant_dir}" + #{green}Vagrant: #{green}v#{Vagrant::VERSION}, #{blue}VirtualBox: #{blue}v#{virtualbox_version} -#{docs}Docs: #{url}https://varyingvagrantvagrants.org/ -#{docs}Contribute: #{url}https://github.com/varying-vagrant-vagrants/vvv -#{docs}Dashboard: #{url}http://vvv.test#{creset} + #{docs}Docs: #{url}https://varyingvagrantvagrants.org/ + #{docs}Contribute: #{url}https://github.com/varying-vagrant-vagrants/vvv + #{docs}Dashboard: #{url}http://vvv.test#{creset} HEREDOC puts splashsecond @@ -360,12 +320,9 @@ if defined? vvv_config['vm_config']['provider'] ENV['VAGRANT_DEFAULT_PROVIDER'] = vvv_config['vm_config']['provider'] end +ENV['LC_ALL'] = 'en_US.UTF-8' - -ENV["LC_ALL"] = "en_US.UTF-8" - -Vagrant.configure("2") do |config| - +Vagrant.configure('2') do |config| # Store the current version of Vagrant for use in conditionals when dealing # with possible backward compatible issues. vagrant_version = Vagrant::VERSION.sub(/^v/, '') @@ -373,38 +330,38 @@ Vagrant.configure("2") do |config| # Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following. config.vm.provider :virtualbox do |v| # Move the ubuntu-bionic-18.04-cloudimg-console.log file to log directory. - v.customize ["modifyvm", :id, "--uartmode1", "file", File.join(vagrant_dir, "log/ubuntu-bionic-18.04-cloudimg-console.log")] + v.customize ['modifyvm', :id, '--uartmode1', 'file', File.join(vagrant_dir, 'log/ubuntu-bionic-18.04-cloudimg-console.log')] - v.customize ["modifyvm", :id, "--memory", vvv_config['vm_config']['memory']] - v.customize ["modifyvm", :id, "--cpus", vvv_config['vm_config']['cores']] - v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] - v.customize ["modifyvm", :id, "--natdnsproxy1", "on"] + v.customize ['modifyvm', :id, '--memory', vvv_config['vm_config']['memory']] + v.customize ['modifyvm', :id, '--cpus', vvv_config['vm_config']['cores']] + v.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] + v.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] # see https://github.com/hashicorp/vagrant/issues/7648 v.customize ['modifyvm', :id, '--cableconnected1', 'on'] - v.customize ["modifyvm", :id, "--rtcuseutc", "on"] - v.customize ["modifyvm", :id, "--audio", "none"] - v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"] - v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//srv/www", "1"] - v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//srv/config", "1"] + v.customize ['modifyvm', :id, '--rtcuseutc', 'on'] + v.customize ['modifyvm', :id, '--audio', 'none'] + v.customize ['modifyvm', :id, '--paravirtprovider', 'kvm'] + v.customize ['setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate//srv/www', '1'] + v.customize ['setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate//srv/config', '1'] # Set the box name in VirtualBox to match the working directory. - v.name = File.basename(vagrant_dir) + "_" + (Digest::SHA256.hexdigest vagrant_dir)[0..10] + v.name = File.basename(vagrant_dir) + '_' + (Digest::SHA256.hexdigest vagrant_dir)[0..10] end # Configuration options for the Parallels provider. config.vm.provider :parallels do |v| v.update_guest_tools = true - v.customize ["set", :id, "--longer-battery-life", "off"] + v.customize ['set', :id, '--longer-battery-life', 'off'] v.memory = vvv_config['vm_config']['memory'] v.cpus = vvv_config['vm_config']['cores'] end # Configuration options for the VMware Desktop provider. config.vm.provider :vmware_desktop do |v| - v.vmx["memsize"] = vvv_config['vm_config']['memory'] - v.vmx["numvcpus"] = vvv_config['vm_config']['cores'] + v.vmx['memsize'] = vvv_config['vm_config']['memory'] + v.vmx['numvcpus'] = vvv_config['vm_config']['cores'] end # Configuration options for Hyper-V provider. @@ -416,21 +373,19 @@ Vagrant.configure("2") do |config| end # Auto Download Vagrant plugins, supported from Vagrant 2.2.0 - unless Vagrant.has_plugin?("vagrant-hostsupdater") - if File.file?(File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) - system("vagrant plugin install " + File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) - File.delete(File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) - puts "#{yellow}VVV has completed installing local plugins. Please run the requested command again.#{creset}" - exit - else - config.vagrant.plugins = ["vagrant-hostsupdater"] - end + unless Vagrant.has_plugin?('vagrant-hostsupdater') + if File.file?(File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) + system('vagrant plugin install ' + File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) + File.delete(File.join(vagrant_dir, 'vagrant-hostsupdater.gem')) + puts "#{yellow}VVV has completed installing the vagrant-hostsupdater plugins. Please run the requested command again.#{creset}" + exit + else + config.vagrant.plugins = ['vagrant-hostsupdater'] + end end # The vbguest plugin has issues for some users, so we're going to disable it for now - if Vagrant.has_plugin?("vagrant-vbguest") - config.vbguest.auto_update = false - end + config.vbguest.auto_update = false if Vagrant.has_plugin?('vagrant-vbguest') # SSH Agent Forwarding # @@ -449,30 +404,30 @@ Vagrant.configure("2") do |config| # This box is provided by Ubuntu vagrantcloud.com and is a nicely sized # box containing the Ubuntu 18.04 Bionic 64 bit release. Once this box is downloaded # to your host computer, it is cached for future use under the specified box name. - config.vm.box = "ubuntu/bionic64" - #config.vm.box = "varying-vagrant-vagrants/ubuntu-18.04" + config.vm.box = 'ubuntu/bionic64' + # config.vm.box = "varying-vagrant-vagrants/ubuntu-18.04" # If we're at a contributor day, switch the base box to the prebuilt one if defined? vvv_config['vm_config']['wordcamp_contributor_day_box'] if vvv_config['vm_config']['wordcamp_contributor_day_box'] == true - config.vm.box = "vvv/contribute" + config.vm.box = 'vvv/contribute' end end # The Parallels Provider uses a different naming scheme. config.vm.provider :parallels do |_v, override| - override.vm.box = "bento/ubuntu-18.04" + override.vm.box = 'bento/ubuntu-18.04' end # The VMware Desktop Provider uses a different naming scheme. config.vm.provider :vmware_desktop do |v, override| - override.vm.box = "bento/ubuntu-18.04" + override.vm.box = 'bento/ubuntu-18.04' v.gui = false end # Hyper-V uses a different base box. config.vm.provider :hyperv do |_v, override| - override.vm.box = "bento/ubuntu-18.04" + override.vm.box = 'bento/ubuntu-18.04' end if defined? vvv_config['vm_config']['box'] @@ -481,7 +436,7 @@ Vagrant.configure("2") do |config| end end - config.vm.hostname = "vvv" + config.vm.hostname = 'vvv' # Specify disk size # @@ -512,10 +467,10 @@ Vagrant.configure("2") do |config| # should be changed. If more than one VM is running through VirtualBox, including other # Vagrant machines, different subnets should be used for each. # - config.vm.network :private_network, id: "vvv_primary", ip: vvv_config['vm_config']['private_network_ip'] + config.vm.network :private_network, id: 'vvv_primary', ip: vvv_config['vm_config']['private_network_ip'] config.vm.provider :hyperv do |_v, override| - override.vm.network :private_network, id: "vvv_primary", ip: nil + override.vm.network :private_network, id: 'vvv_primary', ip: nil end # Public Network (disabled) @@ -553,7 +508,7 @@ Vagrant.configure("2") do |config| # Disable the default synced folder to avoid overlapping mounts config.vm.synced_folder '.', '/vagrant', disabled: true - config.vm.provision "file", source: "#{vagrant_dir}/version", destination: "/home/vagrant/version" + config.vm.provision 'file', source: "#{vagrant_dir}/version", destination: '/home/vagrant/version' # /srv/database/ # @@ -561,29 +516,25 @@ Vagrant.configure("2") do |config| # a mapped directory inside the VM will be created that contains these files. # This directory is used to maintain default database scripts as well as backed # up MariaDB/MySQL dumps (SQL files) that are to be imported automatically on vagrant up - config.vm.synced_folder "database/sql/", "/srv/database" + config.vm.synced_folder 'database/sql/', '/srv/database' use_db_share = false if defined? vvv_config['general']['db_share_type'] - if vvv_config['general']['db_share_type'] != true - use_db_share = false - else - use_db_share = true - end + use_db_share = vvv_config['general']['db_share_type'] == true end if use_db_share == true # Map the MySQL Data folders on to mounted folders so it isn't stored inside the VM - config.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 9001, group: 9001, mount_options: [ "dmode=775", "fmode=664" ] + config.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 9001, group: 9001, mount_options: ['dmode=775', 'fmode=664'] # The Parallels Provider does not understand "dmode"/"fmode" in the "mount_options" as # those are specific to Virtualbox. The folder is therefore overridden with one that # uses corresponding Parallels mount options. config.vm.provider :parallels do |_v, override| - override.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 9001, group: 9001, :mount_options => [] + override.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 9001, group: 9001, mount_options: [] end # Neither does the HyperV provider config.vm.provider :hyperv do |_v, override| - override.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 9001, group: 9001, :mount_options => [ "dir_mode=0775", "file_mode=0664" ] + override.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 9001, group: 9001, mount_options: ['dir_mode=0775', 'file_mode=0664'] end end @@ -593,37 +544,37 @@ Vagrant.configure("2") do |config| # a mapped directory inside the VM will be created that contains these files. # This directory is currently used to maintain various config files for php and # nginx as well as any pre-existing database files. - config.vm.synced_folder "config/", "/srv/config" + config.vm.synced_folder 'config/', '/srv/config' # /srv/config/ # # Map the provision folder so that utilities and provisioners can access helper scripts - config.vm.synced_folder "provision/", "/srv/provision" + config.vm.synced_folder 'provision/', '/srv/provision' # /srv/certificates # # This is a location for the TLS certificates to be accessible inside the VM - config.vm.synced_folder "certificates/", "/srv/certificates", create: true + config.vm.synced_folder 'certificates/', '/srv/certificates', create: true # /var/log/ # # If a log directory exists in the same directory as your Vagrantfile, a mapped # directory inside the VM will be created for some generated log files. - config.vm.synced_folder "log/memcached", "/var/log/memcached", owner: "root", create: true, group: "syslog", mount_options: [ "dmode=777", "fmode=666" ] - config.vm.synced_folder "log/nginx", "/var/log/nginx", owner: "root", create: true, group: "syslog", mount_options: [ "dmode=777", "fmode=666" ] - config.vm.synced_folder "log/php", "/var/log/php", create: true, owner: "root", group: "syslog", mount_options: [ "dmode=777", "fmode=666" ] - config.vm.synced_folder "log/provisioners", "/var/log/provisioners", create: true, owner: "root", group: "syslog", mount_options: [ "dmode=777", "fmode=666" ] + config.vm.synced_folder 'log/memcached', '/var/log/memcached', owner: 'root', create: true, group: 'syslog', mount_options: ['dmode=777', 'fmode=666'] + config.vm.synced_folder 'log/nginx', '/var/log/nginx', owner: 'root', create: true, group: 'syslog', mount_options: ['dmode=777', 'fmode=666'] + config.vm.synced_folder 'log/php', '/var/log/php', create: true, owner: 'root', group: 'syslog', mount_options: ['dmode=777', 'fmode=666'] + config.vm.synced_folder 'log/provisioners', '/var/log/provisioners', create: true, owner: 'root', group: 'syslog', mount_options: ['dmode=777', 'fmode=666'] # /srv/www/ # # If a www directory exists in the same directory as your Vagrantfile, a mapped directory # inside the VM will be created that acts as the default location for nginx sites. Put all # of your project files here that you want to access through the web server - config.vm.synced_folder "www/", "/srv/www", owner: "vagrant", group: "www-data", mount_options: [ "dmode=775", "fmode=774" ] + config.vm.synced_folder 'www/', '/srv/www', owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'] vvv_config['sites'].each do |site, args| if args['local_dir'] != File.join(vagrant_dir, 'www', site) - config.vm.synced_folder args['local_dir'], args['vm_dir'], owner: "vagrant", group: "www-data", :mount_options => [ "dmode=775", "fmode=774" ] + config.vm.synced_folder args['local_dir'], args['vm_dir'], owner: 'vagrant', group: 'www-data', mount_options: ['dmode=775', 'fmode=774'] end end @@ -631,21 +582,21 @@ Vagrant.configure("2") do |config| # those are specific to Virtualbox. The folder is therefore overridden with one that # uses corresponding Parallels mount options. config.vm.provider :parallels do |_v, override| - override.vm.synced_folder "www/", "/srv/www", owner: "vagrant", group: "www-data", :mount_options => [] + override.vm.synced_folder 'www/', '/srv/www', owner: 'vagrant', group: 'www-data', mount_options: [] - override.vm.synced_folder "log/memcached", "/var/log/memcached", owner: "root", create: true, group: "syslog", mount_options: [] - override.vm.synced_folder "log/nginx", "/var/log/nginx", owner: "root", create: true, group: "syslog", mount_options: [] - override.vm.synced_folder "log/php", "/var/log/php", create: true, owner: "root", group: "syslog", mount_options: [] - override.vm.synced_folder "log/provisioners", "/var/log/provisioners", create: true, owner: "root", group: "syslog", mount_options: [] + override.vm.synced_folder 'log/memcached', '/var/log/memcached', owner: 'root', create: true, group: 'syslog', mount_options: [] + override.vm.synced_folder 'log/nginx', '/var/log/nginx', owner: 'root', create: true, group: 'syslog', mount_options: [] + override.vm.synced_folder 'log/php', '/var/log/php', create: true, owner: 'root', group: 'syslog', mount_options: [] + override.vm.synced_folder 'log/provisioners', '/var/log/provisioners', create: true, owner: 'root', group: 'syslog', mount_options: [] if use_db_share == true # Map the MySQL Data folders on to mounted folders so it isn't stored inside the VM - override.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 112, group: 115, mount_options: [] + override.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 112, group: 115, mount_options: [] end vvv_config['sites'].each do |site, args| if args['local_dir'] != File.join(vagrant_dir, 'www', site) - override.vm.synced_folder args['local_dir'], args['vm_dir'], owner: "vagrant", group: "www-data", :mount_options => [] + override.vm.synced_folder args['local_dir'], args['vm_dir'], owner: 'vagrant', group: 'www-data', mount_options: [] end end end @@ -655,23 +606,23 @@ Vagrant.configure("2") do |config| # replaced with SMB shares. Here we switch all the shared folders to us SMB and then # override the www folder with options that make it Hyper-V compatible. config.vm.provider :hyperv do |v, override| - v.vmname = File.basename(vagrant_dir) + "_" + (Digest::SHA256.hexdigest vagrant_dir)[0..10] + v.vmname = File.basename(vagrant_dir) + '_' + (Digest::SHA256.hexdigest vagrant_dir)[0..10] - override.vm.synced_folder "www/", "/srv/www", :owner => "vagrant", :group => "www-data", :mount_options => [ "dir_mode=0775", "file_mode=0774" ] + override.vm.synced_folder 'www/', '/srv/www', owner: 'vagrant', group: 'www-data', mount_options: ['dir_mode=0775', 'file_mode=0774'] if use_db_share == true # Map the MySQL Data folders on to mounted folders so it isn't stored inside the VM - override.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 112, group: 115, mount_options: [ "dir_mode=0775", "file_mode=0664" ] + override.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 112, group: 115, mount_options: ['dir_mode=0775', 'file_mode=0664'] end - override.vm.synced_folder "log/memcached", "/var/log/memcached", owner: "root", create: true, group: "syslog", mount_options: [ "dir_mode=0777", "file_mode=0666" ] - override.vm.synced_folder "log/nginx", "/var/log/nginx", owner: "root", create: true, group: "syslog", mount_options: [ "dir_mode=0777", "file_mode=0666" ] - override.vm.synced_folder "log/php", "/var/log/php", create: true, owner: "root", group: "syslog", mount_options: [ "dir_mode=0777", "file_mode=0666" ] - override.vm.synced_folder "log/provisioners", "/var/log/provisioners", create: true, owner: "root", group: "syslog", mount_options: [ "dir_mode=0777", "file_mode=0666" ] + override.vm.synced_folder 'log/memcached', '/var/log/memcached', owner: 'root', create: true, group: 'syslog', mount_options: ['dir_mode=0777', 'file_mode=0666'] + override.vm.synced_folder 'log/nginx', '/var/log/nginx', owner: 'root', create: true, group: 'syslog', mount_options: ['dir_mode=0777', 'file_mode=0666'] + override.vm.synced_folder 'log/php', '/var/log/php', create: true, owner: 'root', group: 'syslog', mount_options: ['dir_mode=0777', 'file_mode=0666'] + override.vm.synced_folder 'log/provisioners', '/var/log/provisioners', create: true, owner: 'root', group: 'syslog', mount_options: ['dir_mode=0777', 'file_mode=0666'] vvv_config['sites'].each do |site, args| if args['local_dir'] != File.join(vagrant_dir, 'www', site) - override.vm.synced_folder args['local_dir'], args['vm_dir'], :owner => "vagrant", :group => "www-data", :mount_options => [ "dir_mode=0775", "file_mode=0774" ] + override.vm.synced_folder args['local_dir'], args['vm_dir'], owner: 'vagrant', group: 'www-data', mount_options: ['dir_mode=0775', 'file_mode=0774'] end end end @@ -680,21 +631,21 @@ Vagrant.configure("2") do |config| # those are specific to Virtualbox. The folder is therefore overridden with one that # uses corresponding VMware mount options. config.vm.provider :vmware_desktop do |_v, override| - override.vm.synced_folder "www/", "/srv/www", owner: "vagrant", group: "www-data", :mount_options => [ "umask=002" ] + override.vm.synced_folder 'www/', '/srv/www', owner: 'vagrant', group: 'www-data', mount_options: ['umask=002'] - override.vm.synced_folder "log/memcached", "/var/log/memcached", owner: "root", create: true, group: "syslog", mount_options: [ "umask=000" ] - override.vm.synced_folder "log/nginx", "/var/log/nginx", owner: "root", create: true, group: "syslog", mount_options: [ "umask=000" ] - override.vm.synced_folder "log/php", "/var/log/php", create: true, owner: "root", group: "syslog", mount_options: [ "umask=000" ] - override.vm.synced_folder "log/provisioners", "/var/log/provisioners", create: true, owner: "root", group: "syslog", mount_options: [ "umask=000" ] + override.vm.synced_folder 'log/memcached', '/var/log/memcached', owner: 'root', create: true, group: 'syslog', mount_options: ['umask=000'] + override.vm.synced_folder 'log/nginx', '/var/log/nginx', owner: 'root', create: true, group: 'syslog', mount_options: ['umask=000'] + override.vm.synced_folder 'log/php', '/var/log/php', create: true, owner: 'root', group: 'syslog', mount_options: ['umask=000'] + override.vm.synced_folder 'log/provisioners', '/var/log/provisioners', create: true, owner: 'root', group: 'syslog', mount_options: ['umask=000'] if use_db_share == true # Map the MySQL Data folders on to mounted folders so it isn't stored inside the VM - override.vm.synced_folder "database/data/", "/var/lib/mysql", create: true, owner: 112, group: 115, mount_options: [ "umask=000" ] + override.vm.synced_folder 'database/data/', '/var/lib/mysql', create: true, owner: 112, group: 115, mount_options: ['umask=000'] end vvv_config['sites'].each do |site, args| if args['local_dir'] != File.join(vagrant_dir, 'www', site) - override.vm.synced_folder args['local_dir'], args['vm_dir'], owner: "vagrant", group: "www-data", :mount_options => [ "umask=002" ] + override.vm.synced_folder args['local_dir'], args['vm_dir'], owner: 'vagrant', group: 'www-data', mount_options: ['umask=002'] end end end @@ -707,19 +658,22 @@ Vagrant.configure("2") do |config| # # Note that if you find yourself using a Customfile for anything crazy or specifying # different provisioning, then you may want to consider a new Vagrantfile entirely. - if File.exists?(File.join(vagrant_dir,'Customfile')) - puts "Running Custom Vagrant file with additional vagrant configs at #{File.join(vagrant_dir,'Customfile')}\n\n" - eval(IO.read(File.join(vagrant_dir,'Customfile')), binding) - puts "Finished running Custom Vagrant file with additional vagrant configs, resuming normal vagrantfile execution\n\n" + if File.exist?(File.join(vagrant_dir, 'Customfile')) + puts " ⚠ ! Running additional Vagrant code in Customfile located at #{File.join(vagrant_dir, 'Customfile')}\n" + puts " ⚠ ! Official support is not provided for this feature, it is assumed you are proficient with vagrant\n\n" + eval(IO.read(File.join(vagrant_dir, 'Customfile')), binding) + puts " ⚠ ! Finished running Customfile, resuming normal vagrantfile execution\n\n" end vvv_config['sites'].each do |site, args| - if args['allow_customfile'] - paths = Dir[File.join(args['local_dir'], '**', 'Customfile')] - paths.each do |file| - puts "Running additional site vagrant customfile at #{file}\n\n" - eval(IO.read(file), binding) - end + next unless args['allow_customfile'] + + paths = Dir[File.join(args['local_dir'], '**', 'Customfile')] + paths.each do |file| + puts " ⚠ ! Running additional site customfile at #{file}\n" + puts " ⚠ ! Official support is not provided for this feature.\n\n" + eval(IO.read(file), binding) + puts " ⚠ ! Finished running Customfile, resuming normal vagrantfile execution\n\n" end end @@ -730,8 +684,8 @@ Vagrant.configure("2") do |config| # provison-pre.sh acts as a pre-hook to our default provisioning script. Anything that # should run before the shell commands laid out in provision.sh (or your provision-custom.sh # file) should go in this script. If it does not exist, no extra provisioning will run. - if File.exists?(File.join(vagrant_dir,'provision','provision-pre.sh')) - config.vm.provision "pre", type: "shell", keep_color: true, path: File.join( "provision", "provision-pre.sh" ) + if File.exist?(File.join(vagrant_dir, 'provision', 'provision-pre.sh')) + config.vm.provision 'pre', type: 'shell', keep_color: true, path: File.join('provision', 'provision-pre.sh'), env: { "VVV_LOG" => "pre" } end # provision.sh or provision-custom.sh @@ -740,78 +694,79 @@ Vagrant.configure("2") do |config| # provision directory. If it is detected that a provision-custom.sh script has been # created, that is run as a replacement. This is an opportunity to replace the entirety # of the provisioning provided by default. - if File.exists?(File.join(vagrant_dir,'provision','provision-custom.sh')) - config.vm.provision "custom", type: "shell", keep_color: true, path: File.join( "provision", "provision-custom.sh" ) + if File.exist?(File.join(vagrant_dir, 'provision', 'provision-custom.sh')) + config.vm.provision 'custom', type: 'shell', keep_color: true, path: File.join('provision', 'provision-custom.sh'), env: { "VVV_LOG" => "main-custom" } else - config.vm.provision "default", type: "shell", keep_color: true, path: File.join( "provision", "provision.sh" ) + config.vm.provision 'default', type: 'shell', keep_color: true, path: File.join('provision', 'provision.sh'), env: { "VVV_LOG" => "main" } end # Provision the dashboard that appears when you visit vvv.test - config.vm.provision "dashboard", - type: "shell", - keep_color: true, - path: File.join( "provision", "provision-dashboard.sh" ), - args: [ - vvv_config['dashboard']['repo'], - vvv_config['dashboard']['branch'] - ] + config.vm.provision 'dashboard', + type: 'shell', + keep_color: true, + path: File.join('provision', 'provision-dashboard.sh'), + args: [ + vvv_config['dashboard']['repo'], + vvv_config['dashboard']['branch'] + ], + env: { "VVV_LOG" => "dashboard" } vvv_config['utility-sources'].each do |name, args| config.vm.provision "utility-source-#{name}", - type: "shell", - keep_color: true, - path: File.join( "provision", "provision-utility-source.sh" ), - args: [ - name, - args['repo'].to_s, - args['branch'], - ] + type: 'shell', + keep_color: true, + path: File.join('provision', 'provision-utility-source.sh'), + args: [ + name, + args['repo'].to_s, + args['branch'] + ], + env: { "VVV_LOG" => "utility-source-#{name}" } end vvv_config['utilities'].each do |name, utilities| - - unless utilities.kind_of? Array - utilities = Hash.new - end + utilities = {} unless utilities.is_a? Array utilities.each do |utility| - if utility == 'tideways' - vvv_config['hosts'] += ['tideways.vvv.test'] - vvv_config['hosts'] += ['xhgui.vvv.test'] - end - config.vm.provision "utility-#{name}-#{utility}", - type: "shell", - keep_color: true, - path: File.join( "provision", "provision-utility.sh" ), - args: [ - name, - utility - ] + if utility == 'tideways' + vvv_config['hosts'] += ['tideways.vvv.test'] + vvv_config['hosts'] += ['xhgui.vvv.test'] end + config.vm.provision "utility-#{name}-#{utility}", + type: 'shell', + keep_color: true, + path: File.join('provision', 'provision-utility.sh'), + args: [ + name, + utility + ], + env: { "VVV_LOG" => "utility-#{name}-#{utility}" } + end end vvv_config['sites'].each do |site, args| - unless args['skip_provisioning'] - config.vm.provision "site-#{site}", - type: "shell", - keep_color: true, - path: File.join( "provision", "provision-site.sh" ), - args: [ - site, - args['repo'].to_s, - args['branch'], - args['vm_dir'], - args['skip_provisioning'].to_s, - args['nginx_upstream'] - ] - end + next if args['skip_provisioning'] + + config.vm.provision "site-#{site}", + type: 'shell', + keep_color: true, + path: File.join('provision', 'provision-site.sh'), + args: [ + site, + args['repo'].to_s, + args['branch'], + args['vm_dir'], + args['skip_provisioning'].to_s, + args['nginx_upstream'] + ], + env: { "VVV_LOG" => "site-#{site}" } end # provision-post.sh acts as a post-hook to the default provisioning. Anything that should # run after the shell commands laid out in provision.sh or provision-custom.sh should be # put into this file. This provides a good opportunity to install additional packages # without having to replace the entire default provisioning script. - if File.exists?(File.join(vagrant_dir,'provision','provision-post.sh')) - config.vm.provision "post", type: "shell", keep_color: true, path: File.join( "provision", "provision-post.sh" ) + if File.exist?(File.join(vagrant_dir, 'provision', 'provision-post.sh')) + config.vm.provision 'post', type: 'shell', keep_color: true, path: File.join('provision', 'provision-post.sh'), env: { "VVV_LOG" => "post" } end # Local Machine Hosts @@ -823,11 +778,22 @@ Vagrant.configure("2") do |config| # # By default, we'll include the domains set up by VVV through the vvv-hosts file # located in the www/ directory and in config/config.yml. - if defined?(VagrantPlugins::HostsUpdater) + # + if defined?(VagrantPlugins::HostManager) + config.hostmanager.aliases = vvv_config['hosts'] + config.hostmanager.enabled = true + config.hostmanager.manage_host = true + config.hostmanager.manage_guest = true + config.hostmanager.ignore_private_ip = false + config.hostmanager.include_offline = true + elsif defined?(VagrantPlugins::HostsUpdater) # Pass the found host names to the hostsupdater plugin so it can perform magic. config.hostsupdater.aliases = vvv_config['hosts'] config.hostsupdater.remove_on_suspend = true + else + puts "! Neither the HostManager or HostsUpdater plugins are installed!!! Domains won't work without one of these plugins!" + puts "Run vagrant plugin install vagrant-hostmanager then try again." end # Vagrant Triggers @@ -840,42 +806,43 @@ Vagrant.configure("2") do |config| # to create backups of all current databases. This can be overridden with custom # scripting. See the individual files in config/homebin/ for details. config.trigger.after :up do |trigger| - trigger.name = "VVV Post-Up" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_up" } + trigger.name = 'VVV Post-Up' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_up' } trigger.on_error = :continue end config.trigger.before :provision do |trigger| - trigger.info = "༼ つ ◕_◕ ༽つ Provisioning can take a few minutes, go make a cup of tea and sit back. If you only wanted to turn VVV on, use vagrant up" + trigger.name = 'VVV Pre-Provision' + trigger.info = "\n༼ つ ◕_◕ ༽つ A full provision can take a little while!\n Go make a cup of tea and sit back.\n If you only wanted to turn VVV on, use vagrant up\n" trigger.on_error = :continue end config.trigger.after :provision do |trigger| - trigger.name = "VVV Post-Provision" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_provision" } + trigger.name = 'VVV provisioning has reached the end' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_provision' } trigger.on_error = :continue end config.trigger.before :reload do |trigger| - trigger.name = "VVV Pre-Reload" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_halt" } + trigger.name = 'VVV Pre-Reload' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_halt' } trigger.on_error = :continue end config.trigger.after :reload do |trigger| - trigger.name = "VVV Post-Reload" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_up" } + trigger.name = 'VVV Post-Reload' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_up' } trigger.on_error = :continue end config.trigger.before :halt do |trigger| - trigger.name = "VVV Pre-Halt" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_halt" } + trigger.name = 'VVV Pre-Halt' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_halt' } trigger.on_error = :continue end config.trigger.before :suspend do |trigger| - trigger.name = "VVV Pre-Suspend" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_suspend" } + trigger.name = 'VVV Pre-Suspend' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_suspend' } trigger.on_error = :continue end config.trigger.before :destroy do |trigger| - trigger.name = "VVV Pre-Destroy" - trigger.run_remote = { inline: "/srv/config/homebin/vagrant_destroy" } + trigger.name = 'VVV Pre-Destroy' + trigger.run_remote = { inline: '/srv/config/homebin/vagrant_destroy' } trigger.on_error = :continue end end diff --git a/config/apt-source-append.list b/config/apt-source-append.list index 7237259b9..1fccaf1f3 100644 --- a/config/apt-source-append.list +++ b/config/apt-source-append.list @@ -13,10 +13,29 @@ deb-src http://ppa.launchpad.net/ondrej/php/ubuntu bionic main deb http://ppa.launchpad.net/varying-vagrant-vagrants/php/ubuntu bionic main deb-src http://ppa.launchpad.net/varying-vagrant-vagrants/php/ubuntu bionic main -# MariaDB 10.3 repository list - created 2018-06-19 13:36 UTC -# https://downloads.mariadb.org/mariadb/repositories/ -deb [arch=amd64,i386] https://mirror.herrbischoff.com/mariadb/repo/10.3/ubuntu bionic main -deb-src https://mirror.herrbischoff.com/mariadb/repo/10.3/ubuntu bionic main +# MariaDB 10.4 Amsterdam +deb [arch=amd64,arm64,ppc64el] http://ams2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main +deb-src http://ams2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main + +# MariaDB 10.4 Digital Ocean Singapore +deb [arch=amd64,arm64,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main +deb-src http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main + +# MariaDB 10.4 Digital Ocean San Francisco +deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main +deb-src http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main + +# MariaDB 10.4 Yamagata University Japan +deb [arch=amd64,arm64,ppc64el] http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.4/ubuntu bionic main +deb-src http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.4/ubuntu bionic main + +# MariaDB 10.4 UKFast Manchester +deb [arch=amd64,arm64,ppc64el] http://mirrors.ukfast.co.uk/sites/mariadb/repo/10.4/ubuntu bionic main +deb-src http://mirrors.ukfast.co.uk/sites/mariadb/repo/10.4/ubuntu bionic main + +# MariaDB 10.4 PicoNets Mumbai +deb [arch=amd64,arm64,ppc64el] http://mirrors.piconets.webwerks.in/mariadb-mirror/repo/10.4/ubuntu bionic main +deb-src http://mirrors.piconets.webwerks.in/mariadb-mirror/repo/10.4/ubuntu bionic main # Provides Node.js deb https://deb.nodesource.com/node_10.x bionic main diff --git a/config/bash_aliases b/config/bash_aliases index 3cb98d947..ec8e5111e 100644 --- a/config/bash_aliases +++ b/config/bash_aliases @@ -27,20 +27,27 @@ elif [ -d "/srv/www/wordpress-develop/public_html/src/" ]; then fi # PHPCS path -export PATH="$PATH:/srv/www/phpcs/scripts/" +if [[ $PATH != *"/srv/www/phpcs/scripts"* ]]; then + export PATH="$PATH:/srv/www/phpcs/scripts" +fi -# Vagrant scripts -export PATH="$PATH:/srv/config/homebin/" -# nvm path -export NVM_DIR="/srv/config/nvm" +# Ruby Gems +if [ -d "$HOME/.gem/bin" ] ; then + if [[ $PATH != *"${HOME}/.gem/bin"* ]]; then + export PATH="$PATH:${HOME}/.gem/bin" + fi +fi -if [ -n "$BASH" ]; then - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm +# Vagrant scripts +if [[ $PATH != *"/srv/config/homebin"* ]]; then + export PATH="$PATH:/srv/config/homebin" +fi +if [ -n "$BASH" ]; then # add autocomplete for grunt [ ! type "grunt" > /dev/null 2>&1 ] && eval "$(grunt --completion=bash)" # add autocomplete for wp-cli [ -s "/srv/config/wp-cli/wp-completion.bash" ] && . /srv/config/wp-cli/wp-completion.bash -fi \ No newline at end of file +fi diff --git a/config/default-config.yml b/config/default-config.yml index 795781b41..90a0f5fc0 100644 --- a/config/default-config.yml +++ b/config/default-config.yml @@ -123,7 +123,10 @@ vm_config: # Due to a limitation within Vagrant, the specified provider is only respected on a clean `vagrant up` # as Vagrant currently restricts you to one provider per machine # https://www.vagrantup.com/docs/providers/basic_usage.html#vagrant-up - # provider: vmware_workstation + # provider: virtualbox + # provider: hyperv + # provider: parallels + # provider: vmware_desktop # General VVV options general: diff --git a/config/homebin/db_backup b/config/homebin/db_backup index d978c9050..3dc4b44e4 100755 --- a/config/homebin/db_backup +++ b/config/homebin/db_backup @@ -4,7 +4,7 @@ # are imported automatically during an initial provision if # the databases exist per the import-sql.sh process. mkdir -p /srv/database/backups -echo "Performing Database Backups" +echo " * Performing Database Backups" mysql --user="root" --password="root" -e 'show databases' | \ grep -v -F "information_schema" | \ grep -v -F "performance_schema" | \ @@ -13,6 +13,7 @@ grep -v -F "test" | \ grep -v -F "Database" | \ while read dbname; do - echo "Backing up Database $dbname..." - mysqldump -uroot -proot "$dbname" > /srv/database/backups/"$dbname".sql && echo "Database $dbname backed up..."; + echo " - Backing up \"$dbname\" to database/backups/${dbname}.sql" + mysqldump -uroot -proot "$dbname" > "/srv/database/backups/${dbname}.sql"; done +echo " * Finished backing up databases" \ No newline at end of file diff --git a/config/homebin/is_utility_installed b/config/homebin/is_utility_installed index a400f74f0..a131fa433 100755 --- a/config/homebin/is_utility_installed +++ b/config/homebin/is_utility_installed @@ -1,10 +1,8 @@ #!/bin/bash -VVV_CONFIG=/vagrant/config.yml - -utilities=$(shyaml get-values "utilities.${1}" 2> /dev/null < ${VVV_CONFIG}) +utilities=$(shyaml get-values "utilities.${1}" 2> /dev/null < "${VVV_CONFIG}") for utility in ${utilities}; do -if [[ "${utility}" == "${2}" ]]; then - exit 0 -fi + if [[ "${utility}" == "${2}" ]]; then + exit 0 + fi done -exit 1 \ No newline at end of file +exit 1 diff --git a/config/homebin/switch_php_debugmod b/config/homebin/switch_php_debugmod new file mode 100755 index 000000000..aff4a38b9 --- /dev/null +++ b/config/homebin/switch_php_debugmod @@ -0,0 +1,68 @@ +#!/bin/bash + +set -eo pipefail + +# Grab the currently active PHP mods, and lowercase it for comparison +enabled_mods=$(php -m) +enabled_mods=${enabled_mods,,} + +# These PHPMods all interfere with each other in some way +phpmods=( + "xdebug" + "xhgui" + "tideways_xhprof" + "pcov" +) + +# The mod that the user wants enabled, `none` for vanilla PHP +mod=${1:-none} +mod=${mod,,} + +disable_phpmods() { + # declare that our first param is an array + declare -a mods=("${!1}") + + # Take the mods array and turn it into a commar separated list + local mods_joined=$(printf ", %s" "${mods[@]}") + mods_joined=${mods_joined:1} + mods_joined="${mods_joined#"${mods_joined%%[![:space:]]*}"}" + echo " * Disabling if present: '${mods_joined}'" + + for i in "${mods[@]}" + do + if [[ ${enabled_mods,,} == *"${i}"* ]]; then + echo " * Disabling active module: '${i}'" + sudo phpdismod "${i}" + fi + done +} + +enable_phpmod() { + echo " * Enabling '${1}'" + sudo phpenmod "${1}" +} + +restart_phpfpm() { + echo " * Restarting PHP FPM's so the change takes effect" + find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; +} + +echo " * Disabling active debug PHP mods" +disable_phpmods phpmods[@] + +if [[ "${mod}" == "none" ]]; then + restart_phpfpm + exit 0 +fi + + +# Tideways needs 2 mods enabling +if [[ "${mod}" == "tideways" ]]; then + enable_phpmod "xhgui" + enable_phpmod "tideways_xhprof" + restart_phpfpm + exit 0 +fi + +enable_phpmod "${mod}" +restart_phpfpm diff --git a/config/homebin/tideways_off b/config/homebin/tideways_off index 709f58424..bf7ce5c5c 100755 --- a/config/homebin/tideways_off +++ b/config/homebin/tideways_off @@ -1,10 +1,4 @@ #!/bin/bash -echo "Disabling tideways_xhprof/xhgui" -sudo phpdismod tideways_xhprof -sudo phpdismod xhgui +switch_php_debugmod none -echo "Restarting PHP FPM's" -find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; - -echo "Tideways is turned off" diff --git a/config/homebin/tideways_on b/config/homebin/tideways_on index 496afea3a..88e0d8535 100755 --- a/config/homebin/tideways_on +++ b/config/homebin/tideways_on @@ -1,17 +1,3 @@ #!/bin/bash -if [[ ! $(is_utility_installed core tideways) ]]; then - echo "Tideways is not installed" - exit 0 -fi -echo "Disabling XDebug if it's present" -sudo phpdismod xdebug - -echo "Enabling tideways_xhprof/xhgui" -sudo phpenmod tideways_xhprof -sudo phpenmod xhgui - -echo "Restarting PHP FPM's" -find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; - -echo "Tideways enabled!" +switch_php_debugmod tideways diff --git a/config/homebin/vagrant_destroy b/config/homebin/vagrant_destroy index 179ab193e..7a957c07d 100755 --- a/config/homebin/vagrant_destroy +++ b/config/homebin/vagrant_destroy @@ -24,4 +24,14 @@ else then /srv/config/homebin/db_backup fi + + echo "" + echo -e " !!! " + echo -e " ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ __ __ __ __" + echo -e " █▒▒░░░░░░░░░▒▒█ Farewell \ V\ V\ V /" + echo -e " █░░X░░░░░X░░█ virtual world \_/\_/\_/" + echo -e " █░░░▀█▀░░░█ " + echo -e " ▄▄ ▀▄░░░░░░░▄▀ ▄▄ Don't forget to make a new teddy bear" + echo -e "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ with vagrant up --provision" + echo -e "\033[0m" fi diff --git a/config/homebin/vagrant_halt b/config/homebin/vagrant_halt index 4ea1d804c..f1f704e4e 100755 --- a/config/homebin/vagrant_halt +++ b/config/homebin/vagrant_halt @@ -20,8 +20,22 @@ else # Check if backups are turned on or off run_backups=`cat ${VVV_CONFIG} | shyaml get-value general.db_backup 2> /dev/null` - if [[ $run_backups != "False" ]] - then + if [[ $run_backups != "False" ]]; then /srv/config/homebin/db_backup fi + RED="\033[38;5;9m" + GREEN="\033[01;32m" + BLUE="\033[38;5;4m" + CYAN="\033[38;5;6m" + CRESET="\033[0m" + URL="\033[4;38;5;3m" + + echo -e "${BLUE} . ★ ☁ ★ ." + echo -e "${BLUE}Z ☽ ★ . ☁" + echo -e "${BLUE} Z ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ ★ __★__ __ __" + echo -e "${BLUE}☁ z█▒▒░░░░░░░░░▒▒█ Sleep tight \ V\ V\ V /" + echo -e "${BLUE} ★ █░░▁░░░░░▁░░█ ★ \_/\_/\_/" + echo -e "${BLUE} . █░░░▀█▀░░░█ . ★" + echo -e "${BLUE} ★ ▀▄░░░░░░░▄▀ ★ ." + echo -e "${CRESET}" fi diff --git a/config/homebin/vagrant_suspend b/config/homebin/vagrant_suspend index 955562ad6..1dcea1f64 100755 --- a/config/homebin/vagrant_suspend +++ b/config/homebin/vagrant_suspend @@ -24,4 +24,19 @@ else then /srv/config/homebin/db_backup fi + + RED="\033[38;5;9m" + GREEN="\033[01;32m" + BLUE="\033[38;5;4m" + CYAN="\033[38;5;6m" + CRESET="\033[0m" + + echo -e " " + echo -e "${CYAN}❄ ❄ brrrr ❄ ❅ ❄" + echo -e "${CYAN} ❆ ▄▀▀▀▄▄▄▄▄❆▄▀▀▀▄ ❄ ❄ __ __ __❅__" + echo -e "${CYAN} ✧█▒▒░░░░░░░░░▒▒█ Thanks for \ V\ V\ V /" + echo -e "${CYAN}❄ █░░█░░░░░█░░█ ❅ using ❆ \_/\_/\_/" + echo -e "${CYAN} ▄▄❆ █░░░▀█▀░░░█❆ ▄▄✧ ❅ ❄ ❅" + echo -e "${CYAN}█░░█ ▀▄░░░░░░░▄▀ █░░█ Entering stasis! Run vagrant resume to thaw${CRESET}" + echo -e "${CRESET}" fi diff --git a/config/homebin/vagrant_up b/config/homebin/vagrant_up index d8e5f728d..2db9466ea 100755 --- a/config/homebin/vagrant_up +++ b/config/homebin/vagrant_up @@ -8,23 +8,48 @@ # all trigger actions should be handled by this custom script. If # it does not exist, then we'll handle some basic tasks. -echo "Post Vagrant up script" - if [[ -f /srv/config/homebin/vagrant_up_custom ]]; then - echo "Custom vagrant up script found, executing vagrant_up_custom" + echo " * Custom vagrant up script found, executing vagrant_up_custom" /srv/config/homebin/vagrant_up_custom fi -echo "Restarting Nginx and MySQL" +echo " * Restarting Nginx and MySQL" sudo service nginx restart sudo service mysql restart -green="\033[01;32m" -echo "" -echo -e "${green} yay " -echo -e "${green} ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ __ __ __ __" -echo -e "${green} █▒▒░░░░░░░░░▒▒█ Thanks for \ V\ V\ V /" -echo -e "${green} █░░█░░░░░█░░█ using \_/\_/\_/" -echo -e "${green} ▄▄ █░░░▀█▀░░░█ ▄▄ " -echo -e "${green}█░░█ ▀▄░░░░░░░▄▀ █░░█ Vagrant Up has finished! Visit http://vvv.test" -echo -e "\033[0m" +RED="\033[38;5;9m" +GREEN="\033[01;32m" +BLUE="\033[38;5;4m" +CYAN="\033[38;5;6m" +CRESET="\033[0m" +TEARS="${CYAN}░${RED}" +EYE="${CYAN}█${RED}" +URL="\033[4;38;5;3m" + +mkdir -p /vagrant/failed_provisioners +if [ -z "$(ls -A /vagrant/failed_provisioners/)" ]; then + echo -e "${GREEN}" + echo -e "${GREEN} yay " + echo -e "${GREEN} ✧ ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ ✧ __ __ __ __" + echo -e "${GREEN} ✧█▒▒░░░░░░░░░▒▒█ Thanks for \ V\ V\ V /" + echo -e "${GREEN}✧ █░░█░░░░░█░░█ ✧ using \_/\_/\_/" + echo -e "${GREEN} ▄▄ █░░░▀█▀░░░█ ▄▄✧" + echo -e "${GREEN}█░░█ ▀▄░░░░░░░▄▀ █░░█ Vagrant Up has finished! Visit ${URL}http://vvv.test${CRESET}" + echo -e "${CRESET}" +else + date_time=$(cat /vagrant/provisioned_at) + echo -e "${RED}" + echo -e "${RED} oh noes :'( " + echo -e "${RED} ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ __ __ __ __" + echo -e "${RED} █▒▒░░░░░░░░░▒▒█ Provisioning \ V\ V\ V /" + echo -e "${RED} █░░${EYE}░░░░░${EYE}░░█ incomplete! \_/\_/\_/" + echo -e "${RED} █░${TEARS}░▀█▀░${TEARS}░█ " + echo -e "${RED} ▄▄▀▄${TEARS}░░░░░${TEARS}▄▀▄▄ Check the logs and reprovision." + echo -e "${RED} If that fails, go to the VVV Slack or open an issue" + echo -e "${RED} on GitHub. Logs are in the logs/provisioners folder." + echo -e "${RED}" + echo -e "${RED} The failed provisioners left these logs:" + # List failed provisioners, and pipe them through xargs to print them in a formatted way. + ls -A /vagrant/failed_provisioners/ | xargs -I "LOGFILE" echo -e " - log/provisioners/${date_time}/LOGFILE.log" + echo -e "${CRESET}" +fi diff --git a/config/homebin/xdebug_off b/config/homebin/xdebug_off index e5ed4c45e..c469ddbdd 100755 --- a/config/homebin/xdebug_off +++ b/config/homebin/xdebug_off @@ -1,8 +1,3 @@ #!/bin/bash -echo "Disabling XDebug if it's present" -sudo phpdismod xdebug -echo "Restarting PHP FPM's" -find /etc/init.d/ -name "php*-fpm" -exec bash -c 'sudo service "$(basename "$0")" restart' {} \; - -echo "XDebug is turned off" +switch_php_debugmod none diff --git a/config/homebin/xdebug_on b/config/homebin/xdebug_on index d3efd7251..014e6be35 100755 --- a/config/homebin/xdebug_on +++ b/config/homebin/xdebug_on @@ -1,11 +1,6 @@ #!/bin/bash -tideways_off - -echo "Enabling XDebug" -sudo phpenmod xdebug - -find /etc/init.d/ -name "php*-fpm" -exec bash -c 'echo "Restarting $(basename "$0" ) " && sudo service "$(basename "$0")" restart' {} \; +switch_php_debugmod xdebug # Ensure the log file for xdebug is group writeable. echo "Making sure log/php/xdebug-remote.log is readable and present" diff --git a/config/php-config/php7.2-www.conf b/config/php-config/php7.2-www.conf index 28071fdd2..087cad98b 100644 --- a/config/php-config/php7.2-www.conf +++ b/config/php-config/php7.2-www.conf @@ -117,7 +117,7 @@ pm.max_spare_servers = 3 pm.max_requests = 100 ; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. It shows the following informations: +; recognized as a status page. It shows the following information: ; pool - the name of the pool; ; process manager - static, dynamic or ondemand; ; start time - the date and time FPM has started; @@ -187,8 +187,8 @@ pm.max_requests = 100 ; it's always 0 if the process is not in Idle state ; because memory calculation is done when the request ; processing has terminated; -; If the process is in Idle state, then informations are related to the -; last request the process has served. Otherwise informations are related to +; If the process is in Idle state, then information is related to the +; last request the process has served. Otherwise information is related to ; the current request being served. ; Example output: ; ************************ @@ -247,13 +247,13 @@ pm.status_path = /php-status ; %d: time taken to serve the request ; it can accept the following format: ; - %{seconds}d (default) -; - %{miliseconds}d +; - %{milliseconds}d ; - %{mili}d ; - %{microseconds}d ; - %{micro}d ; %e: an environment variable (same as $_ENV or $_SERVER) ; it must be associated with embraces to specify the name of the env -; variable. Some exemples: +; variable. Some examples: ; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e ; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e ; %f: script filename @@ -267,7 +267,7 @@ pm.status_path = /php-status ; - %{megabytes}M ; - %{mega}M ; %n: pool name -; %o: ouput header +; %o: output header ; it must be associated with embraces to specify the name of the header: ; - %{Content-Type}o ; - %{X-Powered-By}o @@ -336,7 +336,7 @@ chdir = / ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. -; Note: on highloaded environement, this can cause some delay in the page +; Note: on highloaded environment, this can cause some delay in the page ; process time (several ms). ; Default Value: no catch_workers_output = yes @@ -344,7 +344,7 @@ catch_workers_output = yes ; Limits the extensions of the main script FPM will allow to parse. This can ; prevent configuration mistakes on the web server side. You should only limit ; FPM to .php extensions to prevent malicious users to use other extensions to -; exectute php code. +; execute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php ;security.limit_extensions = .php .php3 .php4 .php5 .php7 diff --git a/config/php-config/xdebug.ini b/config/php-config/xdebug.ini index f0cf340e2..fc28fa2ed 100644 --- a/config/php-config/xdebug.ini +++ b/config/php-config/xdebug.ini @@ -46,7 +46,7 @@ xdebug.default_enable = "On" ; Type: string, Default value: Empty ; * = COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION. These seven settings control which data ; from the superglobals is shown when an error situation occurs. Each php.ini setting can consist of -; a comma seperated list of variables from this superglobal to dump, but make sure you do not add +; a comma separated list of variables from this superglobal to dump, but make sure you do not add ; spaces in this setting. In order to dump the REMOTE_ADDR and the REQUEST_METHOD when an error ; occurs, add this setting: ; @@ -60,7 +60,7 @@ xdebug.dump.SESSION = "" ; xdebug.dump_globals ; Type: boolean, Default value: 1 -; Controls whether the values of the superglobals as defined by the xdebug.dump.* settings whould be +; Controls whether the values of the superglobals as defined by the xdebug.dump.* settings would be ; shown or not. xdebug.dump_globals = 1 @@ -123,7 +123,7 @@ xdebug.overload_var_dump = 1 ; xdebug.profiler_append ; Type: integer, Default value: 0 ; When this setting is set to 1, profiler files will not be overwritten when a new request would map -; to the same file (depnding on the xdebug.profiler_output_name setting. Instead the file will be +; to the same file (depending on the xdebug.profiler_output_name setting. Instead the file will be ; appended to with the new profile. xdebug.profiler_append = 0 diff --git a/config/update-motd.d/00-vvv-bash-splash b/config/update-motd.d/00-vvv-bash-splash old mode 100644 new mode 100755 index 469209604..0886bc7eb --- a/config/update-motd.d/00-vvv-bash-splash +++ b/config/update-motd.d/00-vvv-bash-splash @@ -3,10 +3,15 @@ red="\033[38;5;9m" green="\033[1;38;5;2m" blue="\033[38;5;4m" +magenta="\033[38;5;5m" purple="\033[38;5;5m" yellow="\033[38;5;3m" creset="\033[0m" -echo -e "\033[1;38;5;196m__ ${green}__ ${blue}__ __ " -echo -e "${red}\\ V${green}\\ V${blue}\\ V / ${red}Varying ${green}Vagrant ${blue}Vagrants" -echo -e "${red} \\_/${green}\\_/${blue}\\_/ ${yellow}Have a nice day ${creset}" -echo " " + +echo -e "${magenta} ✧ Hello Again! ✧ ✧ ✧ " +echo -e "${magenta}✧ ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ ✧ ${red}__ ${green}__ ${blue}__ __" +echo -e "${magenta} ✧█▒▒░░░░░░░░░▒▒█ ${red}\\ V${green}\\ V${blue}\\ V /" +echo -e "${magenta} ▄▄ █░░█░░░░░█░░█ ✧ ${red} \\_/${green}\\_/${blue}\\_/" +echo -e "${magenta}█░░█ █░░░▀█▀░░░█ ✧ ✧ " +echo -e "${magenta}█░░█ ▀▄░░░░░░░▄▀ ✧ Have a nice day :)${CRESET}" +echo -e "${CRESET}" \ No newline at end of file diff --git a/database/sql/import-sql.sh b/database/sql/import-sql.sh index 60cdaaf05..443963314 100755 --- a/database/sql/import-sql.sh +++ b/database/sql/import-sql.sh @@ -53,7 +53,7 @@ then mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS \`${db_name}\`" mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON \`${db_name}\`.* TO wp@localhost IDENTIFIED BY 'wp';" - mysql_cmd="SHOW TABLES FROM \`${db_name}\`" # Required to support hypens in database names + mysql_cmd="SHOW TABLES FROM \`${db_name}\`" # Required to support hyphens in database names db_exist=$(mysql -u root -proot --skip-column-names -e "${mysql_cmd}") if [ "$?" != "0" ] then diff --git a/provision/provision-dashboard.sh b/provision/provision-dashboard.sh index 271fa3add..dd1ddde3f 100644 --- a/provision/provision-dashboard.sh +++ b/provision/provision-dashboard.sh @@ -1,17 +1,11 @@ #!/usr/bin/env bash +. "/srv/provision/provisioners.sh" + REPO=$1 BRANCH=${2:-master} DIR="/srv/www/default/dashboard" -date_time=$(cat /vagrant/provisioned_at) -logfolder="/var/log/provisioners/${date_time}" -logfile="${logfolder}/provisioner-dashboard.log" -mkdir -p "${logfolder}" -touch "${logfile}" -exec > >(tee -a "${logfile}" ) -exec 2> >(tee -a "${logfile}" >&2 ) - if [[ false != "dashboard" && false != "${REPO}" ]]; then # Clone or pull the resources repository if [[ ! -d "${DIR}/.git" ]]; then @@ -29,4 +23,5 @@ else echo " * Skipping dashboard provisioning, set to false in config" fi -exit 0 +provisioner_success + diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh new file mode 100644 index 000000000..61312ce4f --- /dev/null +++ b/provision/provision-helpers.sh @@ -0,0 +1,206 @@ +#!/bin/bash +# +# provision-network-functions.sh +# +# This file is for common network helper functions that get called in +# other provisioners + +export YELLOW="\033[38;5;3m" +export GREEN="\033[38;5;2m" +export RED="\033[38;5;9m" +export CRESET="\033[0m" +export BOLD="\033[1m" + +VVV_CONFIG=/vagrant/vvv-custom.yml +if [[ -f /vagrant/config.yml ]]; then + VVV_CONFIG=/vagrant/config.yml +fi + +export VVV_CONFIG +export VVV_CURRENT_LOG_FILE="" + +function containsElement () { + declare -a array=(${2}) + local i + for i in "${array[@]}" + do + if [ "${i}" == "${1}" ] ; then + return 0 + fi + done + return 1 +} +export -f containsElement + +function network_detection() { + url=${1:-"https://ppa.launchpad.net"} + check_network_connection_to_host "${url}" +} +export -f network_detection + +function check_network_connection_to_host() { + url=${1:-"https://ppa.launchpad.net"} + echo " * Testing network connection to ${url}" + + # Network Detection + # + # If 3 attempts with a timeout of 5 seconds are not successful, + # then we'll skip a few things further in provisioning rather + # than create a bunch of errors. + if [[ "$(wget --tries=3 --timeout=10 "${url}" -O /dev/null 2>&1 | grep 'connected')" ]]; then + vvv_success " * Successful Network connection to ${url} detected" + return 0 + fi + vvv_error " ! Network connection issues found. Unable to reach ${url}" + return 1 +} +export -f check_network_connection_to_host + +function network_check() { + # Make an HTTP request to ppa.launchpad.net to determine if + # outside access is available to us. Also check the mariadb + declare -a hosts_to_test=( + "https://ppa.launchpad.net" + "https://wordpress.org" + "https://github.com" + "https://raw.githubusercontent.com" + "https://getcomposer.org" + "http://ams2.mirrors.digitalocean.com" + ) + declare -a failed_hosts=() + for url in "${hosts_to_test[@]}"; do + if ! check_network_connection_to_host "${url}" ; then + failed_hosts+=( "$url" ) + fi + done + + if (( ${#failed_hosts[@]} )); then + echo -e "${RED} " + echo "#################################################################" + echo " " + echo "! Network Problem:" + echo " " + echo "VVV tried to ping several domains it needs but some failed:" + echo " " + for i in "${hosts_to_test[@]}"; do + local url="${i}" + if containsElement "${i}" "${failed_hosts}"; then + echo -e "${CRESET} [${RED}x${CRESET}] ${url}${RED}" + else + echo -e "${CRESET} [${GREEN}✓${CRESET}] ${url}${RED}" + fi + done + echo -e "${RED} " + echo "Make sure you have a working internet connection, that you " + echo "restarted after installing VirtualBox and Vagrant, and that " + echo "they aren't blocked by a firewall or security software." + echo "If you can load the address in your browser, then VVV should" + echo "be able to connect." + echo " " + echo "Also note that some users have reported issues when combined" + echo "with VPNs, disable your VPN and reprovision to see if this is" + echo "the cause." + echo " " + echo "Additionally, if you're at a contributor day event, be kind," + echo "provisioning involves downloading things, a full provision may " + echo "ruin the wifi for everybody else :(" + echo " " + echo "Network ifconfig output:" + echo " " + ifconfig + echo -e "${RED} " + echo "Aborting provision. " + echo "Try provisioning again once network connectivity is restored." + echo "If that doesn't work, and you're sure you have a strong " + echo "internet connection, open an issue on GitHub, and include the " + echo "output above so that the problem can be debugged" + echo " " + echo "vagrant reload --provision" + echo " " + echo "https://github.com/Varying-Vagrant-Vagrants/VVV/issues" + echo " " + vvv_error "#################################################################" + return 1 + fi + vvv_success " * Network checks succeeded" + return 0 +} +export -f network_check + +function log_to_file() { + local date_time=$(cat /vagrant/provisioned_at) + local logfolder="/var/log/provisioners/${date_time}" + local logfile="${logfolder}/${1}.log" + mkdir -p "${logfolder}" + touch "${logfile}" + # reset output otherwise it will log to previous files. from backup made in provisioners.sh + exec 1>&6 + exec 2>&7 + # pipe to file + if [[ "${1}" == "provisioner-main" ]]; then + exec > >( tee -a "${logfile}" ) # main provisioner outputs everything + else + exec > >( tee -a "${logfile}" >/dev/null ) # others, only stderr + fi + exec 2> >( tee -a "${logfile}" >&2 ) + VVV_CURRENT_LOG_FILE="${logfile}" +} +export -f log_to_file + +function noroot() { + sudo -EH -u "vagrant" "$@"; +} +export -f noroot + +function vvv_info() { + echo -e "${CRESET}${1}${CRESET}" + if [ "${VVV_LOG}" != "main" ]; then + >&6 echo -e "${CRESET}${1}${CRESET}" + fi +} +export -f vvv_info + +function vvv_error() { + echo -e "${RED}${1}${CRESET}" +} +export -f vvv_error + +function vvv_warn() { + echo -e "${YELLOW}${1}${CRESET}" + if [ "${VVV_LOG}" != "main" ]; then + >&6 echo -e "${YELLOW}${1}${CRESET}" + fi +} +export -f vvv_warn + +function vvv_success() { + echo -e "${GREEN}${1}${CRESET}" + if [ "${VVV_LOG}" != "main" ]; then + >&6 echo -e "${GREEN}${1}${CRESET}" + fi +} +export -f vvv_success + +function get_config_value() { + local value=$(shyaml get-value "${1}" 2> /dev/null < "${VVV_CONFIG}") + echo "${value:-$2}" +} +export -f get_config_value + +function get_config_values() { + local value=$(shyaml get-values "${1}" 2> /dev/null < "${VVV_CONFIG}") + echo "${value:-$2}" +} +export -f get_config_values + +function get_config_type() { + local value=$(shyaml get-type "${1}" 2> /dev/null < "${VVV_CONFIG}") + echo "${value}" +} +export -f get_config_type + +function get_config_keys() { + local value=$(shyaml keys "${1}" 2> /dev/null < "${VVV_CONFIG}") + echo "${value:-$2}" +} +export -f get_config_keys diff --git a/provision/provision-network-functions.sh b/provision/provision-network-functions.sh deleted file mode 100644 index 9edbb1a78..000000000 --- a/provision/provision-network-functions.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -# -# provision-network-functions.sh -# -# This file is for common network helper functions that get called in -# other provisioners - -GREEN="\033[38;5;2m" -RED="\033[38;5;9m" -CRESET="\033[0m" - -network_detection() { - echo " * Testing network connection" - # Network Detection - # - # Make an HTTP request to ppa.launchpad.net to determine if outside access is available - # to us. If 3 attempts with a timeout of 5 seconds are not successful, then we'll - # skip a few things further in provisioning rather than create a bunch of errors. - if [[ "$(wget --tries=3 --timeout=10 --spider --recursive --level=2 https://ppa.launchpad.net 2>&1 | grep 'connected')" ]]; then - echo -e "${GREEN} * Succesful Network connection to ppa.launchpad.net detected...${CRESET}" - ping_result="Connected" - else - echo -e "${RED} ! Network connection not detected. Unable to reach ppa.launchpad.net...${CRESET}" - ping_result="Not Connected" - fi -} - -network_check() { - network_detection - if [[ ! "$ping_result" == "Connected" ]]; then - echo -e "${RED} " - echo "#################################################################" - echo " " - echo "Problem:" - echo " " - echo "Provisioning needs a network connection but none was found." - echo "VVV tried to ping ppa.launchpad.net, and got no response." - echo " " - echo "Make sure you have a working internet connection, that you " - echo "restarted after installing VirtualBox and Vagrant, and that " - echo "they aren't blocked by a firewall or security software. If" - echo "you can load https://ppa.launchpad.net in your browser, then VVV" - echo "should be able to connect." - echo " " - echo "Also note that some users have reported issues when combined" - echo "with VPNs, disable your VPN and reprovision to see if this is" - echo "the cause." - echo " " - echo "Additionally, if you're at a contributor day event, be kind," - echo "provisioning involves downloading things, a full provision may " - echo "ruin the wifi for everybody else :(" - echo " " - echo "Network ifconfig output:" - echo " " - ifconfig - echo " " - echo "No network connection available, aborting provision. Try " - echo "provisioning again once network connectivity is restored." - echo "If that doesn't work, and you're sure you have a strong " - echo "internet connection, open an issue on GitHub, and include the " - echo "output above so that the problem can be debugged" - echo " " - echo "vagrant reload --provision" - echo " " - echo "https://github.com/Varying-Vagrant-Vagrants/VVV/issues" - echo " " - echo "#################################################################${CRESET}" - - exit 1 - fi -} diff --git a/provision/provision-site.sh b/provision/provision-site.sh index 097f187f0..45480a3aa 100644 --- a/provision/provision-site.sh +++ b/provision/provision-site.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +. "/srv/provision/provisioners.sh" + SITE=$1 SITE_ESCAPED="${SITE//./\\.}" REPO=$2 @@ -10,47 +12,33 @@ NGINX_UPSTREAM=$6 VVV_PATH_TO_SITE=${VM_DIR} # used in site templates VVV_SITE_NAME=${SITE} -GREEN="\033[38;5;2m" -RED="\033[38;5;9m" -YELLOW="\033[38;5;3m" -CRESET="\033[0m" + + +SUCCESS=1 # By storing the date now, we can calculate the duration of provisioning at the # end of this script. -start_seconds="$(date +%s)" - -date_time=$(cat /vagrant/provisioned_at) -logfolder="/var/log/provisioners/${date_time}" -logfile="${logfolder}/provisioner-site-${SITE}.log" -mkdir -p "${logfolder}" -touch "${logfile}" -exec > >(tee -a "${logfile}" ) -exec 2> >(tee -a "${logfile}" >&2 ) VVV_CONFIG=/vagrant/config.yml -noroot() { - sudo -EH -u "vagrant" "$@"; -} - # Takes 2 values, a key to fetch a value for, and an optional default value # e.g. echo $(get_config_value 'key' 'defaultvalue') -get_config_value() { +function get_config_value() { local value=$(shyaml get-value "sites.${SITE_ESCAPED}.custom.${1}" 2> /dev/null < ${VVV_CONFIG}) echo "${value:-$2}" } -get_hosts() { +function get_hosts() { local value=$(shyaml get-values-0 "sites.${SITE_ESCAPED}.hosts" 2> /dev/null < ${VVV_CONFIG} | tr '\0' ' ' | sed 's/ *$//') echo "${value:-$@}" } -get_primary_host() { +function get_primary_host() { local value=$(shyaml get-value "sites.${SITE_ESCAPED}.hosts.0" 2> /dev/null < ${VVV_CONFIG}) echo "${value:-$1}" } -function vvv_provision_site_nginx() { +function vvv_provision_site_nginx_config() { SITE_NGINX_FILE=$2 DEST_NGINX_FILE=${SITE_NGINX_FILE//\/srv\/www\//} DEST_NGINX_FILE=${DEST_NGINX_FILE//\//\-} @@ -68,17 +56,17 @@ function vvv_provision_site_nginx() { sed -i "s#{vvv_hosts}#${VVV_HOSTS}#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" if [ 'php' != "${NGINX_UPSTREAM}" ] && [ ! -f "/etc/nginx/upstreams/${NGINX_UPSTREAM}.conf" ]; then - echo -e "${YELLOW} * Upstream value '${NGINX_UPSTREAM}' doesn't match a valid upstream. Defaulting to 'php'.${CRESET}" + vvv_warn " * Upstream value '${NGINX_UPSTREAM}' doesn't match a valid upstream. Defaulting to 'php'.${CRESET}" NGINX_UPSTREAM='php' fi sed -i "s#{upstream}#${NGINX_UPSTREAM}#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" - if [[ $(/srv/config/homebin/is_utility_installed core tls-ca) ]]; then + if /srv/config/homebin/is_utility_installed core tls-ca; then sed -i "s#{vvv_tls_cert}#ssl_certificate /srv/certificates/${VVV_SITE_NAME}/dev.crt;#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" sed -i "s#{vvv_tls_key}#ssl_certificate_key /srv/certificates/${VVV_SITE_NAME}/dev.key;#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" else - sed -i "s#{vvv_tls_cert}##" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" - sed -i "s#{vvv_tls_key}##" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" + sed -i "s#{vvv_tls_cert}#\# TLS cert not included as the core tls-ca is not installed#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" + sed -i "s#{vvv_tls_key}## TLS key not included as the core tls-ca is not installed#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}" fi # Resolve relative paths since not supported in Nginx root. @@ -101,149 +89,159 @@ function vvv_provision_hosts_file() { done } -if [[ true == "${SKIP_PROVISIONING}" ]]; then - echo -e "${YELLOW} * Skipping provisioning of ${SITE}${CRESET}" - return -fi - -echo -e "${GREEN} * Running provisioner for site ${SITE}${CRESET}" - -if [[ false != "${REPO}" ]]; then - if [[ -d "${VM_DIR}" ]] && [[ ! -z "$(ls -A "${VM_DIR}")" ]]; then - if [[ -d "${VM_DIR}/.git" ]]; then - echo " * Updating ${SITE} in ${VM_DIR}..." - cd "${VM_DIR}" - git reset "origin/${BRANCH}" --hard -q - git pull origin "${BRANCH}" -q - git checkout "${BRANCH}" -q +function vvv_process_site_hosts() { + # Parse any vvv-hosts file located in the site repository for domains to + # be added to the virtual machine's host file so that it is self aware. + # + # Domains should be entered on new lines. + echo " * Adding domains to the virtual machine's /etc/hosts file..." + hosts=$(shyaml get-values "sites.${SITE_ESCAPED}.hosts" 2> /dev/null < ${VVV_CONFIG}) + if [ ${#hosts[@]} -eq 0 ]; then + echo " * No hosts were found in the VVV config, falling back to vvv-hosts" + if [[ -f "${VM_DIR}/.vvv/vvv-hosts" ]]; then + vvv_success " * Found a .vvv/vvv-hosts file" + vvv_provision_hosts_file "${SITE}" "${VM_DIR}/.vvv/vvv-hosts" + elif [[ -f "${VM_DIR}/provision/vvv-hosts" ]]; then + vvv_success " * Found a provision/vvv-hosts file" + vvv_provision_hosts_file "${SITE}" "${VM_DIR}/provision/vvv-hosts" + elif [[ -f "${VM_DIR}/vvv-hosts" ]]; then + vvv_success " * Found a vvv-hosts file" + vvv_provision_hosts_file "${SITE}" "${VM_DIR}/vvv-hosts" else - echo "${RED}Problem! A site folder for ${SITE} was found at ${VM_DIR} that doesn't use a site template, but a site template is defined in the config file. Either the config file is mistaken, or a previous attempt to provision has failed, VVV will not try to git clone the site template to avoid data destruction, either remove the folder, or fix the config/config.yml entry${CRESET}" + echo " * Searching subfolders 4 levels down for a vvv-hosts file ( this can be skipped by using ./vvv-hosts, .vvv/vvv-hosts, or provision/vvv-hosts" + HOST_FILES=$(find "${VM_DIR}" -maxdepth 4 -name 'vvv-hosts'); + if [[ -z $HOST_FILES ]] ; then + vvv_error " ! Warning: No vvv-hosts file was found, and no hosts were defined in the vvv config, this site may be inaccessible" + else + for HOST_FILE in $HOST_FILES; do + vvv_provision_hosts_file "$HOST_FILE" + done + fi fi else - # Clone or pull the site repository - echo -e " * Downloading ${SITE}, git cloning from ${REPO} into ${VM_DIR}" - git clone --recursive --branch "${BRANCH}" "${REPO}" "${VM_DIR}" -q - if [ $? -eq 0 ]; then - echo " * ${SITE} Site Template clone succesful" + echo " * Adding hosts from the VVV config entry" + for line in $(shyaml get-values "sites.${SITE_ESCAPED}.hosts" 2> /dev/null < ${VVV_CONFIG}); do + if [[ -z "$(grep -q "^127.0.0.1 $line$" /etc/hosts)" ]]; then + echo "127.0.0.1 ${line} # vvv-auto" >> "/etc/hosts" + echo " - Added ${line} from ${VVV_CONFIG}" + fi + done + fi +} + +function vvv_provision_site_repo() { + if [[ false != "${REPO}" ]]; then + if [[ -d "${VM_DIR}" ]] && [[ ! -z "$(ls -A "${VM_DIR}")" ]]; then + if [[ -d "${VM_DIR}/.git" ]]; then + echo " * Updating ${SITE} in ${VM_DIR}..." + cd "${VM_DIR}" + git reset "origin/${BRANCH}" --hard -q + git pull origin "${BRANCH}" -q + git checkout "${BRANCH}" -q + else + echo "${RED}Problem! A site folder for ${SITE} was found at ${VM_DIR} that doesn't use a site template, but a site template is defined in the config file. Either the config file is mistaken, or a previous attempt to provision has failed, VVV will not try to git clone the site template to avoid data destruction, either remove the folder, or fix the config/config.yml entry${CRESET}" + fi else - echo "${RED} ! Git failed to clone the site template for ${SITE}. It tried to clone the ${BRANCH} of ${REPO} into ${VM_DIR}${CRESET}" - echo "${RED} ! VVV won't be able to provision ${SITE} without the template. Check that you have permission to access the repo, and that the filesystem is writable${CRESET}" - exit 1 + # Clone or pull the site repository + echo -e " * Downloading ${SITE}, git cloning from ${REPO} into ${VM_DIR}" + git clone --recursive --branch "${BRANCH}" "${REPO}" "${VM_DIR}" -q + if [ $? -eq 0 ]; then + echo " * ${SITE} Site Template clone successful" + else + echo "${RED} ! Git failed to clone the site template for ${SITE}. It tried to clone the ${BRANCH} of ${REPO} into ${VM_DIR}${CRESET}" + echo "${RED} ! VVV won't be able to provision ${SITE} without the template. Check that you have permission to access the repo, and that the filesystem is writable${CRESET}" + exit 1 + fi + fi + else + echo " * The site: '${SITE}' does not have a site template, assuming custom provision/vvv-init.sh and provision/vvv-nginx.conf" + if [[ ! -d "${VM_DIR}" ]]; then + echo "${RED} ! Error: The '${SITE}' has no folder, VVV does not create the folder for you, or set up the Nginx configs. Use a site template or create the folder and provisioner files, then reprovision VVV${CRESET}" fi fi -else - echo " * The site: '${SITE}' does not have a site template, assuming custom provision/vvv-init.sh and provision/vvv-nginx.conf" - if [[ ! -d "${VM_DIR}" ]]; then - echo "${RED} ! Error: The '${SITE}' has no folder, VVV does not create the folder for you, or set up the Nginx configs. Use a site template or create the folder and provisioner files, then reprovision VVV${CRESET}" - fi -fi - -if [[ ! -d "${VM_DIR}" ]]; then - echo "${RED} ! Error: The ${VM_DIR} folder does not exist, there is nothing to provision for the '${SITE}' site! ${CRESET}" -fi +} function vvv_run_site_template_script() { echo " * Found ${1} at ${2}/${1}" - echo " * Script output will be logged to: log/provisioners/${date_time}/provisioner-site-${SITE}.log" - ( cd "${2}" && source "${1}" >> "$logfile" ) + ( cd "${2}" && source "${1}" ) if [ $? -eq 0 ]; then - echo -e "${GREEN} * Site provisioner script finished successfully${CRESET}" return 0 else - echo -e "${RED}---------------------------------------------${CRESET}\n\n${RED}! Site provisioner failed! Check the full log for more details${CRESET}\n\n${RED}---------------------------------------------${CRESET}" >&2 return 1 fi } -SUCCESS=1 -# Look for site setup scripts -echo " * Searching for a site template provisioner, vvv-init.sh" -if [[ -f "${VM_DIR}/.vvv/vvv-init.sh" ]]; then - vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}/.vvv" - SUCCESS=$? -elif [[ -f "${VM_DIR}/provision/vvv-init.sh" ]]; then - vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}/provision" - SUCCESS=$? -elif [[ -f "${VM_DIR}/vvv-init.sh" ]]; then - vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}" - SUCCESS=$? -else - echo " * Warning: A site provisioner was not found at .vvv/vvv-init.conf provision/vvv-init.conf or vvv-init.conf, searching 3 folders down, please be patient..." - SITE_INIT_SCRIPTS=$(find "${VM_DIR}" -maxdepth 3 -name 'vvv-init.conf'); - if [[ -z $SITE_INIT_SCRIPTS ]] ; then - echo " * Warning: No site provisioner was found, VVV could not perform any scripted setup that might install software for this site" - else - for SITE_INIT_SCRIPT in $SITE_INIT_SCRIPTS; do - DIR="$(dirname "$SITE_INIT_SCRIPT")" - vvv_run_site_template_script "vvv-init.sh" "${DIR}" - done - fi -fi - -# Look for Nginx vhost files, symlink them into the custom sites dir -if [[ -f "${VM_DIR}/.vvv/vvv-nginx.conf" ]]; then - vvv_provision_site_nginx "${SITE}" "${VM_DIR}/.vvv/vvv-nginx.conf" -elif [[ -f "${VM_DIR}/provision/vvv-nginx.conf" ]]; then - vvv_provision_site_nginx "${SITE}" "${VM_DIR}/provision/vvv-nginx.conf" -elif [[ -f "${VM_DIR}/vvv-nginx.conf" ]]; then - vvv_provision_site_nginx "${SITE}" "${VM_DIR}/vvv-nginx.conf" -else - echo " * Warning: An nginx config was not found at .vvv/vvv-nginx.conf provision/vvv-nginx.conf or vvv-nginx.conf, searching 3 folders down, please be patient..." - NGINX_CONFIGS=$(find "${VM_DIR}" -maxdepth 3 -name 'vvv-nginx.conf'); - if [[ -z $NGINX_CONFIGS ]] ; then - echo -e "${RED} ! Warning: No nginx config was found, VVV will not know how to serve this site${CRESET}" +function vvv_provision_site_script() { + # Look for site setup scripts + echo " * Searching for a site template provisioner, vvv-init.sh" + if [[ -f "${VM_DIR}/.vvv/vvv-init.sh" ]]; then + vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}/.vvv" + SUCCESS=$? + elif [[ -f "${VM_DIR}/provision/vvv-init.sh" ]]; then + vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}/provision" + SUCCESS=$? + elif [[ -f "${VM_DIR}/vvv-init.sh" ]]; then + vvv_run_site_template_script "vvv-init.sh" "${VM_DIR}" + SUCCESS=$? else - for SITE_CONFIG_FILE in $NGINX_CONFIGS; do - vvv_provision_site_nginx "${SITE}" "${SITE_CONFIG_FILE}" - done + echo " * Warning: A site provisioner was not found at .vvv/vvv-init.conf provision/vvv-init.conf or vvv-init.conf, searching 3 folders down, please be patient..." + SITE_INIT_SCRIPTS=$(find "${VM_DIR}" -maxdepth 3 -name 'vvv-init.conf'); + if [[ -z $SITE_INIT_SCRIPTS ]] ; then + echo " * Warning: No site provisioner was found, VVV could not perform any scripted setup that might install software for this site" + else + for SITE_INIT_SCRIPT in $SITE_INIT_SCRIPTS; do + DIR="$(dirname "$SITE_INIT_SCRIPT")" + vvv_run_site_template_script "vvv-init.sh" "${DIR}" + done + fi fi -fi +} -# Parse any vvv-hosts file located in the site repository for domains to -# be added to the virtual machine's host file so that it is self aware. -# -# Domains should be entered on new lines. -echo " * Adding domains to the virtual machine's /etc/hosts file..." -hosts=$(shyaml get-values "sites.${SITE_ESCAPED}.hosts" 2> /dev/null < ${VVV_CONFIG}) -if [ ${#hosts[@]} -eq 0 ]; then - echo " * No hosts were found in the VVV config, falling back to vvv-hosts" - if [[ -f "${VM_DIR}/.vvv/vvv-hosts" ]]; then - echo -e "${GREEN} * Found a .vvv/vvv-hosts file${CRESET}" - vvv_provision_hosts_file "${SITE}" "${VM_DIR}/.vvv/vvv-hosts" - elif [[ -f "${VM_DIR}/provision/vvv-hosts" ]]; then - echo -e "${GREEN} * Found a provision/vvv-hosts file${CRESET}" - vvv_provision_hosts_file "${SITE}" "${VM_DIR}/provision/vvv-hosts" - elif [[ -f "${VM_DIR}/vvv-hosts" ]]; then - echo -e "${GREEN} * Found a vvv-hosts file${CRESET}" - vvv_provision_hosts_file "${SITE}" "${VM_DIR}/vvv-hosts" +function vvv_provision_site_nginx() { + # Look for Nginx vhost files, symlink them into the custom sites dir + if [[ -f "${VM_DIR}/.vvv/vvv-nginx.conf" ]]; then + vvv_provision_site_nginx_config "${SITE}" "${VM_DIR}/.vvv/vvv-nginx.conf" + elif [[ -f "${VM_DIR}/provision/vvv-nginx.conf" ]]; then + vvv_provision_site_nginx_config "${SITE}" "${VM_DIR}/provision/vvv-nginx.conf" + elif [[ -f "${VM_DIR}/vvv-nginx.conf" ]]; then + vvv_provision_site_nginx_config "${SITE}" "${VM_DIR}/vvv-nginx.conf" else - echo " * Searching subfolders 4 levels down for a vvv-hosts file ( this can be skipped by using ./vvv-hosts, .vvv/vvv-hosts, or provision/vvv-hosts" - HOST_FILES=$(find "${VM_DIR}" -maxdepth 4 -name 'vvv-hosts'); - if [[ -z $HOST_FILES ]] ; then - echo -e "${RED} ! Warning: No vvv-hosts file was found, and no hosts were defined in the vvv config, this site may be inaccessible${CRESET}" + echo " * Warning: An nginx config was not found at .vvv/vvv-nginx.conf provision/vvv-nginx.conf or vvv-nginx.conf, searching 3 folders down, please be patient..." + NGINX_CONFIGS=$(find "${VM_DIR}" -maxdepth 3 -name 'vvv-nginx.conf'); + if [[ -z $NGINX_CONFIGS ]] ; then + vvv_error " ! Warning: No nginx config was found, VVV will not know how to serve this site" else - for HOST_FILE in $HOST_FILES; do - vvv_provision_hosts_file "$HOST_FILE" + for SITE_CONFIG_FILE in $NGINX_CONFIGS; do + vvv_provision_site_nginx_config "${SITE}" "${SITE_CONFIG_FILE}" done fi fi -else - echo " * Adding hosts from the VVV config entry" - for line in $(shyaml get-values "sites.${SITE_ESCAPED}.hosts" 2> /dev/null < ${VVV_CONFIG}); do - if [[ -z "$(grep -q "^127.0.0.1 $line$" /etc/hosts)" ]]; then - echo "127.0.0.1 ${line} # vvv-auto" >> "/etc/hosts" - echo " - Added ${line} from ${VVV_CONFIG}" - fi - done +} + +# ------------------------------- + +if [[ true == "${SKIP_PROVISIONING}" ]]; then + vvv_warn " * Skipping provisioning of ${SITE}${CRESET}" + return 0 +fi + +vvv_provision_site_repo + +if [[ ! -d "${VM_DIR}" ]]; then + echo "${RED} ! Error: The ${VM_DIR} folder does not exist, there is nothing to provision for the '${SITE}' site! ${CRESET}" + return 1 fi +vvv_process_site_hosts +vvv_provision_site_script +vvv_provision_site_nginx + echo " * Reloading Nginx" service nginx reload -end_seconds="$(date +%s)" - -if [ "${SUCCESS}" -eq "0" ]; then - echo -e "${GREEN} * ${SITE} provisioning finished in "$(( end_seconds - start_seconds ))" seconds${CRESET}" -else - echo -e "${RED} ! ${SITE} provisioning had some issues, check the log as the site may not function correctly, provisioning took "$(( end_seconds - start_seconds ))" seconds${CRESET}" +if [ "${SUCCESS}" -ne "0" ]; then + vvv_error " ! ${SITE} provisioning had some issues, check the log as the site may not function correctly." + return 1 fi + +provisioner_success diff --git a/provision/provision-utility-source.sh b/provision/provision-utility-source.sh index 095d16a4d..03c9ce707 100644 --- a/provision/provision-utility-source.sh +++ b/provision/provision-utility-source.sh @@ -1,48 +1,38 @@ #!/usr/bin/env bash +. "/srv/provision/provisioners.sh" + NAME=$1 REPO=$2 BRANCH="${3:-master}" DIR="/srv/provision/utilities/${NAME}" -GREEN="\033[38;5;2m" -RED="\033[38;5;9m" -CRESET="\033[0m" - -date_time=$(cat /vagrant/provisioned_at) -logfolder="/var/log/provisioners/${date_time}" -logfile="${logfolder}/provisioner-utility-source-${NAME}.log" -mkdir -p "${logfolder}" -touch "${logfile}" -exec > >(tee -a "${logfile}" ) -exec 2> >(tee -a "${logfile}" >&2 ) - if [[ false != "${NAME}" && false != "${REPO}" ]]; then # Clone or pull the utility repository if [[ ! -d "${DIR}/.git" ]]; then - echo -e "${GREEN} * Cloning the \"${NAME}\" utility, see \"${REPO}\"${CRESET}" + echo "* Cloning the \"${NAME}\" utility, see \"${REPO}\"" git clone "${REPO}" --branch "${BRANCH}" "${DIR}" -q cd "${DIR}" git checkout "${BRANCH}" -q else - echo -e "${GREEN} * Updating the \"${NAME}\" utility on the \"${BRANCH}\" branch...${CRESET}" + echo -e "* Updating the \"${NAME}\" utility on the \"${BRANCH}\" branch..." cd "${DIR}" git pull origin "${BRANCH}" -q git checkout "${BRANCH}" -q fi else if [[ false == "${NAME}" && false == "${REPO}" ]]; then - echo -e "${RED}Error: VVV tried to provision a utility, but no name or git repo was supplied, double check your config/config.yml file is correct and has the right indentation${CRESET}" + vvv_error "Error: VVV tried to provision a utility, but no name or git repo was supplied, double check your config/config.yml file is correct and has the right indentation" exit 1 fi if [[ false == "${NAME}" ]]; then - echo -e "${RED}Error: While processing a utility, a utility with a blank name was found, with the git repo ${REPO}${CRESET}" + vvv_error "Error: While processing a utility, a utility with a blank name was found, with the git repo ${REPO}" exit 1 fi if [[ false == "${REPO}" ]]; then - echo -e "${RED}Error: While processing the ${NAME} utility, VVV could not find a git repository to clone${CRESET}" + vvv_error "Error: While processing the ${NAME} utility, VVV could not find a git repository to clone" fi fi -exit 0 +provisioner_success diff --git a/provision/provision-utility.sh b/provision/provision-utility.sh index ffbaee2fa..20e14dca3 100644 --- a/provision/provision-utility.sh +++ b/provision/provision-utility.sh @@ -1,32 +1,20 @@ #!/usr/bin/env bash -date_time=$(cat /vagrant/provisioned_at) -logfolder="/var/log/provisioners/${date_time}" -logfile="${logfolder}/provisioner-utility-${1}-${2}.log" -mkdir -p "${logfolder}" -touch "${logfile}" -exec > >(tee -a "${logfile}" ) -exec 2> >(tee -a "${logfile}" >&2 ) - -GREEN="\033[38;5;2m" -RED="\033[38;5;9m" -CRESET="\033[0m" +. "/srv/provision/provisioners.sh" PROVISIONER="/srv/provision/utilities/${1}/${2}/provision.sh" if [[ -f $PROVISIONER ]]; then - echo -e "${GREEN} * Running utility provisioner for '${1}/${2}'${CRESET}" - start_seconds="$(date +%s)" - ( ${PROVISIONER} >> "${logfile}" ) + ( bash "${PROVISIONER}" >> "${VVV_CURRENT_LOG_FILE}" ) SUCCESS=$? - end_seconds="$(date +%s)" if [ "${SUCCESS}" -eq 0 ]; then - echo -e "${GREEN} * The '${1}/${2}' provisioner completed in "$(( end_seconds - start_seconds ))" seconds${CRESET}" - exit 0 + provisioner_success; exit; else - echo -e "${RED} * The '${1}/${2}' provisioner ran into problems, check the full log in log/provisioners/${date_time}/provisioner-utility-${1}-${2}.log for more details! It completed in "$(( end_seconds - start_seconds ))" seconds${CRESET}" exit 1 fi else - echo -e "${RED} ! VVV Tried to run the utility provisioner for '${1}/${2}' but ${PROVISIONER} doesn't exist${CRESET}" + vvv_error " ! VVV Tried to run the utility provisioner for '${1}/${2}' but ${PROVISIONER} doesn't exist." + exit 1 fi + +provisioner_success diff --git a/provision/provision.sh b/provision/provision.sh index 5cd48a434..57cce2b00 100755 --- a/provision/provision.sh +++ b/provision/provision.sh @@ -7,17 +7,27 @@ # or `vagrant reload` are used. It provides all of the default packages and # configurations included with Varying Vagrant Vagrants. -GREEN="\033[38;5;2m" -RED="\033[38;5;9m" -CRESET="\033[0m" - -# By storing the date now, we can calculate the duration of provisioning at the -# end of this script. -start_seconds="$(date +%s)" - # fix no tty warnings in provisioner logs sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile +# add homebin to secure_path setting for sudo, clean first and then append at the end +sed -i -E \ + -e "s|:/srv/config/homebin||" \ + -e "s|/srv/config/homebin:||" \ + -e "s|(.*Defaults.*secure_path.*?\".*?)(\")|\1:/srv/config/homebin\2|" \ + /etc/sudoers + +# add homebin to the default environment, clean first and then append at the end +sed -i -E \ + -e "s|:/srv/config/homebin||" \ + -e "s|/srv/config/homebin:||" \ + -e "s|(.*PATH.*?\".*?)(\")|\1:/srv/config/homebin\2|" \ + /etc/environment + +# source bash_aliases before anything else so that PATH is properly configured on +# this shell session +. "/srv/config/bash_aliases" + export DEBIAN_FRONTEND=noninteractive export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 export COMPOSER_ALLOW_SUPERUSER=1 @@ -25,9 +35,8 @@ export COMPOSER_NO_INTERACTION=1 # cleanup mkdir -p /vagrant - -# change ownership for /vagrant folder -sudo chown -R vagrant:vagrant /vagrant +rm -rf /vagrant/failed_provisioners +mkdir -p /vagrant/failed_provisioners rm -f /vagrant/provisioned_at rm -f /vagrant/version @@ -35,33 +44,29 @@ rm -f /vagrant/vvv-custom.yml rm -f /vagrant/config.yml touch /vagrant/provisioned_at -echo $(date "+%Y%m%d-%H%M%S") > /vagrant/provisioned_at - -date_time=$(cat /vagrant/provisioned_at) -logfolder="/var/log/provisioners/${date_time}" -logfile="${logfolder}/provisioner-main.log" -mkdir -p "${logfolder}" -touch "${logfile}" -exec > >(tee -a "${logfile}" ) -exec 2> >(tee -a "${logfile}" >&2 ) - -echo -e "${GREEN} * Beginning Main VVV Provisioner, if this is the first provision this may take a few minutes${CRESET}" - -if [ -d /srv/provision/resources ]; then - echo " * An old /srv/provision/resources folder was found, removing the deprecated folder ( utilities are stored in /srv/provision/utilitys now )" - rm -rf /srv/provision/resources ## remove deprecated folder -fi +echo $(date "+%Y.%m.%d_%H-%M-%S") > /vagrant/provisioned_at # copy over version and config files cp -f /home/vagrant/version /vagrant cp -f /srv/config/config.yml /vagrant -VVV_CONFIG=/vagrant/config.yml - sudo chmod 0644 /vagrant/config.yml sudo chmod 0644 /vagrant/version sudo chmod 0644 /vagrant/provisioned_at +# change ownership for /vagrant folder +sudo chown -R vagrant:vagrant /vagrant + +export VVV_CONFIG=/vagrant/config.yml + +# initialize provisioner helpers a bit later +. "/srv/provision/provisioners.sh" + +if [ -d /srv/provision/resources ]; then + echo " * An old /srv/provision/resources folder was found, removing the deprecated folder ( utilities are stored in /srv/provision/utilitys now )" + rm -rf /srv/provision/resources ## remove deprecated folder +fi + # symlink the certificates folder for older site templates compat if [[ ! -d /vagrant/certificates ]]; then ln -s /srv/certificates /vagrant/certificates @@ -107,7 +112,7 @@ if [[ $codename == "trusty" ]]; then echo -e "in a while, take the following steps:" echo -e " " echo -e " 1. downgrade back to VVV 2: git fetch --tags && git checkout 2.6.0" - echo -e " 2. turn on the VM but dont provision: vagrant up" + echo -e " 2. turn on the VM but don't provision: vagrant up" echo -e " 3. run the backup DB script: vagrant ssh -c \"db_backup\"" echo -e " 4. turn off the VM: vagrant halt" echo -e " 5. return to VVV 3+: git checkout develop" @@ -129,8 +134,6 @@ if [[ $codename == "trusty" ]]; then exit 1 fi -source /srv/provision/provision-network-functions.sh - # PACKAGE INSTALLATION # # Build a bash array to pass all of the packages we want to install to a single @@ -198,6 +201,7 @@ apt_package_install_list=( colordiff postfix python-pip + lftp # ntp service to keep clock current ntp @@ -243,10 +247,6 @@ git_ppa_check() { fi } -noroot() { - sudo -EH -u "vagrant" "$@"; -} - cleanup_terminal_splash() { # Dastardly Ubuntu tries to be helpful and suggest users update packages # themselves, but this can break things @@ -256,6 +256,9 @@ cleanup_terminal_splash() { if [[ -f /etc/update-motd.d/10-help-text ]]; then rm /etc/update-motd.d/10-help-text fi + if [[ -f /etc/update-motd.d/50-motd-news ]]; then + rm /etc/update-motd.d/50-motd-news + fi if [[ -f /etc/update-motd.d/51-cloudguest ]]; then rm /etc/update-motd.d/51-cloudguest fi @@ -277,7 +280,7 @@ cleanup_terminal_splash() { if [[ -f /etc/update-motd.d/98-cloudguest ]]; then rm /etc/update-motd.d/98-cloudguest fi - cp "/srv/config/update-motd.d/00-vvv-bash-splash" "/etc/update-motd.d/00-vvv-bash-splash" + cp -f "/srv/config/update-motd.d/00-vvv-bash-splash" "/etc/update-motd.d/00-vvv-bash-splash" chmod +x /etc/update-motd.d/00-vvv-bash-splash } @@ -293,10 +296,9 @@ profile_setup() { rm -f "/home/vagrant/.bash_aliases" noroot cp -f "/srv/config/bash_aliases" "/home/vagrant/.bash_aliases" - echo " * Copying /srv/config/bash_aliases to $HOME/.bash_aliases" - rm -f "$HOME/.bash_aliases" - cp -f "/srv/config/bash_aliases" "$HOME/.bash_aliases" - . "$HOME/.bash_aliases" + echo " * Copying /srv/config/bash_aliases to ${HOME}/.bash_aliases" + rm -f "${HOME}/.bash_aliases" + cp -f "/srv/config/bash_aliases" "${HOME}/.bash_aliases" echo " * Copying /srv/config/vimrc to /home/vagrant/.vimrc" rm -f "/home/vagrant/.vimrc" @@ -321,37 +323,14 @@ profile_setup() { noroot cp "/srv/config/bash_prompt" "/home/vagrant/.bash_prompt" fi - echo " * Copying /srv/config/ssh_known_hosts to /etc/ssh/ssh_known_hosts" + echo " * Copying /srv/config/ssh_known_hosts to /etc/ssh/ssh_known_hosts" cp -f /srv/config/ssh_known_hosts /etc/ssh/ssh_known_hosts - echo " * Copying /srv/config/sshd_config to /etc/ssh/sshd_config" + echo " * Copying /srv/config/sshd_config to /etc/ssh/sshd_config" cp -f /srv/config/sshd_config /etc/ssh/sshd_config echo " * Reloading SSH Daemon" systemctl reload ssh } -not_installed() { - dpkg -s "$1" 2>&1 | grep -q 'Version:' - if [[ "$?" -eq 0 ]]; then - apt-cache policy "$1" | grep 'Installed: (none)' - return "$?" - else - return 0 - fi -} - -print_pkg_info() { - local pkg="$1" - local pkg_version="$2" - local space_count - local pack_space_count - local real_space - - space_count="$(( 20 - ${#pkg} ))" #11 - pack_space_count="$(( 30 - ${#pkg_version} ))" - real_space="$(( space_count + pack_space_count + ${#pkg_version} ))" - printf " * $pkg %${real_space}.${#pkg_version}s ${pkg_version}\n" -} - package_install() { # MariaDB/MySQL @@ -377,7 +356,6 @@ package_install() { echo " * adding the mysql user" useradd -u 9001 -g mysql -G vboxsf -r mysql fi - id mysql mkdir -p "/etc/mysql/conf.d" echo " * Copying /srv/config/mysql-config/vvv-core.cnf to /etc/mysql/conf.d/vvv-core.cnf" @@ -441,6 +419,10 @@ package_install() { apt-key add /srv/config/apt-keys/mongo-server-4.0.asc fi + # fix https://github.com/Varying-Vagrant-Vagrants/VVV/issues/2150 + echo " * Cleaning up dpkg lock file" + rm /var/lib/dpkg/lock* + # Update all of the package references before installing anything echo " * Running apt-get update..." apt-get -y update @@ -454,7 +436,7 @@ package_install() { fi # Remove unnecessary packages - echo " * Removing unnecessary packages..." + echo " * Removing unnecessary apt packages..." apt-get autoremove -y # Clean up apt caches @@ -464,19 +446,6 @@ package_install() { return 0 } -# taken from -latest_github_release() { - local LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/$1/releases/latest") # Get latest release from GitHub api - local GITHUB_RELEASE_REGEXP="\"tag_name\": \"([^\"]+)\"" - - if [[ $LATEST_RELEASE =~ $GITHUB_RELEASE_REGEXP ]]; then - echo "${BASH_REMATCH[1]}" - return 0 - fi - - return 1 -} - tools_install() { echo " * Running tools_install" # Disable xdebug before any composer provisioning. @@ -500,20 +469,9 @@ tools_install() { # # Make sure we have the latest npm version and the update checker module echo " * Installing/updating npm..." - npm install -g npm + npm_config_loglevel=error npm install -g npm echo " * Installing/updating npm-check-updates..." - npm install -g npm-check-updates - - # ack-grep - # - # Install ack-rep directory from the version hosted at beyondgrep.com as the - # PPAs for Ubuntu Precise are not available yet. - if [[ -f /usr/bin/ack ]]; then - echo " * ack-grep already installed" - else - echo " * Installing ack-grep as ack" - curl -s https://beyondgrep.com/ack-2.16-single-file > "/usr/bin/ack" && chmod +x "/usr/bin/ack" - fi + npm_config_loglevel=error npm install -g npm-check-updates echo " * Making sure the composer cache is not owned by root" mkdir -p /usr/local/src/composer @@ -532,7 +490,7 @@ tools_install() { mv "composer.phar" "/usr/local/bin/composer" fi - github_token=$(shyaml get-value general.github_token 2> /dev/null < ${VVV_CONFIG}) + github_token=$(shyaml get-value general.github_token 2> /dev/null < "${VVV_CONFIG}") if [[ ! -z $github_token ]]; then rm /srv/provision/github.token echo "$github_token" >> /srv/provision/github.token @@ -555,19 +513,19 @@ tools_install() { function install_grunt() { echo " * Installing Grunt CLI" - npm install -g grunt grunt-cli --no-optional - hack_avoid_gyp_errors & npm install -g grunt-sass --no-optional; touch /tmp/stop_gyp_hack - npm install -g grunt-cssjanus --no-optional - npm install -g grunt-rtlcss --no-optional + npm_config_loglevel=error npm install -g grunt grunt-cli --no-optional + npm_config_loglevel=error hack_avoid_gyp_errors & npm install -g grunt-sass --no-optional; touch /tmp/stop_gyp_hack + npm_config_loglevel=error npm install -g grunt-cssjanus --no-optional + npm_config_loglevel=error npm install -g grunt-rtlcss --no-optional echo " * Installed Grunt CLI" } function update_grunt() { echo " * Updating Grunt CLI" - npm update -g grunt grunt-cli --no-optional - hack_avoid_gyp_errors & npm update -g grunt-sass; touch /tmp/stop_gyp_hack - npm update -g grunt-cssjanus --no-optional - npm update -g grunt-rtlcss --no-optional + npm_config_loglevel=error npm update -g grunt grunt-cli --no-optional + npm_config_loglevel=error hack_avoid_gyp_errors & npm update -g grunt-sass; touch /tmp/stop_gyp_hack + npm_config_loglevel=error npm update -g grunt-cssjanus --no-optional + npm_config_loglevel=error npm update -g grunt-rtlcss --no-optional echo " * Updated Grunt CLI" } # Grunt @@ -614,6 +572,11 @@ tools_install() { nginx_setup() { # Create an SSL key and certificate for HTTPS support. + if [[ ! -e /root/.rnd ]]; then + echo " * Generating Random Number for cert generation..." + vvvgenrnd="$(openssl rand -out /root/.rnd -hex 256 2>&1)" + echo "$vvvgenrnd" + fi if [[ ! -e /etc/nginx/server-2.1.0.key ]]; then echo " * Generating Nginx server private key..." vvvgenrsa="$(openssl genrsa -out /etc/nginx/server-2.1.0.key 2048 2>&1)" @@ -631,10 +594,6 @@ nginx_setup() { echo " * Setup configuration files..." - # Used to ensure proper services are started on `vagrant up` - echo " * Copying /srv/config/init/vvv-start.conf to /etc/init/vvv-start.conf" - cp -f "/srv/config/init/vvv-start.conf" "/etc/init/vvv-start.conf" - # Copy nginx configuration from local echo " * Copying /srv/config/nginx-config/nginx.conf to /etc/nginx/nginx.conf" cp -f "/srv/config/nginx-config/nginx.conf" "/etc/nginx/nginx.conf" @@ -741,55 +700,88 @@ EOL systemctl start mailhog } +check_mysql_root_password() { + echo " * Checking the root user password is root" + mysql -u root --password=root -e "SHOW DATABASES" &> /dev/null + if [ $? -eq 0 ]; then + echo " * The root password is the expected value" + return 0 + fi + echo " * The root password is not root, fixing" + echo " - stopping database" + service mysql stop + echo " - checking /var/run/mysqld" + mkdir -p /var/run/mysqld && chown mysql:mysql /var/run/mysqld + echo " - starting the database in safe mode and updating the root user" + mysqld_safe --skip-grant-tables & + echo " - waiting 2 seconds for database to finish starting" + sleep 2 + echo " - updating the root user" + sql=$( cat <<-SQL + use mysql; + update user set authentication_string=PASSWORD('root') where User='root'; + update user set plugin='mysql_native_password' where User='root'; + flush privileges; +SQL + ) + mysql -uroot -e "${sql}" + echo " - stopping database in safemode" + mysqladmin -u root --password="root" shutdown + echo " - root user password should now be root" +} + mysql_setup() { # If MariaDB/MySQL is installed, go through the various imports and service tasks. local exists_mysql exists_mysql="$(service mysql status)" - if [[ "mysql: unrecognized service" != "${exists_mysql}" ]]; then - echo -e "\n * Setup MySQL configuration file links..." - - # Copy mysql configuration from local - cp "/srv/config/mysql-config/my.cnf" "/etc/mysql/my.cnf" - echo " * Copied /srv/config/mysql-config/my.cnf to /etc/mysql/my.cnf" - - cp "/srv/config/mysql-config/root-my.cnf" "/home/vagrant/.my.cnf" - chmod 0644 "/home/vagrant/.my.cnf" - echo " * Copied /srv/config/mysql-config/root-my.cnf to /home/vagrant/.my.cnf" - - # MySQL gives us an error if we restart a non running service, which - # happens after a `vagrant halt`. Check to see if it's running before - # deciding whether to start or restart. - if [[ "mysql stop/waiting" == "${exists_mysql}" ]]; then - echo " * service mysql start" - service mysql start - else - echo " * service mysql restart" - service mysql restart - fi - - # IMPORT SQL - # - # Create the databases (unique to system) that will be imported with - # the mysqldump files located in database/backups/ - if [[ -f "/srv/database/init-custom.sql" ]]; then - mysql -u "root" -p"root" < "/srv/database/init-custom.sql" - echo -e "\n * Initial custom MySQL scripting..." - else - echo -e "\n * No custom MySQL scripting found in database/init-custom.sql, skipping..." - fi - - # Setup MySQL by importing an init file that creates necessary - # users and databases that our vagrant setup relies on. - mysql -u "root" -p"root" < "/srv/database/init.sql" - echo " * Initial MySQL prep..." - - # Process each mysqldump SQL file in database/backups to import - # an initial data set for MySQL. - "/srv/database/import-sql.sh" + if [[ "mysql: unrecognized service" == "${exists_mysql}" ]]; then + echo -e "\n ! MySQL is not installed. No databases imported." + return + fi + echo -e "\n * Setting up database configuration file links..." + + # Copy mysql configuration from local + cp "/srv/config/mysql-config/my.cnf" "/etc/mysql/my.cnf" + echo " * Copied /srv/config/mysql-config/my.cnf to /etc/mysql/my.cnf" + + cp -f "/srv/config/mysql-config/root-my.cnf" "/home/vagrant/.my.cnf" + chmod 0644 "/home/vagrant/.my.cnf" + echo " * Copied /srv/config/mysql-config/root-my.cnf to /home/vagrant/.my.cnf" + + check_mysql_root_password + + # MySQL gives us an error if we restart a non running service, which + # happens after a `vagrant halt`. Check to see if it's running before + # deciding whether to start or restart. + if [[ "mysql stop/waiting" == "${exists_mysql}" ]]; then + echo " * Starting the mysql service" + service mysql start else - echo -e "\n * MySQL is not installed. No databases imported." + echo " * Restarting mysql service" + service mysql restart fi + + # IMPORT SQL + # + # Create the databases (unique to system) that will be imported with + # the mysqldump files located in database/backups/ + if [[ -f "/srv/database/init-custom.sql" ]]; then + echo " * Running custom init-custom.sql under the root user..." + mysql -u "root" -p"root" < "/srv/database/init-custom.sql" + echo " * init-custom.sql has run" + else + echo -e "\n * No custom MySQL scripting found in database/init-custom.sql, skipping..." + fi + + # Setup MySQL by importing an init file that creates necessary + # users and databases that our vagrant setup relies on. + mysql -u "root" -p"root" < "/srv/database/init.sql" + echo " * Initial MySQL prep..." + + # Process each mysqldump SQL file in database/backups to import + # an initial data set for MySQL. + "/srv/database/import-sql.sh" } services_restart() { @@ -893,7 +885,7 @@ cleanup_vvv(){ sed -n '/# vvv-auto$/!p' /etc/hosts > /tmp/hosts echo "127.0.0.1 vvv # vvv-auto" >> "/etc/hosts" echo "127.0.0.1 vvv.test # vvv-auto" >> "/etc/hosts" - if [[ $(is_utility_installed core tideways) ]]; then + if is_utility_installed core tideways; then echo "127.0.0.1 tideways.vvv.test # vvv-auto" >> "/etc/hosts" echo "127.0.0.1 xhgui.vvv.test # vvv-auto" >> "/etc/hosts" fi @@ -903,31 +895,32 @@ cleanup_vvv(){ ### SCRIPT #set -xv -network_check # Profile_setup echo " * Bash profile setup and directories." cleanup_terminal_splash profile_setup -network_check +if ! network_check; then + exit 1 +fi # Package and Tools Install echo " " echo " * Main packages check and install." git_ppa_check if ! package_install; then - echo -e "${RED} ! Main packages check and install failed, halting provision${CRESET}" + vvv_error " ! Main packages check and install failed, halting provision" exit 1 fi tools_install + +mysql_setup nginx_setup mailhog_setup phpfpm_setup services_restart -mysql_setup -network_check # WP-CLI and debugging tools echo " " echo " * Installing/updating wp-cli and debugging tools" @@ -935,7 +928,9 @@ echo " * Installing/updating wp-cli and debugging tools" wp_cli php_codesniff -network_check +if ! network_check; then + exit 1 +fi # Time for WordPress! echo " " @@ -947,7 +942,5 @@ cleanup_vvv #set +xv # And it's done -end_seconds="$(date +%s)" -echo -e "${GREEN} -----------------------------${CRESET}" -echo -e "${GREEN} * Provisioning complete in "$(( end_seconds - start_seconds ))" seconds${CRESET}" -echo -e "${GREEN} * For further setup instructions, visit http://vvv.test${CRESET}" + +provisioner_success diff --git a/provision/provisioners.sh b/provision/provisioners.sh new file mode 100644 index 000000000..fa2e20830 --- /dev/null +++ b/provision/provisioners.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# don't allow inclusion of this file more than once +if ( type provisioner_begin &>/dev/null ); then + return +fi + +# backup original file descriptors +exec 6>&1 +exec 7>&2 + +source /srv/provision/provision-helpers.sh + +function provisioner_begin() { + VVV_PROVISIONER_RUNNING="${1:-${FUNCNAME[1]}}" + touch "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" + log_to_file "provisioner-${VVV_PROVISIONER_RUNNING}" + vvv_success " ▷ Running the '${VVV_PROVISIONER_RUNNING}' provisioner..." + start_seconds="$(date +%s)" + trap "provisioner_end" EXIT +} + +function provisioner_end() { + PROVISION_SUCCESS="${1:-"1"}" + end_seconds="$(date +%s)" + local elapsed="$(( end_seconds - start_seconds ))" + if [[ $PROVISION_SUCCESS -eq "0" ]]; then + vvv_success " ✔ The '${VVV_PROVISIONER_RUNNING}' provisioner completed in ${elapsed} seconds." + rm -f "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" + else + vvv_error " ! The '${VVV_PROVISIONER_RUNNING}' provisioner ran into problems, check the full log for more details! It completed in ${elapsed} seconds." + fi + echo "" + trap - EXIT +} + +if [[ ! -z $VVV_LOG ]]; then + provisioner_begin "${VVV_LOG}" +fi + +function provisioner_success() { + if [[ ! -z $VVV_LOG ]]; then + provisioner_end 0 + fi +} diff --git a/provision/tests/provisioners.sh b/provision/tests/provisioners.sh new file mode 100644 index 000000000..1e711cf2a --- /dev/null +++ b/provision/tests/provisioners.sh @@ -0,0 +1,147 @@ +#!/bin/bash +. "/srv/provision/provisioners.sh" + +export VVV_LOG="" + +# provisioners + +function pre_hook() { + # provison-pre.sh + # + # acts as a pre-hook to our default provisioning script. Anything that + # should run before the shell commands laid out in provision.sh (or your provision-custom.sh + # file) should go in this script. If it does not exist, no extra provisioning will run. + if [[ -f "/srv/provision/provision-pre.sh" ]]; then + VVV_LOG="pre" + bash /srv/provision/provision-pre.sh + fi +} + +function post_hook() { + # provision-post.sh + # + # acts as a post-hook to the default provisioning. Anything that should + # run after the shell commands laid out in provision.sh or provision-custom.sh should be + # put into this file. This provides a good opportunity to install additional packages + # without having to replace the entire default provisioning script. + if [[ -f "/srv/provision/provision-post.sh" ]]; then + VVV_LOG="post" + bash /srv/provision/provision-post.sh + fi +} + +function provision_dashboard() { + local dashboard_repo=$(get_config_value "dashboard.repo" "https://github.com/Varying-Vagrant-Vagrants/dashboard.git") + local dashboard_branch=$(get_config_value "dashboard.branch" "master") + + VVV_LOG="dashboard" + bash /srv/provision/provision-dashboard.sh "${dashboard_repo}" "${dashboard_branch}" +} + +function provision_utility_sources() { + local name=() + local repo=() + local branch=() + + local key="utility-sources" + + local utilities=$(get_config_type "${key}") + if [[ "${utilities}" == "struct" ]]; then + utilities=($(get_config_keys "${key}")) + else + utilities=$(get_config_value "${key}") + if [[ ! -z "${utilities}" ]]; then + vvv_error "Malformed ${key} config" + fi + utilities=() + fi + + containsElement "core" "${utilities}" + if [[ $? -ne 0 ]]; then + name+=("core") + repo+=("https://github.com/Varying-Vagrant-Vagrants/vvv-utilities.git") + branch+=("master") + fi + + local utility + for utility in "${utilities[@]}"; do + type=$(get_config_type "${key}.${utility}") + name+=(${utility}) + if [[ "${type}" == "str" ]]; then + repo+=($(get_config_value "${key}.${utility}")) + branch+=(master) + else + repo+=($(get_config_value "${key}.${utility}.repo")) + branch+=($(get_config_value "${key}.${utility}.branch" "master")) + fi + done + + local i + for i in ${!name[@]}; do + VVV_LOG="utility-source-${name[$i]}" + bash /srv/provision/provision-utility-source.sh "${name[$i]}" "${repo[$i]}" "${branch[$i]}" + done +} + +function provision_utilities() { + local groups=($(get_config_keys utilities)) + local group + local utility + for group in ${groups[@]}; do + local utilities=($(get_config_values utilities."${group}")) + for utility in ${utilities[@]}; do + provision_utility "${group}" "${utility}" + done + done +} + +function provision_utility() { + local group=$1 + local utility=$2 + VVV_LOG="utility-${group}-${utility}" + bash /srv/provision/provision-utility.sh "${group}" "${utility}" +} + +function provision_sites() { + local sites=($(get_config_keys sites)) + local site + for site in ${sites[@]}; do + provision_site "${site}" + done +} + +function provision_site() { + local site=$1 + local skip_provisioning=$(get_config_value "sites.${site}.skip_provisioning" "False") + if [[ $skip_provisioning == "True" ]]; then + continue + fi + local repo=$(get_config_type "sites.${site}") + if [[ "${repo}" == "str" ]]; then + repo=$(get_config_value "sites.${site}" "") + else + repo=$(get_config_value "sites.${site}.repo" "") + fi + local branch=$(get_config_value "sites.${site}.branch" "master") + local vm_dir=$(get_config_value "sites.${site}.vm_dir" "/srv/www/${site}") + local nginx_upstream=$(get_config_value "sites.${site}.nginx_upstream" "php") + + VVV_LOG="site-${site}" + bash /srv/provision/provision-site.sh "${site}" "${repo}" "${branch}" "${vm_dir}" "${skip_provisioning}" "${nginx_upstream}" +} + +function provision_main() { + # provision.sh or provision-custom.sh + # + # By default, Vagrantfile is set to use the provision.sh bash script located in the + # provision directory. If it is detected that a provision-custom.sh script has been + # created, that is run as a replacement. This is an opportunity to replace the entirety + # of the provisioning provided by default. + if [[ -f "/srv/provision/provision-custom.sh" ]]; then + VVV_LOG="main-custom" + bash /srv/provision/provision-custom.sh + else + VVV_LOG="main" + bash /srv/provision/provision.sh + fi +} diff --git a/provision/tests/run-provisioners.sh b/provision/tests/run-provisioners.sh new file mode 100644 index 000000000..0a2dafb09 --- /dev/null +++ b/provision/tests/run-provisioners.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +. "/srv/provision/tests/provisioners.sh" + +pre_hook +provision_main +provision_dashboard +provision_utility_sources +provision_utilities +provision_sites +post_hook diff --git a/version b/version index 0fa4ae489..8cf6caf56 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.3.0 \ No newline at end of file +3.4.1 \ No newline at end of file