diff --git a/packaging/windows/product.wxs.template b/packaging/windows/product.wxs.template
index 20a3b8b921..2afec13731 100755
--- a/packaging/windows/product.wxs.template
+++ b/packaging/windows/product.wxs.template
@@ -92,24 +92,6 @@
Before="AddUserToHypervAdminGroup"
Sequence="execute"/>
-
-
-
-
-
-
NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED
@@ -118,9 +100,6 @@
NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED
NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED
Installed AND NOT UPGRADINGPRODUCTCODE
- NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED
- NOT Installed AND NOT REMOVE~="ALL"
- Installed AND NOT UPGRADINGPRODUCTCODE
NOT Installed AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED
@@ -140,9 +119,6 @@
Installing Hyper-V
Adding user: [LogonUser] to Hyper-V Administrators group
Removing crcDaemon task
- Creating share named: [SHAREDDIRNAME] for folder: [USERFOLDER]
- Removing share named: [SHAREDDIRNAME] for folder: [USERFOLDER]
- Enabling file and printer Sharing
diff --git a/pkg/crc/preflight/labels.go b/pkg/crc/preflight/labels.go
index 0db6483b0e..4733d255cb 100644
--- a/pkg/crc/preflight/labels.go
+++ b/pkg/crc/preflight/labels.go
@@ -11,6 +11,7 @@ type LabelName uint32
const (
Os LabelName = iota
NetworkMode
+ SharedDir
// Keep it last
// will be used in OS-specific go files to extend LabelName
@@ -29,6 +30,10 @@ const (
User
System
+ // shared dir enabled/disable
+ Enabled
+ Disabled
+
// Keep it last
// will be used in OS-specific go files to extend LabelValue
lastLabelValue // nolint
@@ -65,6 +70,14 @@ func (filter preflightFilter) SetNetworkMode(networkMode network.Mode) {
}
}
+func (filter preflightFilter) SetSharedDirStatus(enabled bool) {
+ if enabled {
+ filter[SharedDir] = Enabled
+ return
+ }
+ filter[SharedDir] = Disabled
+}
+
/* This will iterate over 'checks' and only keep the checks which match the filter:
* - if a key is present in the filter and not in the check labels, the check is kept
* - if a key is present in the check labels, but not in the filter, the check is kept
diff --git a/pkg/crc/preflight/preflight.go b/pkg/crc/preflight/preflight.go
index fb729e9dd8..e281ab130a 100644
--- a/pkg/crc/preflight/preflight.go
+++ b/pkg/crc/preflight/preflight.go
@@ -157,8 +157,9 @@ func getPreflightChecksHelper(config crcConfig.Storage) []Check {
bundlePath := config.Get(crcConfig.Bundle).AsString()
preset := crcConfig.GetPreset(config)
enableBundleQuayFallback := config.Get(crcConfig.EnableBundleQuayFallback).AsBool()
+ sharedDirEnabled := config.Get(crcConfig.EnableSharedDirs).AsBool()
logging.Infof("Using bundle path %s", bundlePath)
- return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset, enableBundleQuayFallback)
+ return getPreflightChecks(experimentalFeatures, mode, bundlePath, preset, enableBundleQuayFallback, sharedDirEnabled)
}
// StartPreflightChecks performs the preflight checks before starting the cluster
diff --git a/pkg/crc/preflight/preflight_checks_windows.go b/pkg/crc/preflight/preflight_checks_windows.go
index 3f61aeccce..ee2f7659c5 100644
--- a/pkg/crc/preflight/preflight_checks_windows.go
+++ b/pkg/crc/preflight/preflight_checks_windows.go
@@ -1,7 +1,9 @@
package preflight
import (
+ "errors"
"fmt"
+ "os/user"
"strconv"
"strings"
@@ -209,3 +211,64 @@ func checkAdminHelperNamedPipeAccessible() error {
}
return nil
}
+
+func checkFileAndPrinterSharingIsEnabled() error {
+ cmd := `(Get-NetFirewallRule -Group '@FirewallAPI.dll,-28502' | Where-Object {$_.Profile -eq 'Private, Public'}).Enabled`
+ stdout, stderr, err := powershell.Execute(cmd)
+ if err != nil {
+ return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s", err, stderr)
+ }
+ if strings.Contains(stdout, "False") {
+ return errors.New("Printer and File Sharing is disabled")
+ }
+ return nil
+}
+
+func fixFileAndPrinterSharing() error {
+ cmd := `Set-NetFirewallRule -Group '@FirewallAPI.dll,-28502' -Enabled True -Profile 'Private,Public'`
+ stdout, stderr, err := powershell.ExecuteAsAdmin("to enable Printer and File Sharing", cmd)
+ if err != nil {
+ return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s: %s", err, stdout, stderr)
+ }
+ return nil
+}
+
+func checkCRCSmbShareCreated() error {
+ cmd := `Get-SmbShare -Name crc-dir0`
+ stdout, stderr, err := powershell.Execute(cmd)
+ if err != nil {
+ return fmt.Errorf("unable to check if Printer and File Sharing is enabled %v: %s: %s", err, stdout, stderr)
+ }
+ return nil
+}
+
+func fixCRCSmbShareCreated() error {
+ u, err := user.Current()
+ if err != nil {
+ return fmt.Errorf("unable to get user information for homedir and username: %v", err)
+ }
+ cmd := fmt.Sprintf(`New-SmbShare -Name 'crc-dir0' -Path '%s' -FullAccess '%s'`, u.HomeDir, username())
+ _, stderr, err := powershell.ExecuteAsAdmin("create new SMB share for home directory", cmd)
+ if err != nil {
+ return fmt.Errorf("unable to get create new SMB share %v: %s", err, stderr)
+ }
+ return nil
+}
+
+func removeSmbShare() error {
+ cmd := `Remove-SmbShare -Name 'crc-dir0' -Force`
+ _, stderr, err := powershell.ExecuteAsAdmin("remove SMB share for home directory", cmd)
+ if err != nil {
+ return fmt.Errorf("unable to get create new SMB share %v: %s", err, stderr)
+ }
+ return nil
+}
+
+func removeFirewallRuleAllowingPrinterAndFileSharing() error {
+ cmd := `Set-NetFirewallRule -Group '@FirewallAPI.dll,-28502' -Enabled False -Profile 'Private,Public'`
+ stdout, stderr, err := powershell.ExecuteAsAdmin("to disable Printer and File Sharing", cmd)
+ if err != nil {
+ logging.Warnf("unable to turn off Printer and File Sharing %v: %s: %s", err, stdout, stderr)
+ }
+ return nil
+}
diff --git a/pkg/crc/preflight/preflight_darwin.go b/pkg/crc/preflight/preflight_darwin.go
index 05b419eb23..8052a42e32 100644
--- a/pkg/crc/preflight/preflight_darwin.go
+++ b/pkg/crc/preflight/preflight_darwin.go
@@ -110,7 +110,7 @@ var daemonLaunchdChecks = []Check{
// Passing 'SystemNetworkingMode' to getPreflightChecks currently achieves this
// as there are no user networking specific checks
func getAllPreflightChecks() []Check {
- return getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false)
+ return getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false)
}
func getChecks(_ network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
@@ -132,7 +132,7 @@ func getChecks(_ network.Mode, bundlePath string, preset crcpreset.Preset, enabl
return checks
}
-func getPreflightChecks(_ bool, mode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
+func getPreflightChecks(_ bool, mode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, _ bool) []Check {
filter := newFilter()
filter.SetNetworkMode(mode)
diff --git a/pkg/crc/preflight/preflight_darwin_test.go b/pkg/crc/preflight/preflight_darwin_test.go
index 88a6b47dad..d4aaec857e 100644
--- a/pkg/crc/preflight/preflight_darwin_test.go
+++ b/pkg/crc/preflight/preflight_darwin_test.go
@@ -17,9 +17,9 @@ func TestCountConfigurationOptions(t *testing.T) {
}
func TestCountPreflights(t *testing.T) {
- assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 21)
- assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 21)
+ assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 21)
+ assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 21)
- assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 20)
- assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 20)
+ assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 20)
+ assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 20)
}
diff --git a/pkg/crc/preflight/preflight_linux.go b/pkg/crc/preflight/preflight_linux.go
index 46c7100d39..b0c2683682 100644
--- a/pkg/crc/preflight/preflight_linux.go
+++ b/pkg/crc/preflight/preflight_linux.go
@@ -346,7 +346,7 @@ func getAllPreflightChecks() []Check {
return filter.Apply(getChecks(distro(), constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false))
}
-func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
+func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, _ bool) []Check {
usingSystemdResolved := checkSystemdResolvedIsRunning()
return getPreflightChecksForDistro(distro(), networkMode, usingSystemdResolved == nil, bundlePath, preset, enableBundleQuayFallback)
diff --git a/pkg/crc/preflight/preflight_windows.go b/pkg/crc/preflight/preflight_windows.go
index 03e488a0d1..b9bc7fbacc 100644
--- a/pkg/crc/preflight/preflight_windows.go
+++ b/pkg/crc/preflight/preflight_windows.go
@@ -167,6 +167,32 @@ var userPartOfCrcUsersAndHypervAdminsGroupCheck = Check{
labels: labels{Os: Windows},
}
+// Checks to verify and setup SMB share is created and file sharing is enabled
+var smbShareCreatedAndFileSharingEnabledChecks = []Check{
+ {
+ configKeySuffix: "check-file-sharing-enabled",
+ checkDescription: "Checking if Printer and File Sharing is enabled",
+ check: checkFileAndPrinterSharingIsEnabled,
+ fixDescription: "Enabling Printer and File Sharing",
+ fix: fixFileAndPrinterSharing,
+ cleanupDescription: "Disabling Printer and File Sharing",
+ cleanup: removeFirewallRuleAllowingPrinterAndFileSharing,
+
+ labels: labels{Os: Windows, SharedDir: Enabled},
+ },
+ {
+ configKeySuffix: "check-smb-share-exists",
+ checkDescription: "Checking if SMB share crc-dir0 exists",
+ check: checkCRCSmbShareCreated,
+ fixDescription: "Creating SMB share crc-dir0",
+ fix: fixCRCSmbShareCreated,
+ cleanupDescription: "Removing SMB share crc-dir0",
+ cleanup: removeSmbShare,
+
+ labels: labels{Os: Windows, SharedDir: Enabled},
+ },
+}
+
var errReboot = errors.New("Please reboot your system and run 'crc setup' to complete the setup process")
func username() string {
@@ -202,7 +228,7 @@ func checkVsock() error {
// Passing 'UserNetworkingMode' to getPreflightChecks currently achieves this
// as there are no system networking specific checks
func getAllPreflightChecks() []Check {
- return getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false)
+ return getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, true, true)
}
func getChecks(bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
@@ -219,12 +245,14 @@ func getChecks(bundlePath string, preset crcpreset.Preset, enableBundleQuayFallb
checks = append(checks, daemonTaskChecks...)
checks = append(checks, adminHelperServiceCheks...)
checks = append(checks, sshPortCheck())
+ checks = append(checks, smbShareCreatedAndFileSharingEnabledChecks...)
return checks
}
-func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback bool) []Check {
+func getPreflightChecks(_ bool, networkMode network.Mode, bundlePath string, preset crcpreset.Preset, enableBundleQuayFallback, sharedDirEnabled bool) []Check {
filter := newFilter()
filter.SetNetworkMode(networkMode)
+ filter.SetSharedDirStatus(sharedDirEnabled)
return filter.Apply(getChecks(bundlePath, preset, enableBundleQuayFallback))
}
diff --git a/pkg/crc/preflight/preflight_windows_test.go b/pkg/crc/preflight/preflight_windows_test.go
index 696bfcb890..5759e43778 100644
--- a/pkg/crc/preflight/preflight_windows_test.go
+++ b/pkg/crc/preflight/preflight_windows_test.go
@@ -13,13 +13,19 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage(), config.NewEmptyInMemorySecretStorage())
RegisterSettings(cfg)
- assert.Len(t, cfg.AllConfigs(), 16)
+ assert.Len(t, cfg.AllConfigs(), 18)
}
func TestCountPreflights(t *testing.T) {
- assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23)
- assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 23)
+ assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 23)
+ assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 23)
- assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24)
- assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false), 24)
+ assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 24)
+ assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, false), 24)
+
+ assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 25)
+ assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 25)
+
+ assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 26)
+ assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift, false, true), 26)
}