function

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: GPL-3.0 Imports: 17 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 = home + "/.config/chezmoi/chezmoi.toml"

	// cobra的依赖项
	CobraDependencies = goGOBIN + "/cobra-cli"

	CobraConfig     = fmt.Sprintf(cobraConfigFormat, cobraAuthor, email, cobraLicense, cobraUseViper)
	CobraConfigFile = 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 = home + "/.gitconfig"

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

	GoConfig     = fmt.Sprintf(goConfigFormat, goGO111MODULE, goGOBIN, goGOPATH, goGOCACHE, goGOMODCACHE)
	GoConfigFile = home + "/.config/go/env"

	// npm的依赖项
	NpmDependencies = "/usr/bin/npm"

	NpmConfig     = fmt.Sprintf(npmConfigFormat, npmRegistry)
	NpmConfigFile = home + "/.npmrc"

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

	PipConfig     = fmt.Sprintf(pipConfigFormat, pipIndexUrl, pipTrustedHost)
	PipConfigFile = 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"
)

用户信息

View Source
var UserName = func() string {
	if GetVariable("SUDO_USER") != "" {
		return GetVariable("SUDO_USER")
	}
	return GetVariable("USER")
}()

用户名,当程序提权运行时,使用SUDO_USER变量获取提权前的用户名

Functions

func CloneRepoViaHTTP added in v0.1.2

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

通过HTTP协议克隆仓库

func CompareFile added in v0.1.0

func CompareFile(file1Path string, file2Path string) (bool, error)

并发比较两个文件是否相同

func CreateDir added in v0.1.0

func CreateDir(dirPath string) error

创建文件夹,如果其父目录不存在则创建父目录

func CreateFile added in v0.0.4

func CreateFile(filePath string) error

创建文件,如果其父目录不存在则创建父目录

func DeleteFile added in v0.0.4

func DeleteFile(filePath string) error

删除文件

func DownloadFile added in v0.3.0

func DownloadFile(url string, urlFile string, outputFile string) (string, error)

通过HTTP协议下载文件

func FileEmpty added in v0.0.5

func FileEmpty(filePath string) bool

判断文件是否为空(无法判断文件夹)

func FileExist added in v0.0.4

func FileExist(filePath string) bool

判断文件是否存在

func FolderEmpty added in v0.7.5

func FolderEmpty(filePath string) bool

判断文件夹是否为空,包括隐藏文件

func GetCurrentUserInfo added in v0.7.8

func GetCurrentUserInfo() (*user.User, error)

获取当前用户信息

func GetHostname added in v0.0.5

func GetHostname() string

获取不在环境变量中的HOSTNAME

func GetTomlConfig added in v0.0.4

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

读取toml配置文件

func GetUserInfoById added in v0.8.4

func GetUserInfoById(userId int) (*user.User, error)

根据ID获取用户信息

func GetUserInfoByName added in v0.8.4

func GetUserInfoByName(userName string) (*user.User, error)

根据用户名获取用户信息

func GetVariable added in v0.0.4

func GetVariable(key string) string

获取环境变量

func GoToDir added in v0.1.0

func GoToDir(dirPath string) error

进到指定目录

func InstallFile added in v0.1.0

func InstallFile(sourceFile, targetFile string) error

复制文件,如果文件存在则覆盖

func ParseApiResponse added in v0.2.9

func ParseApiResponse(body []byte) (string, error)

解析API响应体,根据JSON数据解析后的类型选择数据提取方式

func PolicyKitAuthentication added in v0.1.0

func PolicyKitAuthentication()

func ProgramInfo

func ProgramInfo(only bool) string

func RequestApi added in v0.2.9

func RequestApi(url string) ([]byte, error)

请求API,返回响应体

func RunCommand added in v0.7.3

func RunCommand(command string, args []string) error

运行指定命令(命令无输出)

func RunCommandGetResult added in v0.0.5

func RunCommandGetResult(command string, args []string) (string, error)

运行指定命令并获取命令输出

func SetVariable added in v0.1.0

func SetVariable(key, value string) error

设置环境变量

func WriteFile added in v0.0.5

func WriteFile(filePath string, content string) error

写入内容到文件

func WriteTomlConfig added in v0.0.4

func WriteTomlConfig(filePath string) (int64, error)

写入toml配置文件

Types

This section is empty.

Jump to

Keyboard shortcuts

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