cli

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// chezmoi 的依赖项
	ChezmoiDependencies = "/usr/bin/chezmoi"

	ChezmoiConfig     = fmt.Sprintf(chezmoiConfigFormat, chezmoiSourceDir, sep, chezmoiAutoCommit, sep, chezmoiAutoPush)
	ChezmoiConfigFile = filepath.Join(home, ".config", "chezmoi", "chezmoi.toml")

	// cobra 的依赖项
	CobraDependencies = filepath.Join(golangGOBIN, "cobra-cli")

	CobraConfig     = fmt.Sprintf(cobraConfigFormat, cobraAuthor, email, cobraLicense, cobraUseViper)
	CobraConfigFile = filepath.Join(home, ".cobra.yaml")

	// docker service 和 mirrors 的依赖项
	DockerDependencies = "/usr/bin/dockerd"

	DockerServiceConfig     = fmt.Sprintf(dockerServiceConfigFormat, dockerServiceExecStart, dockerServiceDataRoot)
	DockerServiceConfigFile = "/etc/systemd/system/docker.service.d/override.conf"

	DockerMirrorsConfig     = fmt.Sprintf(dockerMirrorsConfigFormat, sep, dockerMirrorsRegistryMirrors)
	DockerMirrorsConfigFile = "/etc/docker/daemon.json"

	// frpc 的依赖项
	FrpcDependencies = "/usr/bin/frpc"

	FrpcConfig     = fmt.Sprintf(frpcConfigFormat, frpcRestart)
	FrpcConfigFile = "/etc/systemd/system/frpc.service.d/override.conf"

	// git 的依赖项
	GitDependencies = "/usr/bin/git"

	GitConfig     = fmt.Sprintf(gitConfigFormat, sep, hostname, sep, email, sep, gitCoreEditor, sep, gitCoreAutoCRLF, sep, gitMergeTool, sep, gitColorUI, sep, gitPullRebase, sep, gitFilterLfsClean, sep, gitFilterLfsSmudge, sep, gitFilterLfsProcess, sep, gitFilterLfsRequired)
	GitConfigFile = filepath.Join(home, ".gitconfig")

	// go 的依赖项
	GolangDependencies = "/usr/bin/go"

	GolangConfig     = fmt.Sprintf(golangConfigFormat, golangGO111MODULE, golangGOBIN, golangGOPATH, golangGOCACHE, golangGOMODCACHE)
	GolangConfigFile = filepath.Join(home, ".config", "go", "env")

	// pip 的依赖项
	PipDependencies = "/usr/bin/pip"

	PipConfig     = fmt.Sprintf(pipConfigFormat, pipIndexUrl, pipTrustedHost)
	PipConfigFile = filepath.Join(home, ".config", "pip", "pip.conf")

	// system-checkupdates timer 和 service 的依赖项
	SystemCheckupdatesDependencies = "/usr/local/bin/system-checkupdates" // >= 3.0.0-20230313.1

	SystemCheckupdatesTimerConfig     = fmt.Sprintf(systemCheckupdatesTimerConfigFormat, systemcheckupdatesTimerDescription, systemcheckupdatesTimerOnBootSec, systemcheckupdatesTimerOnUnitInactiveSec, systemcheckupdatesTimerAccuracySec, systemcheckupdatesTimerPersistent, systemcheckupdatesTimerWantedBy)
	SystemCheckupdatesTimerConfigFile = "/etc/systemd/system/system-checkupdates.timer"

	SystemCheckupdatesServiceConfig     = fmt.Sprintf(systemCheckupdatesServiceConfigFormat, systemcheckupdatesServiceDescription, systemcheckupdatesServiceAfter, systemcheckupdatesServiceWants, systemcheckupdatesServiceType, systemcheckupdatesServiceExecStart)
	SystemCheckupdatesServiceConfigFile = "/etc/systemd/system/system-checkupdates.service"
)

Functions

func CloneRepoViaHTTP

func CloneRepoViaHTTP(path string, url string, repo string) error

CloneRepoViaHTTP 通过 HTTP 协议克隆仓库

参数:

返回:

  • 错误信息

func DownloadFile

func DownloadFile(url string, outputFile string, progressParameters map[string]string) error

DownloadFile 通过 HTTP 协议下载文件

参数:

  • url: 文件下载地址
  • outputFile: 下载文件保存路径
  • progressParameters: 进度条参数

返回:

  • 错误信息

func FileVerification added in v1.0.4

func FileVerification(checksumFile, filePath string) (bool, error)

FileVerification 使用校验和文件校验文件的完整性

参数:

  • checksumFile: 校验和文件
  • filePath: 待校验文件

返回:

  • 校验结果
  • 错误信息

func GetTomlConfig

func GetTomlConfig(filePath string) (*toml.Tree, error)

