mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
quiet output for setup scripts
This commit is contained in:
parent
14fd7e2801
commit
b6f54324a5
@ -19,7 +19,7 @@ namespace Bit.Setup
|
||||
Url = _context.Config.Url
|
||||
};
|
||||
|
||||
Console.WriteLine("Building FIDO U2F app id.");
|
||||
Helpers.WriteLine(_context, "Building FIDO U2F app id.");
|
||||
Directory.CreateDirectory("/bitwarden/web/");
|
||||
var template = Helpers.ReadTemplate("AppId");
|
||||
using(var sw = File.CreateText("/bitwarden/web/app-id.json"))
|
||||
|
@ -24,12 +24,12 @@ namespace Bit.Setup
|
||||
Directory.CreateDirectory($"/bitwarden/ssl/{_context.Install.Domain}/");
|
||||
var message = "Make sure 'certificate.crt' and 'private.key' are provided in the \n" +
|
||||
"appropriate directory before running 'start' (see docs for info).";
|
||||
Helpers.ShowBanner("NOTE", message);
|
||||
Helpers.ShowBanner(_context, "NOTE", message);
|
||||
}
|
||||
else if(Helpers.ReadQuestion("Do you want to generate a self-signed SSL certificate?"))
|
||||
{
|
||||
Directory.CreateDirectory($"/bitwarden/ssl/self/{_context.Install.Domain}/");
|
||||
Console.WriteLine("Generating self signed SSL certificate.");
|
||||
Helpers.WriteLine(_context, "Generating self signed SSL certificate.");
|
||||
_context.Config.Ssl = true;
|
||||
_context.Install.Trusted = false;
|
||||
_context.Install.SelfSignedCert = true;
|
||||
@ -55,7 +55,7 @@ namespace Bit.Setup
|
||||
"(requires ca.crt, see docs)?");
|
||||
}
|
||||
|
||||
Console.WriteLine("Generating key for IdentityServer.");
|
||||
Helpers.WriteLine(_context, "Generating key for IdentityServer.");
|
||||
_context.Install.IdentityCertPassword = Helpers.SecureRandomString(32, alpha: true, numeric: true);
|
||||
Directory.CreateDirectory("/bitwarden/identity/");
|
||||
Helpers.Exec("openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout identity.key " +
|
||||
@ -63,14 +63,14 @@ namespace Bit.Setup
|
||||
Helpers.Exec("openssl pkcs12 -export -out /bitwarden/identity/identity.pfx -inkey identity.key " +
|
||||
$"-in identity.crt -certfile identity.crt -passout pass:{_context.Install.IdentityCertPassword}");
|
||||
|
||||
Console.WriteLine();
|
||||
Helpers.WriteLine(_context);
|
||||
|
||||
if(!_context.Config.Ssl)
|
||||
{
|
||||
var message = "You are not using a SSL certificate. Bitwarden requires HTTPS to operate. \n" +
|
||||
"You must front your installation with a HTTPS proxy or the web vault (and \n" +
|
||||
"other Bitwarden apps) will not work properly.";
|
||||
Helpers.ShowBanner("WARNING", message, ConsoleColor.Yellow);
|
||||
Helpers.ShowBanner(_context, "WARNING", message, ConsoleColor.Yellow);
|
||||
}
|
||||
else if(_context.Config.Ssl && !_context.Install.Trusted)
|
||||
{
|
||||
@ -78,7 +78,7 @@ namespace Bit.Setup
|
||||
"trusted by Bitwarden client applications. You must add this certificate to \n" +
|
||||
"the trusted store on each device or else you will receive errors when trying \n" +
|
||||
"to connect to your installation.";
|
||||
Helpers.ShowBanner("WARNING", message, ConsoleColor.Yellow);
|
||||
Helpers.ShowBanner(_context, "WARNING", message, ConsoleColor.Yellow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace Bit.Setup
|
||||
private const string ConfigPath = "/bitwarden/config.yml";
|
||||
|
||||
public string[] Args { get; set; }
|
||||
public bool Quiet { get; set; }
|
||||
public IDictionary<string, string> Parameters { get; set; }
|
||||
public string OutputDir { get; set; } = "/etc/bitwarden";
|
||||
public string HostOS { get; set; } = "win";
|
||||
@ -19,17 +20,22 @@ namespace Bit.Setup
|
||||
public Installation Install { get; set; } = new Installation();
|
||||
public Configuration Config { get; set; } = new Configuration();
|
||||
|
||||
public bool PrintToScreen()
|
||||
{
|
||||
return !Quiet || Parameters.ContainsKey("install");
|
||||
}
|
||||
|
||||
public void LoadConfiguration()
|
||||
{
|
||||
if(!File.Exists(ConfigPath))
|
||||
{
|
||||
Console.WriteLine("No existing `config.yml` detected. Let's generate one.");
|
||||
Helpers.WriteLine(this, "No existing `config.yml` detected. Let's generate one.");
|
||||
|
||||
// Looks like updating from older version. Try to create config file.
|
||||
var url = Helpers.GetValueFromEnvFile("global", "globalSettings__baseServiceUri__vault");
|
||||
if(!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
{
|
||||
Console.WriteLine("Unable to determine existing installation url.");
|
||||
Helpers.WriteLine(this, "Unable to determine existing installation url.");
|
||||
return;
|
||||
}
|
||||
Config.Url = url;
|
||||
|
@ -26,10 +26,10 @@ namespace Bit.Setup
|
||||
private void Build()
|
||||
{
|
||||
Directory.CreateDirectory("/bitwarden/docker/");
|
||||
Console.WriteLine("Building docker-compose.yml.");
|
||||
Helpers.WriteLine(_context, "Building docker-compose.yml.");
|
||||
if(!_context.Config.GenerateComposeConfig)
|
||||
{
|
||||
Console.WriteLine("...skipped");
|
||||
Helpers.WriteLine(_context, "...skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace Bit.Setup
|
||||
{
|
||||
var template = Helpers.ReadTemplate("EnvironmentFile");
|
||||
|
||||
Console.WriteLine("Building docker environment files.");
|
||||
Helpers.WriteLine(_context, "Building docker environment files.");
|
||||
Directory.CreateDirectory("/bitwarden/docker/");
|
||||
using(var sw = File.CreateText("/bitwarden/docker/global.env"))
|
||||
{
|
||||
@ -181,7 +181,7 @@ namespace Bit.Setup
|
||||
}
|
||||
Helpers.Exec("chmod 600 /bitwarden/docker/mssql.env");
|
||||
|
||||
Console.WriteLine("Building docker environment override files.");
|
||||
Helpers.WriteLine(_context, "Building docker environment override files.");
|
||||
Directory.CreateDirectory("/bitwarden/env/");
|
||||
using(var sw = File.CreateText("/bitwarden/env/global.override.env"))
|
||||
{
|
||||
|
@ -165,8 +165,12 @@ namespace Bit.Setup
|
||||
return input == "y" || input == "yes";
|
||||
}
|
||||
|
||||
public static void ShowBanner(string title, string message, ConsoleColor? color = null)
|
||||
public static void ShowBanner(Context context, string title, string message, ConsoleColor? color = null)
|
||||
{
|
||||
if(!context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(color != null)
|
||||
{
|
||||
Console.ForegroundColor = color.Value;
|
||||
@ -192,5 +196,34 @@ namespace Bit.Setup
|
||||
return HandlebarsDotNet.Handlebars.Compile(templateText);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLine(Context context, string format = null, object arg0 = null, object arg1 = null,
|
||||
object arg2 = null)
|
||||
{
|
||||
if(!context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(format != null && arg0 != null && arg1 != null && arg2 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0, arg1, arg2);
|
||||
}
|
||||
else if(format != null && arg0 != null && arg1 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0, arg1);
|
||||
}
|
||||
else if(format != null && arg0 != null)
|
||||
{
|
||||
Console.WriteLine(format, arg0);
|
||||
}
|
||||
else if(format != null)
|
||||
{
|
||||
Console.WriteLine(format);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ namespace Bit.Setup
|
||||
private void Build(TemplateModel model)
|
||||
{
|
||||
Directory.CreateDirectory("/bitwarden/nginx/");
|
||||
Console.WriteLine("Building nginx config.");
|
||||
Helpers.WriteLine(_context, "Building nginx config.");
|
||||
if(!_context.Config.GenerateNginxConfig)
|
||||
{
|
||||
Console.WriteLine("...skipped");
|
||||
Helpers.WriteLine(_context, "...skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -14,13 +14,16 @@ namespace Bit.Setup
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine();
|
||||
_context = new Context
|
||||
{
|
||||
Args = args
|
||||
};
|
||||
ParseParameters();
|
||||
|
||||
if(_context.Parameters.ContainsKey("q"))
|
||||
{
|
||||
_context.Quiet = _context.Parameters["q"] == "true" || _context.Parameters["q"] == "1";
|
||||
}
|
||||
if(_context.Parameters.ContainsKey("os"))
|
||||
{
|
||||
_context.HostOS = _context.Parameters["os"];
|
||||
@ -34,6 +37,8 @@ namespace Bit.Setup
|
||||
_context.WebVersion = _context.Parameters["webv"];
|
||||
}
|
||||
|
||||
Helpers.WriteLine(_context);
|
||||
|
||||
if(_context.Parameters.ContainsKey("install"))
|
||||
{
|
||||
Install();
|
||||
@ -48,7 +53,7 @@ namespace Bit.Setup
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No top-level command detected. Exiting...");
|
||||
Helpers.WriteLine(_context, "No top-level command detected. Exiting...");
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,6 +130,10 @@ namespace Bit.Setup
|
||||
private static void PrintEnvironment()
|
||||
{
|
||||
_context.LoadConfiguration();
|
||||
if(!_context.PrintToScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("\nBitwarden is up and running!");
|
||||
Console.WriteLine("===================================================");
|
||||
Console.WriteLine("\nvisit {0}", _context.Config.Url);
|
||||
@ -144,7 +153,7 @@ namespace Bit.Setup
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Migrating database.");
|
||||
Helpers.WriteLine(_context, "Migrating database.");
|
||||
|
||||
var vaultConnectionString = Helpers.GetValueFromEnvFile("global",
|
||||
"globalSettings__sqlServer__connectionString");
|
||||
@ -179,11 +188,11 @@ namespace Bit.Setup
|
||||
var result = upgrader.PerformUpgrade();
|
||||
if(result.Successful)
|
||||
{
|
||||
Console.WriteLine("Migration successful.");
|
||||
Helpers.WriteLine(_context, "Migration successful.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Migration failed.");
|
||||
Helpers.WriteLine(_context, "Migration failed.");
|
||||
}
|
||||
}
|
||||
catch(SqlException e)
|
||||
@ -191,7 +200,7 @@ namespace Bit.Setup
|
||||
if(e.Message.Contains("Server is in script upgrade mode") && attempt < 10)
|
||||
{
|
||||
var nextAttempt = attempt + 1;
|
||||
Console.WriteLine("Database is in script upgrade mode. " +
|
||||
Helpers.WriteLine(_context, "Database is in script upgrade mode. " +
|
||||
"Trying again (attempt #{0})...", nextAttempt);
|
||||
System.Threading.Thread.Sleep(20000);
|
||||
MigrateDatabase(nextAttempt);
|
||||
|
Loading…
Reference in New Issue
Block a user