public async Task <ChannelReader <string> > Install(InstallRequest request) { var channel = Channel.CreateUnbounded <string>(); _ = _installerService.Install(request, channel.Writer); return(channel.Reader); }
public async Task Install(InstallRequest installRequest, ChannelWriter <string> writer) { var client = await Connect(installRequest); try { if (string.IsNullOrEmpty(installRequest.DockerBranch)) { installRequest.DockerBranch = "master"; } if (string.IsNullOrEmpty(installRequest.DockerRepositoryUrl)) { installRequest.DockerRepositoryUrl = "https://github.com/btcpayserver/btcpayserver-docker"; } await SendCommandToStream(writer, client, "apt-get update && apt-get install -y git"); await SendCommandToStream(writer, client, "[ -d \"btcpayserver-docker\" ] && rm -r btcpayserver-docker && echo \"Deleted existing folder\"", true); await SendCommandToStream(writer, client, $"git clone {installRequest.DockerRepositoryUrl} btcpayserver-docker -b {installRequest.DockerBranch} "); List <string> commands = new List <string>(); StringBuilder sb = new StringBuilder(); for (var i = 0; i < installRequest.Coins.Count(); i++) { commands.Add($"export BTCPAYGEN_CRYPTO{i + 1}=\"{installRequest.Coins[i]}\""); } commands.Add($"export NBITCOIN_NETWORK=\"{installRequest.Network}\""); commands.Add($"export BTCPAY_HOST=\"{installRequest.BtcpayHost}\""); commands.Add( $"export BTCPAYGEN_REVERSEPROXY=\"{installRequest.ReverseProxy}\""); commands.Add($"export BTCPAYGEN_LIGHTNING=\"{installRequest.Lightning}\""); commands.Add( $"export LIGHTNING_ALIAS=\"{installRequest.LightningAlias}\""); commands.Add( $"export LETSENCRYPT_EMAIL=\"{installRequest.LetsEncryptEmail}\""); commands.Add( $"export BTCPAYGEN_DOCKER_IMAGE=\"{installRequest.BtcpayGeneratorDockerImage}\""); commands.Add( $"export BTCPAY_IMAGE=\"{installRequest.BtcPayDockerImage}\""); commands.Add( $"export LIBREPATRON_HOST=\"{installRequest.LibrePatronHost}\""); commands.Add( $"export WOOCOMMERCE_HOST=\"{installRequest.WoocommerceHost}\""); commands.Add( $"export BTCTRANSMUTER_HOST=\"{installRequest.BtcTransmuterHost}\""); commands.Add( $"export BTCTRANSMUTER_CRYPTOS=\"{string.Join(',',installRequest.Coins)}\""); commands.Add( $"export BTCPAYGEN_ADDITIONAL_FRAGMENTS=\"{string.Join(';', installRequest.AdditionalFragments)}\""); commands.Add( $"export ACME_CA_URI=\"https://acme-v01.api.letsencrypt.org/directory\""); commands.Add( $"ssh-keygen -t rsa -f /root/.ssh/id_rsa_btcpay -q -P \"\""); commands.Add( $"echo \"# Key used by BTCPay Server\" >> /root/.ssh/authorized_keys"); commands.Add( $"cat /root/.ssh/id_rsa_btcpay.pub >> /root/.ssh/authorized_keys"); commands.Add( $"export BTCPAY_HOST_SSHKEYFILE=/root/.ssh/id_rsa_btcpay"); commands.Add($"cd btcpayserver-docker && . ./btcpay-setup.sh -i"); await SendCommandToStream(writer, client, sb.AppendJoin($" && ", commands).ToString()); // // // for (var i = 0; i < installRequest.Coins.Count(); i++) // { // await SendCommandToStream(writer, client, // $"export BTCPAYGEN_CRYPTO{i + 1}=\"{installRequest.Coins[i]}\""); // } // // await SendCommandToStream(writer, client, $"export NBITCOIN_NETWORK=\"{installRequest.Network}\""); // await SendCommandToStream(writer, client, $"export BTCPAY_HOST=\"{installRequest.BtcpayHost}\""); // await SendCommandToStream(writer, client, // $"export BTCPAYGEN_REVERSEPROXY=\"{installRequest.ReverseProxy}\""); // await SendCommandToStream(writer, client, $"export BTCPAYGEN_LIGHTNING=\"{installRequest.Lightning}\""); // // await SendCommandToStream(writer, client, // $"export LIGHTNING_ALIAS=\"{installRequest.LightningAlias}\""); // await SendCommandToStream(writer, client, // $"export LETSENCRYPT_EMAIL=\"{installRequest.LetsEncryptEmail}\""); // await SendCommandToStream(writer, client, // $"export BTCPAYGEN_DOCKER_IMAGE=\"{installRequest.BtcpayGeneratorDockerImage}\""); // await SendCommandToStream(writer, client, // $"export BTCPAY_IMAGE=\"{installRequest.BtcPayDockerImage}\""); // await SendCommandToStream(writer, client, // $"export LIBREPATRON_HOST=\"{installRequest.LibrePatronHost}\""); // await SendCommandToStream(writer, client, // $"export WOOCOMMERCE_HOST=\"{installRequest.WoocommerceHost}\""); // await SendCommandToStream(writer, client, // $"export BTCPAYGEN_ADDITIONAL_FRAGMENTS=\"{string.Join(';', installRequest.AdditionalFragments)}\""); // await SendCommandToStream(writer, client, // $"export ACME_CA_URI=\"https://acme-v01.api.letsencrypt.org/directory\""); // await SendCommandToStream(writer, client, $"ssh-keygen -t rsa -f /root/.ssh/id_rsa_btcpay -q -P \"\" -y"); // await SendCommandToStream(writer, client, // $"echo \"# Key used by BTCPay Server\" >> /root/.ssh/authorized_keys"); // await SendCommandToStream(writer, client, // $"cat /root/.ssh/id_rsa_btcpay.pub >> /root/.ssh/authorized_keys"); // await SendCommandToStream(writer, client, $"export BTCPAY_HOST_SSHKEYFILE=/root/.ssh/id_rsa_btcpay"); // await SendCommandToStream(writer, client, $"cd btcpayserver-docker && . ./btcpay-setup.sh -i"); writer.Complete(); } catch (Exception e) { Console.WriteLine(e); writer.Complete(e); } finally { await Disconnect(client); } }