diff --git a/images/macos/provision/core/apache.sh b/images/macos/provision/core/apache.sh new file mode 100644 index 000000000..08639cba3 --- /dev/null +++ b/images/macos/provision/core/apache.sh @@ -0,0 +1,6 @@ +#!/bin/bash -e -o pipefail + +brew install httpd +sudo sed -Ei '' 's/Listen .*/Listen 80/' $(brew --prefix)/etc/httpd/httpd.conf + +invoke_tests "WebServers" "Apache" diff --git a/images/macos/provision/core/nginx.sh b/images/macos/provision/core/nginx.sh new file mode 100644 index 000000000..616c19eed --- /dev/null +++ b/images/macos/provision/core/nginx.sh @@ -0,0 +1,6 @@ +#!/bin/bash -e -o pipefail + +brew install nginx +sudo sed -Ei '' 's/listen.*/listen 80;/' $(brew --prefix)/etc/nginx/nginx.conf + +invoke_tests "WebServers" "Nginx" diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 6cbb986e4..e3b50aeb4 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -14,6 +14,7 @@ Import-Module "$PSScriptRoot/SoftwareReport.Java.psm1" -DisableNameChecking Import-Module "$PSScriptRoot/SoftwareReport.Xamarin.psm1" -DisableNameChecking Import-Module "$PSScriptRoot/SoftwareReport.Toolcache.psm1" -DisableNameChecking Import-Module "$PSScriptRoot/SoftwareReport.Browsers.psm1" -DisableNameChecking +Import-Module "$PSScriptRoot/SoftwareReport.WebServers.psm1" -DisableNameChecking Import-Module "$PSScriptRoot/../helpers/SoftwareReport.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1" @@ -219,6 +220,11 @@ $markdown += New-MDHeader "PowerShell Modules" -Level 4 $markdown += Get-PowerShellModules | New-MDTable $markdown += New-MDNewLine +# Web Servers +if ($os.IsHigherThanMojave) { + $markdown += Build-WebServersSection +} + # Xamarin section $markdown += New-MDHeader "Xamarin" -Level 3 $markdown += New-MDHeader "Visual Studio for Mac" -Level 4 diff --git a/images/macos/software-report/SoftwareReport.WebServers.psm1 b/images/macos/software-report/SoftwareReport.WebServers.psm1 new file mode 100644 index 000000000..041325538 --- /dev/null +++ b/images/macos/software-report/SoftwareReport.WebServers.psm1 @@ -0,0 +1,41 @@ +function Get-ApacheVersion { + $name = "httpd" + $port = 80 + $version = brew list $name --versions | Take-Part -Part 1 + $serviceStatus = (brew services list) -match $name | Take-Part -Part 1 + $configFile = "$(brew --prefix)/etc/httpd/httpd.conf" + return [PsCustomObject]@{ + "Name" = $name + "Version" = $version + "ConfigFile" = $configFile + "ServiceStatus" = $serviceStatus + "ListenPort" = $port + } +} + +function Get-NginxVersion { + $name = "nginx" + $port = 80 + $version = brew list $name --versions | Take-Part -Part 1 + $serviceStatus = (brew services list) -match $name | Take-Part -Part 1 + $configFile = "$(brew --prefix)/etc/nginx/nginx.conf" + return [PsCustomObject]@{ + "Name" = $name + "Version" = $version + "ConfigFile" = $configFile + "ServiceStatus" = $serviceStatus + "ListenPort" = $port + } +} + +function Build-WebServersSection { + $output = "" + $output += New-MDHeader "Web Servers" -Level 3 + $output += @( + (Get-ApacheVersion), + (Get-NginxVersion) + ) | Sort-Object Name | New-MDTable + + $output += New-MDNewLine + return $output +} diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index 575f109f4..92b2f36c6 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -174,6 +174,8 @@ "./provision/core/xamarin-android-ndk.sh", "./provision/core/vsmac.sh", "./provision/core/nvm.sh", + "./provision/core/apache.sh", + "./provision/core/nginx.sh", "./provision/core/postgresql.sh", "./provision/core/mongodb.sh", "./provision/core/audiodevice.sh", diff --git a/images/macos/templates/macOS-11.0.json b/images/macos/templates/macOS-11.0.json index 943e53d16..fb96ec821 100644 --- a/images/macos/templates/macOS-11.0.json +++ b/images/macos/templates/macOS-11.0.json @@ -173,6 +173,8 @@ "./provision/core/xamarin.sh", "./provision/core/vsmac.sh", "./provision/core/nvm.sh", + "./provision/core/apache.sh", + "./provision/core/nginx.sh", "./provision/core/postgresql.sh", "./provision/core/mongodb.sh", "./provision/core/vcpkg.sh", diff --git a/images/macos/tests/WebServers.Tests.ps1 b/images/macos/tests/WebServers.Tests.ps1 new file mode 100644 index 000000000..5bd1f116d --- /dev/null +++ b/images/macos/tests/WebServers.Tests.ps1 @@ -0,0 +1,19 @@ +Describe "Apache" { + It "Apache CLI" { + "httpd -v" | Should -ReturnZeroExitCode + } + + It "Apache Service" { + brew services list | Out-String | Should -Match "httpd\s+stopped" + } +} + +Describe "Nginx" { + It "Nginx CLI" { + "nginx -v" | Should -ReturnZeroExitCode + } + + It "Nginx Service" { + brew services list | Out-String | Should -Match "nginx\s+stopped" + } +}