From 424e0945dbf6aa835daf5cc907e3446854fc80e7 Mon Sep 17 00:00:00 2001 From: autumn Date: Fri, 11 Jun 2021 11:00:57 +0800 Subject: [PATCH] caddy arm issue --- ProxySuper.Core/Services/NaiveProxyProject.cs | 5 +- ProxySuper.Core/Services/ProjectBase.cs | 61 ++++++++++++++----- ProxySuper.Core/Services/TrojanGoProject.cs | 5 +- ProxySuper.Core/Services/XrayProject.cs | 2 + .../ViewModels/XrayInstallerViewModel.cs | 2 - .../Views/NaiveProxyInstallerView.xaml | 1 - .../Views/TrojanGoInstallerView.xaml | 1 - ProxySuper.WPF/Views/XrayInstallerView.xaml | 1 - .../Views/XrayInstallerView.xaml.cs | 1 - 9 files changed, 56 insertions(+), 23 deletions(-) diff --git a/ProxySuper.Core/Services/NaiveProxyProject.cs b/ProxySuper.Core/Services/NaiveProxyProject.cs index 0d25b6b..26d125a 100644 --- a/ProxySuper.Core/Services/NaiveProxyProject.cs +++ b/ProxySuper.Core/Services/NaiveProxyProject.cs @@ -20,7 +20,10 @@ namespace ProxySuper.Core.Services public void Uninstall() { - UninstallCaddy(); + RunCmd("rm -rf caddy_install.sh"); + RunCmd("curl -o caddy_install.sh https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); + RunCmd("yes | bash caddy_install.sh uninstall"); + RunCmd("rm -rf caddy_install.sh"); WriteOutput("ProxyNaive卸载完成"); } diff --git a/ProxySuper.Core/Services/ProjectBase.cs b/ProxySuper.Core/Services/ProjectBase.cs index 3e525b3..970217a 100644 --- a/ProxySuper.Core/Services/ProjectBase.cs +++ b/ProxySuper.Core/Services/ProjectBase.cs @@ -395,10 +395,29 @@ namespace ProxySuper.Core.Services /// protected void InstallCaddy() { - RunCmd("rm -rf caddy_install.sh"); - RunCmd("curl -o caddy_install.sh https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); - RunCmd("yes | bash caddy_install.sh"); - RunCmd("rm -rf caddy_install.sh"); + if (CmdType == CmdType.Apt) + { + RunCmd("sudo apt -y install debian-keyring debian-archive-keyring apt-transport-https"); + RunCmd("echo yes | curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -"); + RunCmd("echo yes | curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list"); + RunCmd("sudo apt -y update"); + RunCmd("sudo apt -y install caddy"); + } + + if (CmdType == CmdType.Dnf) + { + RunCmd("dnf -y install 'dnf-command(copr)'"); + RunCmd("dnf -y copr enable @caddy/caddy"); + RunCmd("dnf -y install caddy"); + } + + if (CmdType == CmdType.Yum) + { + RunCmd("yum -y install yum-plugin-copr"); + RunCmd("yum -y copr enable @caddy/caddy"); + RunCmd("yum -y install caddy"); + } + RunCmd("systemctl enable caddy.service"); } @@ -407,11 +426,25 @@ namespace ProxySuper.Core.Services /// protected void UninstallCaddy() { - RunCmd("rm -rf caddy_install.sh"); - RunCmd("curl -o caddy_install.sh https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); - RunCmd("yes | bash caddy_install.sh uninstall"); - RunCmd("rm -rf caddy_install.sh"); + RunCmd("systemctl stop caddy"); + if (CmdType == CmdType.Apt) + { + RunCmd("sudo apt -y remove caddy"); + } + + if (CmdType == CmdType.Dnf) + { + RunCmd("dnf -y remove caddy"); + } + + if (CmdType == CmdType.Yum) + { + RunCmd("yum -y remove caddy"); + } + + RunCmd("rm -rf /usr/bin/caddy"); RunCmd("rm -rf /usr/share/caddy"); + RunCmd("rm -rf /etc/caddy"); } @@ -435,7 +468,7 @@ namespace ProxySuper.Core.Services if (string.IsNullOrEmpty(IPv6)) { - throw new Exception("未检测可用的的IP地址"); + throw new Exception("未检测到可用的的IP地址"); } OnlyIpv6 = true; @@ -646,12 +679,12 @@ namespace ProxySuper.Core.Services // 申请证书 if (OnlyIpv6) { - var cmd = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {Parameters.Domain} --listen-v6 --pre-hook \"service caddy stop\" --post-hook \"service caddy start\""; + var cmd = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {Parameters.Domain} --listen-v6 --pre-hook \"systemctl stop caddy\" --post-hook \"systemctl start caddy\""; result = RunCmd(cmd); } else { - var cmd = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {Parameters.Domain} --pre-hook \"service caddy stop\" --post-hook \"service caddy start\""; + var cmd = $"/root/.acme.sh/acme.sh --force --debug --issue --standalone -d {Parameters.Domain} --pre-hook \"systemctl stop caddy\" --post-hook \"systemctl start caddy\""; result = RunCmd(cmd); } @@ -730,15 +763,15 @@ namespace ProxySuper.Core.Services { if (CmdType == CmdType.Apt) { - return "echo y | apt-get install " + soft; + return "apt-get -y install " + soft; } else if (CmdType == CmdType.Dnf) { - return "echo y | dnf -y install " + soft; + return "dnf -y install " + soft; } else if (CmdType == CmdType.Yum) { - return "echo y | yum -y install " + soft; + return "yum -y install " + soft; } throw new Exception("未识别的系统"); diff --git a/ProxySuper.Core/Services/TrojanGoProject.cs b/ProxySuper.Core/Services/TrojanGoProject.cs index 4519f0d..554eb60 100644 --- a/ProxySuper.Core/Services/TrojanGoProject.cs +++ b/ProxySuper.Core/Services/TrojanGoProject.cs @@ -48,8 +48,10 @@ namespace ProxySuper.Core.Services public void Uninstall() { + EnsureRootAuth(); + EnsureSystemEnv(); + RunCmd("systemctl stop trojan-go"); - RunCmd("systemctl stop caddy"); base.UninstallCaddy(); RunCmd("rm -rf /usr/local/bin/trojan-go"); @@ -133,7 +135,6 @@ namespace ProxySuper.Core.Services private void InstallTrojanGo() { - WriteOutput("安装Trojan-Go"); RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh yes | bash"); var success = FileExists("/usr/local/bin/trojan-go"); if (success == false) diff --git a/ProxySuper.Core/Services/XrayProject.cs b/ProxySuper.Core/Services/XrayProject.cs index 4dd6043..d57e30c 100644 --- a/ProxySuper.Core/Services/XrayProject.cs +++ b/ProxySuper.Core/Services/XrayProject.cs @@ -105,6 +105,7 @@ namespace ProxySuper.Core.Services public void UninstallProxy() { EnsureRootAuth(); + EnsureSystemEnv(); WriteOutput("卸载Caddy"); UninstallCaddy(); WriteOutput("卸载Xray"); @@ -153,6 +154,7 @@ namespace ProxySuper.Core.Services public void DoUninstallCaddy() { EnsureRootAuth(); + EnsureSystemEnv(); UninstallCaddy(); WriteOutput("************ 卸载Caddy完成 ************"); } diff --git a/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs b/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs index 8074b25..d96a841 100644 --- a/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs @@ -43,7 +43,5 @@ namespace ProxySuper.Core.ViewModels } public string CommandText { get; set; } - - public string OutputText { get; set; } } } diff --git a/ProxySuper.WPF/Views/NaiveProxyInstallerView.xaml b/ProxySuper.WPF/Views/NaiveProxyInstallerView.xaml index 379e94d..5ca4f0c 100644 --- a/ProxySuper.WPF/Views/NaiveProxyInstallerView.xaml +++ b/ProxySuper.WPF/Views/NaiveProxyInstallerView.xaml @@ -23,7 +23,6 @@ VerticalAlignment="Top" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" - Text="{Binding Path=OutputText}" /> diff --git a/ProxySuper.WPF/Views/TrojanGoInstallerView.xaml b/ProxySuper.WPF/Views/TrojanGoInstallerView.xaml index 3dd9fc7..bc9138e 100644 --- a/ProxySuper.WPF/Views/TrojanGoInstallerView.xaml +++ b/ProxySuper.WPF/Views/TrojanGoInstallerView.xaml @@ -23,7 +23,6 @@ VerticalAlignment="Top" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" - Text="{Binding Path=OutputText}" /> diff --git a/ProxySuper.WPF/Views/XrayInstallerView.xaml b/ProxySuper.WPF/Views/XrayInstallerView.xaml index f0461dc..01c380b 100644 --- a/ProxySuper.WPF/Views/XrayInstallerView.xaml +++ b/ProxySuper.WPF/Views/XrayInstallerView.xaml @@ -23,7 +23,6 @@ VerticalAlignment="Top" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" - Text="{Binding Path=OutputText}" /> diff --git a/ProxySuper.WPF/Views/XrayInstallerView.xaml.cs b/ProxySuper.WPF/Views/XrayInstallerView.xaml.cs index feb2632..525dff7 100644 --- a/ProxySuper.WPF/Views/XrayInstallerView.xaml.cs +++ b/ProxySuper.WPF/Views/XrayInstallerView.xaml.cs @@ -76,7 +76,6 @@ namespace ProxySuper.WPF.Views outShell += "\n"; } - ViewModel.OutputText += outShell; Dispatcher.Invoke(() => { OutputTextBox.AppendText(outShell);