2023-01-10 21:58:41 +01:00
|
|
|
|
using System.Globalization;
|
2022-02-09 17:13:21 +01:00
|
|
|
|
using System.Net.Http.Json;
|
2019-03-25 18:21:05 +01:00
|
|
|
|
using Bit.Migrator;
|
2023-07-31 19:14:33 +02:00
|
|
|
|
using Bit.Setup.Enums;
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2017-09-08 17:45:20 +02:00
|
|
|
|
namespace Bit.Setup;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2017-08-07 22:31:00 +02:00
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
private static Context _context;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2017-08-07 22:31:00 +02:00
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context = new Context
|
2017-08-07 22:31:00 +02:00
|
|
|
|
{
|
2019-07-11 21:03:17 +02:00
|
|
|
|
Args = args
|
2022-08-29 22:06:55 +02:00
|
|
|
|
};
|
2024-03-22 15:54:13 +01:00
|
|
|
|
|
2019-07-11 21:03:17 +02:00
|
|
|
|
ParseParameters();
|
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("q"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.Quiet = _context.Parameters["q"] == "true" || _context.Parameters["q"] == "1";
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("os"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.HostOS = _context.Parameters["os"];
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("corev"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.CoreVersion = _context.Parameters["corev"];
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("webv"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-12-29 17:07:16 +01:00
|
|
|
|
_context.WebVersion = _context.Parameters["webv"];
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-12-29 17:07:16 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("keyconnectorv"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.KeyConnectorVersion = _context.Parameters["keyconnectorv"];
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
2018-08-30 17:35:44 +02:00
|
|
|
|
if (_context.Parameters.ContainsKey("stub"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2019-03-15 14:28:39 +01:00
|
|
|
|
_context.Stub = _context.Parameters["stub"] == "true" ||
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.Parameters["stub"] == "1";
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2018-03-30 15:23:33 +02:00
|
|
|
|
|
2021-12-29 17:07:16 +01:00
|
|
|
|
Helpers.WriteLine(_context);
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("install"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
Install();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
else if (_context.Parameters.ContainsKey("update"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2017-08-19 00:22:25 +02:00
|
|
|
|
Update();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
else if (_context.Parameters.ContainsKey("printenv"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2017-08-24 17:16:01 +02:00
|
|
|
|
PrintEnvironment();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-12 15:26:14 +01:00
|
|
|
|
Helpers.WriteLine(_context, "No top-level command detected. Exiting...");
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-12 15:26:14 +01:00
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
private static void Install()
|
2022-08-29 21:53:48 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("letsencrypt"))
|
2017-08-24 17:16:01 +02:00
|
|
|
|
{
|
|
|
|
|
_context.Config.SslManagedLetsEncrypt =
|
|
|
|
|
_context.Parameters["letsencrypt"].ToLowerInvariant() == "y";
|
|
|
|
|
}
|
2019-03-12 15:26:14 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("domain"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2019-03-12 15:26:14 +01:00
|
|
|
|
_context.Install.Domain = _context.Parameters["domain"].ToLowerInvariant();
|
2017-08-19 00:22:25 +02:00
|
|
|
|
}
|
2021-07-02 16:52:34 +02:00
|
|
|
|
if (_context.Parameters.ContainsKey("dbname"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-07-02 16:52:34 +02:00
|
|
|
|
_context.Install.Database = _context.Parameters["dbname"];
|
2017-08-19 00:22:25 +02:00
|
|
|
|
}
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2021-07-02 16:52:34 +02:00
|
|
|
|
if (_context.Stub)
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
_context.Install.InstallationId = Guid.Empty;
|
2021-07-02 16:52:34 +02:00
|
|
|
|
_context.Install.InstallationKey = "SECRET_INSTALLATION_KEY";
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-07-02 16:52:34 +02:00
|
|
|
|
else if (!ValidateInstallation())
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var certBuilder = new CertBuilder(_context);
|
2021-07-02 16:52:34 +02:00
|
|
|
|
certBuilder.BuildForInstall();
|
2018-08-30 22:09:18 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
// Set the URL
|
|
|
|
|
_context.Config.Url = string.Format("http{0}://{1}",
|
|
|
|
|
_context.Config.Ssl ? "s" : string.Empty, _context.Install.Domain);
|
2017-08-11 14:57:31 +02:00
|
|
|
|
|
2017-11-08 04:35:36 +01:00
|
|
|
|
var nginxBuilder = new NginxConfigBuilder(_context);
|
|
|
|
|
nginxBuilder.BuildForInstaller();
|
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var environmentFileBuilder = new EnvironmentFileBuilder(_context);
|
2017-11-07 04:55:15 +01:00
|
|
|
|
environmentFileBuilder.BuildForInstaller();
|
2017-10-24 04:45:59 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var appIdBuilder = new AppIdBuilder(_context);
|
2017-10-24 04:45:59 +02:00
|
|
|
|
appIdBuilder.Build();
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var dockerComposeBuilder = new DockerComposeBuilder(_context);
|
|
|
|
|
dockerComposeBuilder.BuildForInstaller();
|
|
|
|
|
|
|
|
|
|
_context.SaveConfiguration();
|
2018-08-31 15:16:01 +02:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("\nInstallation complete");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("\nIf you need to make additional configuration changes, you can modify\n" +
|
|
|
|
|
"the settings in `{0}` and then run:\n{1}",
|
|
|
|
|
_context.HostOS == "win" ? ".\\bwdata\\config.yml" : "./bwdata/config.yml",
|
2019-03-25 21:24:16 +01:00
|
|
|
|
_context.HostOS == "win" ? "`.\\bitwarden.ps1 -rebuild` or `.\\bitwarden.ps1 -update`" :
|
2018-08-31 15:16:01 +02:00
|
|
|
|
"`./bitwarden.sh rebuild` or `./bitwarden.sh update`");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("\nNext steps, run:");
|
|
|
|
|
if (_context.HostOS == "win")
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2019-03-25 21:24:16 +01:00
|
|
|
|
Console.WriteLine("`.\\bitwarden.ps1 -start`");
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-31 15:16:01 +02:00
|
|
|
|
Console.WriteLine("`./bitwarden.sh start`");
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-07-14 20:41:15 +02:00
|
|
|
|
Console.WriteLine(string.Empty);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2017-08-19 00:22:25 +02:00
|
|
|
|
private static void Update()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2017-08-19 00:22:25 +02:00
|
|
|
|
// This portion of code checks for multiple certs in the Identity.pfx PKCS12 bag. If found, it generates
|
|
|
|
|
// a new cert and bag to replace the old Identity.pfx. This fixes an issue that came up as a result of
|
2020-03-27 19:36:37 +01:00
|
|
|
|
// moving the project to .NET 5.
|
2017-08-19 00:22:25 +02:00
|
|
|
|
_context.Install.IdentityCertPassword = Helpers.GetValueFromEnvFile("global", "globalSettings__identityServer__certificatePassword");
|
2021-07-14 20:41:15 +02:00
|
|
|
|
var certCountString = Helpers.Exec("openssl pkcs12 -nokeys -info -in /bitwarden/identity/identity.pfx " +
|
|
|
|
|
$"-passin pass:{_context.Install.IdentityCertPassword} 2> /dev/null | grep -c \"\\-----BEGIN CERTIFICATE----\"", true);
|
2018-08-30 22:09:18 +02:00
|
|
|
|
if (int.TryParse(certCountString, out var certCount) && certCount > 1)
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-07-14 20:41:15 +02:00
|
|
|
|
// Extract key from identity.pfx
|
2017-10-24 04:45:59 +02:00
|
|
|
|
Helpers.Exec("openssl pkcs12 -in /bitwarden/identity/identity.pfx -nocerts -nodes -out identity.key " +
|
2018-08-30 22:09:18 +02:00
|
|
|
|
$"-passin pass:{_context.Install.IdentityCertPassword} > /dev/null 2>&1");
|
2021-07-14 20:41:15 +02:00
|
|
|
|
// Extract certificate from identity.pfx
|
2018-08-30 22:09:18 +02:00
|
|
|
|
Helpers.Exec("openssl pkcs12 -in /bitwarden/identity/identity.pfx -clcerts -nokeys -out identity.crt " +
|
2022-08-29 21:53:48 +02:00
|
|
|
|
$"-passin pass:{_context.Install.IdentityCertPassword} > /dev/null 2>&1");
|
2021-07-14 20:41:15 +02:00
|
|
|
|
// Create new PKCS12 bag with certificate and key
|
|
|
|
|
Helpers.Exec("openssl pkcs12 -export -out /bitwarden/identity/identity.pfx -inkey identity.key " +
|
|
|
|
|
$"-in identity.crt -passout pass:{_context.Install.IdentityCertPassword} > /dev/null 2>&1");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("db"))
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2024-03-22 15:54:13 +01:00
|
|
|
|
PrepareAndMigrateDatabase();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2020-03-27 19:36:37 +01:00
|
|
|
|
else
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2017-10-24 04:45:59 +02:00
|
|
|
|
RebuildConfigs();
|
2018-08-31 15:16:01 +02:00
|
|
|
|
}
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
2017-08-19 00:22:25 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
private static void PrintEnvironment()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.LoadConfiguration();
|
|
|
|
|
if (!_context.PrintToScreen())
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
return;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2018-08-30 17:35:44 +02:00
|
|
|
|
Console.WriteLine("\nBitwarden is up and running!");
|
2017-08-24 17:35:16 +02:00
|
|
|
|
Console.WriteLine("===================================================");
|
2018-08-30 17:35:44 +02:00
|
|
|
|
Console.WriteLine("\nvisit {0}", _context.Config.Url);
|
2017-11-09 02:54:39 +01:00
|
|
|
|
Console.Write("to update, run ");
|
2018-08-30 17:35:44 +02:00
|
|
|
|
if (_context.HostOS == "win")
|
2017-08-24 17:16:01 +02:00
|
|
|
|
{
|
2018-08-30 22:09:18 +02:00
|
|
|
|
Console.Write("`.\\bitwarden.ps1 -updateself` and then `.\\bitwarden.ps1 -update`");
|
2017-08-24 17:16:01 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-30 22:09:18 +02:00
|
|
|
|
Console.Write("`./bitwarden.sh updateself` and then `./bitwarden.sh update`");
|
2017-08-24 17:16:01 +02:00
|
|
|
|
}
|
2017-08-24 17:35:16 +02:00
|
|
|
|
Console.WriteLine("\n");
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2022-08-29 21:53:48 +02:00
|
|
|
|
|
2024-03-22 15:54:13 +01:00
|
|
|
|
private static void PrepareAndMigrateDatabase()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2023-03-07 14:10:34 +01:00
|
|
|
|
var vaultConnectionString = Helpers.GetValueFromEnvFile("global",
|
|
|
|
|
"globalSettings__sqlServer__connectionString");
|
2024-03-22 15:54:13 +01:00
|
|
|
|
var migrator = new DbMigrator(vaultConnectionString);
|
2023-09-28 16:29:52 +02:00
|
|
|
|
|
2024-03-22 15:54:13 +01:00
|
|
|
|
var enableLogging = false;
|
2023-09-28 16:29:52 +02:00
|
|
|
|
|
2024-03-22 15:54:13 +01:00
|
|
|
|
// execute all general migration scripts (will detect those not yet applied)
|
|
|
|
|
migrator.MigrateMsSqlDatabaseWithRetries(enableLogging);
|
2023-09-28 16:29:52 +02:00
|
|
|
|
|
2024-03-22 15:54:13 +01:00
|
|
|
|
// execute explicit transition migration scripts, per EDD
|
|
|
|
|
migrator.MigrateMsSqlDatabaseWithRetries(enableLogging, true, MigratorConstants.TransitionMigrationsFolderName);
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-07-02 16:52:34 +02:00
|
|
|
|
|
|
|
|
|
private static bool ValidateInstallation()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-07-02 16:52:34 +02:00
|
|
|
|
var installationId = string.Empty;
|
|
|
|
|
var installationKey = string.Empty;
|
2023-07-31 19:14:33 +02:00
|
|
|
|
CloudRegion cloudRegion;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (_context.Parameters.ContainsKey("install-id"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
installationId = _context.Parameters["install-id"].ToLowerInvariant();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
var prompt = "Enter your installation id (get at https://bitwarden.com/host)";
|
|
|
|
|
installationId = Helpers.ReadInput(prompt);
|
|
|
|
|
while (string.IsNullOrEmpty(installationId))
|
|
|
|
|
{
|
|
|
|
|
Helpers.WriteError("Invalid input for installation id. Please try again.");
|
|
|
|
|
installationId = Helpers.ReadInput(prompt);
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-07-02 16:52:34 +02:00
|
|
|
|
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (!Guid.TryParse(installationId.Trim(), out var installationidGuid))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
Console.WriteLine("Invalid installation id.");
|
|
|
|
|
return false;
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 16:52:34 +02:00
|
|
|
|
if (_context.Parameters.ContainsKey("install-key"))
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-07-02 16:52:34 +02:00
|
|
|
|
installationKey = _context.Parameters["install-key"];
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2021-07-02 16:52:34 +02:00
|
|
|
|
else
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
var prompt = "Enter your installation key";
|
|
|
|
|
installationKey = Helpers.ReadInput(prompt);
|
|
|
|
|
while (string.IsNullOrEmpty(installationKey))
|
|
|
|
|
{
|
|
|
|
|
Helpers.WriteError("Invalid input for installation key. Please try again.");
|
|
|
|
|
installationKey = Helpers.ReadInput(prompt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_context.Parameters.ContainsKey("cloud-region"))
|
|
|
|
|
{
|
|
|
|
|
Enum.TryParse(_context.Parameters["cloud-region"], out cloudRegion);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var prompt = "Enter your region (US/EU) [US]";
|
|
|
|
|
var region = Helpers.ReadInput(prompt);
|
|
|
|
|
if (string.IsNullOrEmpty(region)) region = "US";
|
|
|
|
|
|
|
|
|
|
while (!Enum.TryParse(region, out cloudRegion))
|
|
|
|
|
{
|
|
|
|
|
Helpers.WriteError("Invalid input for region. Please try again.");
|
|
|
|
|
region = Helpers.ReadInput(prompt);
|
|
|
|
|
if (string.IsNullOrEmpty(region)) region = "US";
|
|
|
|
|
}
|
2017-08-19 15:33:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 20:39:27 +02:00
|
|
|
|
_context.Install.InstallationId = installationidGuid;
|
|
|
|
|
_context.Install.InstallationKey = installationKey;
|
2023-07-31 19:14:33 +02:00
|
|
|
|
_context.Install.CloudRegion = cloudRegion;
|
2021-07-02 16:52:34 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
string url;
|
|
|
|
|
switch (cloudRegion)
|
|
|
|
|
{
|
|
|
|
|
case CloudRegion.EU:
|
|
|
|
|
url = "https://api.bitwarden.eu/installations/";
|
|
|
|
|
break;
|
|
|
|
|
case CloudRegion.US:
|
|
|
|
|
default:
|
|
|
|
|
url = "https://api.bitwarden.com/installations/";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
var response = new HttpClient().GetAsync(url + _context.Install.InstallationId).GetAwaiter().GetResult();
|
2017-08-19 15:33:14 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
if (!response.IsSuccessStatusCode)
|
2017-08-19 15:33:14 +02:00
|
|
|
|
{
|
2018-08-30 17:35:44 +02:00
|
|
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
2017-08-19 15:33:14 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
Console.WriteLine($"Invalid installation id for {cloudRegion.ToString()} region.");
|
2017-08-19 15:33:14 +02:00
|
|
|
|
}
|
2022-02-09 17:13:21 +01:00
|
|
|
|
else
|
2017-08-19 15:33:14 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
Console.WriteLine($"Unable to validate installation id for {cloudRegion.ToString()} region.");
|
2017-08-19 15:33:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2017-08-19 15:33:14 +02:00
|
|
|
|
var result = response.Content.ReadFromJsonAsync<InstallationValidationResponseModel>().GetAwaiter().GetResult();
|
2022-02-09 17:13:21 +01:00
|
|
|
|
if (!result.Enabled)
|
2017-08-19 15:33:14 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
Console.WriteLine($"Installation id has been disabled in the {cloudRegion.ToString()} region.");
|
2017-08-19 15:33:14 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-11-07 04:55:15 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
return true;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2018-08-30 17:35:44 +02:00
|
|
|
|
catch
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2023-07-31 19:14:33 +02:00
|
|
|
|
Console.WriteLine($"Unable to validate installation id. Problem contacting Bitwarden {cloudRegion.ToString()} server.");
|
2018-08-30 17:35:44 +02:00
|
|
|
|
return false;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2021-11-16 18:52:02 +01:00
|
|
|
|
private static void RebuildConfigs()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2021-11-16 18:52:02 +01:00
|
|
|
|
_context.LoadConfiguration();
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var environmentFileBuilder = new EnvironmentFileBuilder(_context);
|
2017-10-24 04:45:59 +02:00
|
|
|
|
environmentFileBuilder.BuildForUpdater();
|
2017-08-07 22:31:00 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var certBuilder = new CertBuilder(_context);
|
2017-10-24 04:45:59 +02:00
|
|
|
|
certBuilder.BuildForUpdater();
|
2017-11-06 23:28:02 +01:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var nginxBuilder = new NginxConfigBuilder(_context);
|
2017-11-06 23:28:02 +01:00
|
|
|
|
nginxBuilder.BuildForUpdater();
|
2018-08-30 17:35:44 +02:00
|
|
|
|
|
|
|
|
|
var appIdBuilder = new AppIdBuilder(_context);
|
|
|
|
|
appIdBuilder.Build();
|
2022-08-29 20:53:16 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
var dockerComposeBuilder = new DockerComposeBuilder(_context);
|
|
|
|
|
dockerComposeBuilder.BuildForUpdater();
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
_context.SaveConfiguration();
|
2018-08-31 04:30:31 +02:00
|
|
|
|
Console.WriteLine(string.Empty);
|
2017-08-08 18:29:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 17:35:44 +02:00
|
|
|
|
private static void ParseParameters()
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
_context.Parameters = new Dictionary<string, string>();
|
|
|
|
|
for (var i = 0; i < _context.Args.Length; i = i + 2)
|
2017-08-07 22:31:00 +02:00
|
|
|
|
{
|
2020-03-27 19:36:37 +01:00
|
|
|
|
if (!_context.Args[i].StartsWith("-"))
|
2017-08-07 22:31:00 +02:00
|
|
|
|
{
|
|
|
|
|
continue;
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2022-08-29 20:53:16 +02:00
|
|
|
|
|
2022-02-09 17:13:21 +01:00
|
|
|
|
_context.Parameters.Add(_context.Args[i].Substring(1), _context.Args[i + 1]);
|
2022-08-29 21:53:48 +02:00
|
|
|
|
}
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2022-02-09 17:13:21 +01:00
|
|
|
|
class InstallationValidationResponseModel
|
2022-08-29 22:06:55 +02:00
|
|
|
|
{
|
2022-02-09 17:13:21 +01:00
|
|
|
|
public bool Enabled { get; init; }
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2017-08-07 22:31:00 +02:00
|
|
|
|
}
|