utils

package module
v0.0.0-...-400a49d Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CommonLog *log.Logger = nil // Common logs
	ErrorLog  *log.Logger = nil // Error logs
)

Functions

func AppendDirToPath

func AppendDirToPath(pathTemplate string, pars ...any) error

Append directory to PATH variable for bash & zsh

func AppendDirToPathVariable

func AppendDirToPathVariable(pathTemplate string, pars ...any) error

Append directory to current PATH variable

func CheckErrorWithMsg

func CheckErrorWithMsg(err error, format string, pars ...any) bool

If err is not nil, print the error message, send it to the error logs, and return false Otherwise, do nothing and return true

func CheckErrorWithTagAndMsg

func CheckErrorWithTagAndMsg(err error, format string, pars ...any) bool

If err is not nil, print the error message, send it to the error logs, and return false Otherwise, print a success tag, and return true

func CheckVHiveRepo

func CheckVHiveRepo() error

Check whether vHive repo exists, if not, clone it to the temporary directory

func CleanEnvironment

func CleanEnvironment() error

Clean the Environment

func CleanUpTmpDir

func CleanUpTmpDir() error

Clean up temporary directory

func CloneRepoToTmpDir

func CloneRepoToTmpDir(branch string, urlTemplate string, pars ...any) (string, error)

Clone git repo to temporary directory (absolute path of cloned repo will be the first return value if successful)

func CopyToDir

func CopyToDir(source string, target string, privileged bool) error

Copy file(directory) to the specific destination

func CreateLogs

func CreateLogs(logDir string, logFilePrefix ...string) error

Create Logs

func CreateTmpDir

func CreateTmpDir() error

Create temporary directory

func DetectArch

func DetectArch() error

Detect current architecture

func DetectOS

func DetectOS() error

Detect current operating system

func DownloadAndExecScript

func DownloadAndExecScript(scriptUrl string, scriptPars ...string) error

Download and execute remote bash script

func DownloadToTmpDir

func DownloadToTmpDir(urlTemplate string, pars ...any) (string, error)

Download file to temporary directory (absolute path of downloaded file will be the first return value if successful)

func ErrorPrintf

func ErrorPrintf(format string, pars ...any)

Print error message (red) in terminal and send it to the error logs(if exist)

func ExecShellCmd

func ExecShellCmd(cmd string, pars ...any) (string, error)

Execute Shell Command

func ExecVHiveBashScript

func ExecVHiveBashScript(scriptRelativePath string, scriptPars ...string) (string, error)

Execute bash scripts from vHive repo

func ExtractToDir

func ExtractToDir(archiveFilePath string, dirPath string, privileged bool) error

Extract archive file to specific directory(currently support .tar.gz, .gz, .tgz, .zip file only)

func FatalPrintf

func FatalPrintf(format string, pars ...any)

Call `ErrorPrintf()`

func GetCurrentDir

func GetCurrentDir() error

Get current directory

func GetEnvironmentVariable

func GetEnvironmentVariable(variableNameTemplate string, pars ...any) string

Get the value of specific environment variable

func GetKernelArch

func GetKernelArch() (string, error)

Get kernel arch info (equivalent to `uname -m`)

func GetKernelVersion

func GetKernelVersion() (string, error)

Get kernel version info (equivalent to `uname -r`)

func GetUserHomeDir

func GetUserHomeDir() error

Get current home directory

func GetVHiveFilePath

func GetVHiveFilePath(fileRelativePath string) (string, error)

Get absolute path of the file in vHive repo(given the relative path)

func InfoPrintf

func InfoPrintf(format string, pars ...any)

Print information (blue) in terminal and send it to the common logs(if exist)

func InstallPackages

func InstallPackages(packagesTemplate string, pars ...any) error

Install packages on various OS

func PrepareEnvironment

func PrepareEnvironment() error

Detect and prepare for the environment

func PrintWarningInfo

func PrintWarningInfo()

Print warning information

func SuccessPrintf

func SuccessPrintf(format string, pars ...any)

Print success message (green) in terminal and send it to the common logs(if exist)

func TurnOffAutomaticUpgrade

func TurnOffAutomaticUpgrade() error

Turn off unattended-upgrades

func UpdateEnvironmentVariable

func UpdateEnvironmentVariable(variableName string, newValueTemplate string, pars ...any) (string, error)

Update the value of specific environment variable

func WaitPrintf

func WaitPrintf(format string, pars ...any)

Print information (blue) with waiting symbol in terminal and send it to the common logs(if exist)

func WarnPrintf

func WarnPrintf(format string, pars ...any)

Print warning message (yellow) in terminal and send it to the common logs(if exist)

func WriteToSysctl

func WriteToSysctl(sysConfigTemplate string, pars ...any) error

Write to sysctl.conf

Types

type ShellError

type ShellError struct {
	Msg      string
	ExitCode int
}

Implement error interface of ShellError

func (*ShellError) Error

func (err *ShellError) Error() string

Jump to

Keyboard shortcuts

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