Files
ProjectOctopus/agent-wdd/cmd/Zsh.go
zeaslity 35646ff89f 优化Harbor、Docker和Zsh安装流程,改进命令执行和文件操作
- 重构Harbor安装命令,改进容器检查和启动逻辑
- 修改Docker和DockerCompose安装方法,优化文件移动和权限设置
- 更新Zsh插件安装命令,简化git克隆过程
- 调整UnzipFile工具方法,支持更多压缩文件类型
- 修正Docker Daemon配置文件中的安装节标签
- 更新测试脚本,简化文件上传流程
2025-03-11 15:59:21 +08:00

148 lines
4.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"agent-wdd/config"
"agent-wdd/log"
"agent-wdd/op"
"agent-wdd/utils"
"github.com/spf13/cobra"
)
func addZshSubcommands(cmd *cobra.Command) {
cmd.Run = func(cmd *cobra.Command, args []string) {
log.Info("安装zsh")
// 初始化安装命令
utils.CreateFolder("/root/wdd")
if config.CanConnectInternet() <= 1 {
log.Error("无法连接互联网无法安装zsh")
return
}
// 判定config
if config.ConfigCache.Agent.Network.Public.IPv4 == "" {
network := config.ConfigCache.Agent.Network
network.Gather()
network.SaveConfig()
}
// 下载并安装zsh和git
ok := op.AgentPackOperator.Install([]string{"git", "zsh"})
if !ok {
log.Error("安装git和zsh失败, 无法继续后面的的安装!")
return
}
// 清理残留
utils.RemoveFolderComplete("/root/.oh-my-zsh")
utils.RemoveFolderComplete("/root/wdd/zsh-install.sh")
utils.RemoveFolderComplete("/root/wdd/oh-my-zsh-plugins-list.txt")
ohMyZshInstallUrl := ""
if config.ConfigCache.Agent.Network.Internet == 7 {
ohMyZshInstallUrl = "https://gitea.107421.xyz/zeaslity/ohmyzsh/raw/branch/master/tools/install.sh"
} else {
ohMyZshInstallUrl = "https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh"
}
downloadOk, resultLog := utils.DownloadFile(ohMyZshInstallUrl, "/root/wdd/zsh-install.sh")
if !downloadOk {
log.Error("下载zsh安装脚本失败: %v", resultLog)
return
}
op.SingleLineCommandExecutor([]string{
"chmod",
"+x",
"/root/wdd/zsh-install.sh",
})
installZshCommand := []string{
"/bin/bash",
"/root/wdd/zsh-install.sh",
}
if config.ConfigCache.Agent.Network.Internet == 7 {
installZshCommand = append(installZshCommand,
"REMOTE=https://gitea.107421.xyz/zeaslity/ohmyzsh.git",
)
}
op.SingleLineCommandExecutor(installZshCommand)
log.Info("安装zsh完成, 开始安装插件!")
pluginsHardCodeUrl := []string{
"https://gitee.com/wangl-cc/zsh-autosuggestions.git /root/.oh-my-zsh/plugins/zsh-autosuggestions",
"https://gitee.com/xiaoqqya/zsh-syntax-highlighting.git /root/.oh-my-zsh/plugins/zsh-syntax-highlighting",
}
pluginsHardCodeOutsideUrl := []string{
"https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/plugins/zsh-autosuggestions",
"https://github.com/zsh-users/zsh-syntax-highlighting.git /root/.oh-my-zsh/plugins/zsh-syntax-highlighting",
}
pluginsListUrl := []string{
"https://gitea.107421.xyz/zeaslity/ohmyzsh/src/branch/master/plugins/command-not-found/command-not-found.plugin.zsh",
"https://gitea.107421.xyz/zeaslity/ohmyzsh/src/branch/master/plugins/autojump/autojump.plugin.zsh",
"https://gitea.107421.xyz/zeaslity/ohmyzsh/src/branch/master/plugins/themes/themes.plugin.zsh",
}
if config.ConfigCache.Agent.Network.Internet == 7 {
log.Info("使用gitea镜像安装插件!")
pluginsHardCodeUrl = append(pluginsHardCodeUrl,
"wget -c -i https://b2.107421.xyz/oh-my-zsh-plugins-list.txt -P /root/.oh-my-zsh/plugins/",
)
} else {
log.Info("使用github安装插件!")
}
// 下载插件
if config.ConfigCache.Agent.Network.Internet == 7 {
// 执行硬编码命令, 安装插件
for _, command := range pluginsHardCodeUrl {
op.SingleLineCommandExecutor([]string{"git", "clone", command})
}
} else {
// 执行硬编码命令, 安装插件 国外
for _, command := range pluginsHardCodeOutsideUrl {
op.SingleLineCommandExecutor([]string{"git", "clone", command})
}
}
// 下载插件
for _, url := range pluginsListUrl {
downloadOk, resultLog := utils.DownloadFile(url, "/root/.oh-my-zsh/plugins/")
if !downloadOk {
log.Error("下载插件失败: %v", resultLog)
}
}
// 修改ZSH配置
utils.FindAndReplaceContentInFile("robbyrussell", "agnoster", "/root/.zshrc")
utils.FindAndReplaceContentInFile("# DISABLE_AUTO_UPDATE=\"true\"", "DISABLE_AUTO_UPDATE=\"true\"", "/root/.zshrc")
utils.FindAndReplaceContentInFile("plugins=(git)", "plugins=(git zsh-autosuggestions zsh-syntax-highlighting command-not-found z themes)", "/root/.zshrc")
//
op.SingleLineCommandExecutor([]string{
"source",
"/root/.zshrc",
})
op.SingleLineCommandExecutor([]string{
"chsh",
"-s",
"/bin/zsh",
})
op.SingleLineCommandExecutor([]string{
"zsh",
})
log.Info("Zsh安装完成")
}
}