Files
ProjectOctopus/agent-wdd/cmd/Zsh.go
zeaslity 5c2325b7e4 优化Docker和SSH命令,增强系统配置和安装流程
- 更新Docker安装命令,默认版本升级到20.10.24
- 新增Docker配置命令,支持主节点配置daemon.json
- 修改SSH相关命令,增加输出换行以提高可读性
- 优化Zsh插件安装,使用完整git路径
- 改进系统配置中的主机名生成逻辑,增加内网IP最后一段标识
- 完善操作系统类型检测,扩展Ubuntu类型系统识别
- 调整包管理操作中的输出格式
2025-03-05 16:47:14 +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{
"/usr/bin/git clone https://gitee.com/wangl-cc/zsh-autosuggestions.git /root/.oh-my-zsh/plugins/zsh-autosuggestions",
"/usr/bin/git clone https://gitee.com/xiaoqqya/zsh-syntax-highlighting.git /root/.oh-my-zsh/plugins/zsh-syntax-highlighting",
}
pluginsHardCodeOutsideUrl := []string{
"/usr/bin/git clone https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/plugins/zsh-autosuggestions",
"/usr/bin/git clone 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.HardCodeCommandExecutor(command)
}
} else {
// 执行硬编码命令, 安装插件 国外
for _, command := range pluginsHardCodeOutsideUrl {
op.HardCodeCommandExecutor(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安装完成")
}
}