/// <summary> /// Install chef to the specified drive /// </summary> /// <param name="installDir"></param> /// <param name="environmentId"></param> public void SelfInstall(string installDir, string environmentId) { if (string.IsNullOrWhiteSpace(environmentId)) { environmentId = Environment.MachineName; } string settingsFile = null; // If chef is already installed, don't let us install!! var environmentSettingsFile = this.GetGlobalStorageVariable("environment-file-path"); if (settingsFile != null) { environmentSettingsFile = settingsFile; } if (File.Exists(environmentSettingsFile)) { this.Logger.LogWarning(false, "Chef already installed. Current config file in: " + environmentSettingsFile); return; } var autosettings = new EnvironmentSettings(); autosettings.id = environmentId; autosettings.contentStorages = new List <StorageLocation>(); autosettings.contentStorages.Add(new StorageLocation() { id = "default", path = Path.Combine(installDir, "_contents") }); autosettings.primaryContentStorage = "default"; autosettings.tempStorages = new List <StorageLocation>(); autosettings.tempStorages.Add(new StorageLocation() { id = "default", path = Path.Combine(installDir, "_temp") }); autosettings.primaryTempStorage = "default"; autosettings.applicationStorages = new List <StorageLocation>(); autosettings.applicationStorages.Add(new StorageLocation() { id = "default", path = Path.Combine(installDir, "_apps") }); autosettings.primaryApplicationStorage = "default"; autosettings.logStorages = new List <StorageLocation>(); autosettings.logStorages.Add(new StorageLocation() { id = "default", path = Path.Combine(installDir, "_log") }); autosettings.primaryLogStorage = "default"; autosettings.defaultApplicationLimits = new ApplicationLimits(); ApplicationLimits.PopulateDefaultsIfMissing(autosettings.defaultApplicationLimits); foreach (var p in autosettings.logStorages) { UtilsSystem.EnsureDir(p.path); } foreach (var p in autosettings.applicationStorages) { UtilsSystem.EnsureDir(p.path); } foreach (var p in autosettings.tempStorages) { UtilsSystem.EnsureDir(p.path); } foreach (var p in autosettings.contentStorages) { UtilsSystem.EnsureDir(p.path); } var settingsDir = Path.Combine(installDir, "_configuration"); var settingsPath = Path.Combine(settingsDir, "config.json"); autosettings.endpoints = new List <NetworkInterface>(); autosettings.endpoints.Add(new NetworkInterface() { forcehosts = true, id = "local", ip = UtilsIis.LOCALHOST_ADDRESS }); // Retrieve the enumerator instance and then the data. SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; this.Logger.LogInfo(false, "Searching for local SQL Server instances..."); System.Data.DataTable table = instance.GetDataSources(); string sqlserverSuffix = string.Empty; foreach (System.Data.DataRow t in table.Rows) { string id = "default" + sqlserverSuffix; string serverName = t["ServerName"] as string; string instanceName = t["InstanceName"] as string; string serverString = serverName; if (!string.IsNullOrWhiteSpace(instanceName)) { serverString += "\\" + instanceName; } var connectionString = $"Server={serverString};Integrated Security = true;"; autosettings.sqlServers = new List <SQLServer>(); autosettings.sqlServers.Add(new SQLServer() { id = id, connectionString = connectionString }); this.Logger.LogInfo(false, "Added server: {0}", connectionString); autosettings.primarySqlServer = id; sqlserverSuffix = autosettings.sqlServers.Count.ToString(); } UtilsSystem.EnsureDir(settingsDir); string serialized = JsonConvert.SerializeObject(autosettings, Formatting.Indented); File.WriteAllText(settingsPath, serialized); this.SetGlobalEnvironmentFilePath(settingsPath); autosettings.installationSalt = Guid.NewGuid().ToString(); this.Logger.LogInfo(true, "Find chef configuration file at: {0}", settingsPath); }