GetTomlConfig 读取 toml 配置文件

参数:

  • filePath: toml 配置文件路径

返回:

  • toml 配置树
  • 错误信息

func InstallFile

func InstallFile(sourceFile, targetFile string, perm os.FileMode) error

InstallFile 安装文件,覆盖已存在的同名文件

参数:

  • sourceFile: 源文件路径
  • targetFile: 目标文件路径
  • perm: 目标文件权限

返回:

  • 错误信息

func InstallGolangBasedProgram added in v1.4.0

func InstallGolangBasedProgram(configTree *toml.Tree)

InstallGolangBasedProgram 安装/更新基于 Golang 的程序

参数:

  • configTree: 解析 toml 配置文件得到的配置树

func InstallSelfProgram added in v1.4.0

func InstallSelfProgram(configTree *toml.Tree)

InstallSelfProgram 安装/更新管理程序本身

参数:

  • configTree: 解析 toml 配置文件得到的配置树

func InstallShellBasedProgram added in v1.4.0

func InstallShellBasedProgram(configTree *toml.Tree)

InstallShellBasedProgram 安装/更新基于 Shell 的程序

参数:

  • configTree: 解析 toml 配置文件得到的配置树

func ProgramConfigurator added in v1.4.2

func ProgramConfigurator(flags map[string]bool)

ProgramConfigurator 程序配置器 参数:

  • flags: 系统信息各部分的开关

func WriteTomlConfig

func WriteTomlConfig(filePath string) (int64, error)

WriteTomlConfig 写入 toml 配置文件

参数:

  • filePath: toml 配置文件路径

返回:

  • 写入的字节数
  • 错误信息

Types

type Config added in v1.4.0

type Config struct {
	Install  InstallConfig  `toml:"install"`
	Variable VariableConfig `toml:"variable"`
}

用于转换 Toml 配置树的结构体

func LoadConfigToStruct added in v1.4.0

func LoadConfigToStruct(configTree *toml.Tree) (*Config, error)

LoadConfigToStruct 将 Toml 配置树加载到结构体

参数:

  • configTree: 解析 toml 配置文件得到的配置树

返回:

  • 结构体
  • 错误信息

type GoConfig

type GoConfig struct {
	Names          []string `toml:"names"`
	ReleaseApi     string   `toml:"release_api"`
	ReleaseAccept  string   `toml:"release_accept"`
	GeneratePath   string   `toml:"generate_path"`
	GithubUrl      string   `toml:"github_url"`
	GithubApi      string   `toml:"github_api"`
	GithubUsername string   `toml:"github_username"`
	GiteaUrl       string   `toml:"gitea_url"`
	GiteaApi       string   `toml:"gitea_api"`
	GiteaUsername  string   `toml:"gitea_username"`
	CompletionDir  []string `toml:"completion_dir"`
}

type InstallConfig added in v1.4.0

type InstallConfig struct {
	Method        string      `toml:"method"`
	ProgramPath   string      `toml:"program_path"`
	ReleaseTemp   string      `toml:"release_temp"`
	SourceTemp    string      `toml:"source_temp"`
	ResourcesPath string      `toml:"resources_path"`
	Self          SelfConfig  `toml:"self"`
	Go            GoConfig    `toml:"go"`
	Shell         ShellConfig `toml:"shell"`
}

type SelfConfig added in v1.4.0

type SelfConfig struct {
	Name           string   `toml:"name"`
	ReleaseApi     string   `toml:"release_api"`
	ReleaseAccept  string   `toml:"release_accept"`
	GeneratePath   string   `toml:"generate_path"`
	GithubUrl      string   `toml:"github_url"`
	GithubApi      string   `toml:"github_api"`
	GithubUsername string   `toml:"github_username"`
	GiteaUrl       string   `toml:"gitea_url"`
	GiteaApi       string   `toml:"gitea_api"`
	GiteaUsername  string   `toml:"gitea_username"`
	CompletionDir  []string `toml:"completion_dir"`
}

type ShellConfig added in v1.4.0

type ShellConfig struct {
	Names          []string `toml:"names"`
	Repo           string   `toml:"repo"`
	Dir            string   `toml:"dir"`
	GithubApi      string   `toml:"github_api"`
	GithubRaw      string   `toml:"github_raw"`
	GithubUsername string   `toml:"github_username"`
	GithubBranch   string   `toml:"github_branch"`
	GiteaApi       string   `toml:"gitea_api"`
	GiteaRaw       string   `toml:"gitea_raw"`
	GiteaUsername  string   `toml:"gitea_username"`
	GiteaBranch    string   `toml:"gitea_branch"`
}

type VariableConfig added in v1.4.0

type VariableConfig struct {
	HTTPProxy  string `toml:"http_proxy"`
	HTTPSProxy string `toml:"https_proxy"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL