-
Notifications
You must be signed in to change notification settings - Fork 394
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
base: master
Are you sure you want to change the base?
Changes from all commits
969035c
a5daee4
8ca3b61
f3bad0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
} |
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 | ||
} |
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'" | ||
} |
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
choco install -y Microsoft-Windows-Subsystem-Linux --source="'windowsfeatures'" | ||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple suggestions
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Maybe distros would be better handled by choco install commands? (Yes, I'm open to improvements in my install scripts.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also note that WSL requires a reboot before use/installing distros. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving the above comment to issue #32 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
#> | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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