Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operating system and edition checks (fixes #18) #78

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dev_app.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think of putting these include statements inside the helper scripts that use them instead of in the recipes? Since the helper scripts now have a dependency on CompatibilityChecks it would be best to add the include there or the helper scripts become more fragile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't thought about that (fairly new to PowerShell scripting, more used to Python) but that does make sense


#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_app_desktop_.NET.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_app_desktop_cplusplus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_ml_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_ml_wsl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_web.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "FileExplorerSettings.ps1";
executeScript "SystemConfiguration.ps1";
Expand Down
2 changes: 2 additions & 0 deletions dev_web_nodejs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "SystemConfiguration.ps1";
executeScript "FileExplorerSettings.ps1";
Expand Down
2 changes: 2 additions & 0 deletions devops_azure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function executeScript {
iex ((new-object net.webclient).DownloadString("$helperUri/$script"))
}

executeScript "CompatibilityChecks.ps1";

#--- Setting up Windows ---
executeScript "FileExplorerSettings.ps1";
executeScript "SystemConfiguration.ps1";
Expand Down
78 changes: 78 additions & 0 deletions scripts/CompatibilityChecks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Helper functions for compatibility checks

# Returns $true if running a 64-bit OS.
# TODO: checks for non-x86-based architectures, eg. ARM64
function Is-64Bit
{
return [Environment]::Is64BitOperatingSystem
}

# Returns $true if running on a server edition of Windows.
function Is-Server
{
return ((Get-WmiObject Win32_OperatingSystem).ProductType -gt 1)
}

# Returns $true if system has hardware virtualization enabled.
function Is-Virtualization-Capable
{
return (Get-WmiObject Win32_Processor).VirtualizationFirmwareEnabled
}

# Returns $true if system should be capable of Hyper-V virtualization.
function Is-HyperV-Capable
{
# Ensure we're running on a 64-bit operating system
if(-Not (Is-64Bit)) {
return $false
}

# Ensure hardware virtualization is available and enabled
if(-Not (Is-Virtualization-Capable)) {
return $false
}

# Ensure product SKU supports Hyper-V
# Source for SKU IDs: https://docs.microsoft.com/en-gb/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getproductinfo
if((Get-WmiObject Win32_OperatingSystem).OperatingSystemSKU -NotIn 0x06, 0x10, 0x12, 0x50, 0x8, 0xC, 0x79, 0x7A, 0x04, 0x46, 0x48, 0x1B, 0x54, 0x7D, 0x81, 0x7E, 0x82, 0x0A, 0x0E, 0x2A, 0xA1, 0xA2, 0x30, 0x45, 0x31, 0x67, 0x18, 0x4F, 0x07, 0x0D, 0x01, 0x47, 0x1C)
{
return $false
}

$BuildVersion = [System.Environment]::OSVersion.Version

# Ensure that we're not running on XP
if($BuildVersion.Major -lt '6')
{
return $false
}

# Windows Server 2008/R2 and variants
if($BuildVersion.Major -eq '6' -and $BuildVersion.Minor -lt '2')
{
# Ensure we aren't running on a client edition
if(-Not (Is-Server)) {
return $false
}

return $true
}

# Windows 8/8.1 and Windows Server 2012/R2
if($BuildVersion.Major -ge '6' -and $BuildVersion.Minor -ge '2')
{
# Client Hyper-V requires SLAT
if(-Not (Is-Server)) {
return (Get-WmiObject Win32_Processor).SecondLevelAddressTranslationExtensions
}

return $true
}

# Windows 10 / Windows Server 2016 and later
if($BuildVersion.Major -ge '10')
{
# Ensure SLAT is supported
return (Get-WmiObject Win32_Processor).SecondLevelAddressTranslationExtensions
}
}
13 changes: 9 additions & 4 deletions scripts/Docker.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Enable-WindowsOptionalFeature -Online -FeatureName containers -All
RefreshEnv
choco install -y docker-for-windows
choco install -y vscode-docker
if(
(Is-HyperV-Capable) -and
# Windows 10 Anniversary Update or later
((Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 14393)) {
Enable-WindowsOptionalFeature -Online -FeatureName containers -All
RefreshEnv
choco install -y docker-for-windows
choco install -y vscode-docker
}
5 changes: 4 additions & 1 deletion scripts/HyperV.ps1
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
choco install -y Microsoft-Hyper-V-All --source="'windowsFeatures'"
# Install Hyper-V
if(Is-HyperV-Capable) {
choco install -y Microsoft-Hyper-V-All --source="'windowsFeatures'"
}
9 changes: 6 additions & 3 deletions scripts/RemoveDefaultApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ $applicationList = @(
"*.AdobePhotoshopExpress"
);

foreach ($app in $applicationList) {
removeApp $app
}
# If on Windows 8 / Server 2012 or later...
if([Environment]::OSVersion.Version -ge (New-Object 'Version' 6,2)) {
foreach ($app in $applicationList) {
removeApp $app
}
}
7 changes: 4 additions & 3 deletions scripts/SystemConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


#--- Enable developer mode on the system ---
Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -Value 1
# (if on Windows 8 / Server 2012 or later)
if([Environment]::OSVersion.Version -ge (New-Object 'Version' 6,2)) {
Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -Value 1
}
59 changes: 34 additions & 25 deletions scripts/WSL.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
choco install -y Microsoft-Windows-Subsystem-Linux --source="'windowsfeatures'"
if (
Copy link
Contributor

@yodurr yodurr Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple suggestions

  1. you can install WSL on some versions of Server: https://docs.microsoft.com/en-us/windows/wsl/install-on-server
  2. With this logic block I think it will be better to put it into a Is-WSL-Capable function in CompabitibilityChecks and use that here. Also a if !Is-WSL-Capable and return is cleaner than putting the rest of the file inside the then { }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yep, this permits FCU and newer Windows Server builds to install WSL
  2. That certainly seems cleaner; could also allow use elsewhere for possible future dependencies on WSL. I'll do that

Copy link

@bcurran3 bcurran3 Nov 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I just looked at the wsl install script, I hope I'm commenting in the right place...trying to be helpful.)

There are some gotchas on the installing the various distros, not all have a simple install options that then return you to the command prompt, thus breaking automation without some extra effort.

You can look at my Chocolatey package install scripts for examples.
https://chocolatey.org/packages/wsl-ubuntu-1804
https://chocolatey.org/packages/wsl-ubuntu-1604
https://chocolatey.org/packages/wsl-debiangnulinux
https://chocolatey.org/packages/wsl-kalilinux
https://chocolatey.org/packages/wsl-opensuse
https://chocolatey.org/packages/wsl-archlinux
https://chocolatey.org/packages/wsl-sles

Maybe distros would be better handled by choco install commands? (Yes, I'm open to improvements in my install scripts.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Cross posted from #23 (comment))

I mention this because what I saw in the commit 969035c for SLES and openSUSE won't work based on my experience.

openSUSE REF: https://github.com/bcurran3/ChocolateyPackages/blob/master/wsl-opensuse/tools/ChocolateyInstall.ps1
SLES REF: https://github.com/bcurran3/ChocolateyPackages/blob/master/wsl-sles/tools/ChocolateyInstall.ps1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that WSL requires a reboot before use/installing distros.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bcurran3. I agree the choco install commands make it easier to install the distro. Thank you for taking initiative in making these. I'd like the distro owners to review your choco packages before we add them to this project. I'll discuss with @tara-raj and we can start going through the list of distro owners.

A challenge with installing a WSL distro as part of a boxstarter script is the default user creation so we can also automate the install of tools inside the distro. In the case of Ubuntu we use the default root user with empty password, allowing us to then automate install of packages. After the boxstarter script completes the user is encouraged to then create a new user in Ubuntu with a non-blank password. I see you do the same thing. As long as the user remembers to go in and create a user with a non-blank password and use that as the default then they're back in the same setup as when installing from the Store. It may be possible to improve on this so a choco install and Store install produce the same first run experience - this is a topic I'd love to hear feedback on from the community and distro owners.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving the above comment to issue #32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yodurr I'm game for improvements. My scripts for the installs are not the best, but the best I could do. I welcome feedback/changes/PRs. :)

(Is-64Bit) -and (
(
(
(-Not (Is-Server)) -and (Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 14316
) -or
(Get-WmiObject Win32_OperatingSystem).BuildNumber -ge 16299
)
) {
choco install -y Microsoft-Windows-Subsystem-Linux --source="'windowsfeatures'"

#--- Ubuntu ---
# TODO: Move this to choco install once --root is included in that package
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing
Add-AppxPackage -Path ~/Ubuntu.appx
# run the distro once and have it install locally with root user, unset password
#--- Ubuntu ---
# TODO: Move this to choco install once --root is included in that package
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing
Add-AppxPackage -Path ~/Ubuntu.appx
# run the distro once and have it install locally with root user, unset password

RefreshEnv
Ubuntu1804 install --root
Ubuntu1804 run apt update
Ubuntu1804 run apt upgrade -y
RefreshEnv
Ubuntu1804 install --root
Ubuntu1804 run apt update
Ubuntu1804 run apt upgrade -y

<#
NOTE: Other distros can be scripted the same way for example:
<#
NOTE: Other distros can be scripted the same way for example:

#--- SLES ---
# Install SLES Store app
Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile ~/SLES.appx -UseBasicParsing
Add-AppxPackage -Path ~/SLES.appx
# Launch SLES
sles-12.exe

# --- openSUSE ---
Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile ~/openSUSE.appx -UseBasicParsing
Add-AppxPackage -Path ~/openSUSE.appx
# Launch openSUSE
opensuse-42.exe
#>
#--- SLES ---
# Install SLES Store app
Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile ~/SLES.appx -UseBasicParsing
Add-AppxPackage -Path ~/SLES.appx
# Launch SLES
sles-12.exe

# --- openSUSE ---
Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile ~/openSUSE.appx -UseBasicParsing
Add-AppxPackage -Path ~/openSUSE.appx
# Launch openSUSE
opensuse-42.exe
#>
}