diff --git a/scripts/run.ps1 b/scripts/run.ps1 index 1e4ba44c43..a84bfacc38 100644 --- a/scripts/run.ps1 +++ b/scripts/run.ps1 @@ -41,6 +41,11 @@ function Update-Database { echo "Database update complete" } +function Print-Environment { + docker run -it --rm --name setup -v ${outputDir}:/bitwarden bitwarden/setup ` + dotnet Setup.dll -printenv 1 -env win +} + # Commands if($start -Or $restart) { @@ -48,6 +53,7 @@ if($start -Or $restart) { Update-Lets-Encrypt Docker-Compose-Up Docker-Prune + Print-Environment } elseif($stop) { Docker-Compose-Down diff --git a/scripts/run.sh b/scripts/run.sh index cdfca35f44..98dafd7ee1 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -51,6 +51,11 @@ function updateDatabase() { echo "Database update complete" } +function printEnvironment() { + docker run -it --rm --name setup -v $OUTPUT_DIR:/bitwarden bitwarden/setup \ + dotnet Setup.dll -printenv 1 -env $OS +} + # Commands if [ "$1" == "start" -o "$1" == "restart" ] @@ -59,6 +64,7 @@ then updateLetsEncrypt dockerComposeUp dockerPrune + printEnvironment elif [ "$1" == "stop" ] then dockerComposeDown diff --git a/util/Setup/Helpers.cs b/util/Setup/Helpers.cs index 139dcc8009..52936714c3 100644 --- a/util/Setup/Helpers.cs +++ b/util/Setup/Helpers.cs @@ -108,17 +108,17 @@ namespace Setup return builder.ConnectionString; } - public static string GetDatabasePasswordFronEnvFile() + public static string GetValueFronEnvFile(string envFile, string key) { - if(!File.Exists("/bitwarden/env/mssql.override.env")) + if(!File.Exists($"/bitwarden/env/{envFile}.override.env")) { return null; } - var lines = File.ReadAllLines("/bitwarden/env/mssql.override.env"); + var lines = File.ReadAllLines($"/bitwarden/env/{envFile}.override.env"); foreach(var line in lines) { - if(line.StartsWith("SA_PASSWORD=")) + if(line.StartsWith($"{key}=")) { return line.Split(new char[] { '=' }, 2)[1]; } diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index d90ee4e9d9..6a37cf0a1d 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -38,6 +38,10 @@ namespace Setup { Update(); } + else if(_parameters.ContainsKey("printenv")) + { + PrintEnvironment(); + } else { Console.WriteLine("No top-level command detected. Exiting..."); @@ -93,11 +97,29 @@ namespace Setup } } + private static void PrintEnvironment() + { + var vaultUrl = Helpers.GetValueFronEnvFile("global", "globalSettings__baseServiceUri__vault"); + Console.WriteLine("============================"); + Console.WriteLine("bitwarden is up and running!"); + Console.WriteLine("============================"); + Console.WriteLine("visit {0}", vaultUrl); + Console.Write("\nto update, run "); + if(_parameters.ContainsKey("env") && _parameters["env"] == "win") + { + Console.Write(".\bitwarden.ps1 update"); + } + else + { + Console.Write("./bitwarden.sh update"); + } + } + private static void MigrateDatabase() { Console.WriteLine("Migrating database."); - var dbPass = Helpers.GetDatabasePasswordFronEnvFile(); + var dbPass = Helpers.GetValueFronEnvFile("mssql", "SA_PASSWORD"); var masterConnectionString = Helpers.MakeSqlConnectionString("mssql", "master", "sa", dbPass ?? string.Empty); var vaultConnectionString = Helpers.MakeSqlConnectionString("mssql", "vault", "sa", dbPass ?? string.Empty);