utils

package
v0.0.0-...-fc2143d Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Symbolic link.
	TagLink = 0o120000
	// Directory.
	TagDirectory = 0o40000
	// TypeFile is the type of a regular file. This is also the type that is
	// implied when no type is specified.
	TypeFile = "file"
	// TypeDir is the type of a directory that is explicitly added in order to
	// declare ownership or non-standard permission.
	TypeDir = "dir"
	// TypeSymlink is the type of a symlink that is created at the destination
	// path and points to the source path.
	TypeSymlink = "symlink"
	// TypeConfig is the type of a configuration file that may be changed by the
	// user of the package.
	TypeConfig = "config"
	// TypeConfigNoReplace is like TypeConfig with an added noreplace directive
	// that is respected by RPM-based distributions.
	// For all other package formats it is handled exactly like TypeConfig.
	TypeConfigNoReplace = "config|noreplace"
)

Variables

View Source
var (
	// Logger is the default logger with information level logging.
	// It writes to the MultiPrinter's writer.
	Logger = pterm.DefaultLogger.WithLevel(pterm.LogLevelInfo).WithWriter(MultiPrinter.Writer)
	// MultiPrinter is the default multi printer.
	MultiPrinter = pterm.DefaultMultiPrinter
)

Functions

func CheckGO

func CheckGO() bool

CheckGO checks if the GO executable is already installed.

It does not take any parameters. It returns a boolean value indicating whether the GO executable is already installed.

func CheckWritable

func CheckWritable(binary string) error

CheckWritable checks if a binary file is writeable.

It checks if the file exists and if write permission is granted. If the file does not exist or does not have write permission, an error is returned.

func Chmod

func Chmod(path string, perm os.FileMode) error

Chmod changes the file mode of the specified path.

It takes a string parameter `path` which represents the path of the file whose mode needs to be changed. It also takes an `os.FileMode` parameter `perm` which represents the new file mode to be set.

The function returns an error if there was an issue changing the file mode. If the file mode was successfully changed, it returns nil.

func Contains

func Contains(array []string, str string) bool

Contains checks if a string is present in an array of strings.

func Create

func Create(path string) (*os.File, error)

Create creates a new file at the specified path.

It takes a string parameter `path` which represents the path of the file to be created. The function returns a pointer to an `os.File` and an error.

func CreateWrite

func CreateWrite(path, data string) error

CreateWrite writes the given data to the file specified by the path.

It takes two parameters: - path: a string representing the path of the file. - data: a string representing the data to be written to the file.

It returns an error if there was a problem creating or writing to the file.

func Download

func Download(destination, uri string) error

Download downloads a file from the given URL and saves it to the specified destination.

Parameters: - destination: the path where the downloaded file will be saved. - url: the URL of the file to download.

func Exec

func Exec(excludeStdout bool, dir, name string, args ...string) error

Exec executes a command in the specified directory.

It takes the following parameters: - dir: the directory in which the command will be executed. - name: the name of the command to be executed. - arg: optional arguments to be passed to the command.

It returns an error if the command execution fails.

func ExecOutput

func ExecOutput(dir, name string, arg ...string) (string, error)

ExecOutput executes a command with the given arguments and returns its output as a string.

It takes the following parameters: - dir: the directory in which the command should be executed. - name: the name of the command to be executed. - arg: a variadic parameter representing the arguments to be passed to the command.

It returns a string representing the output of the command and an error if any occurred.

func Exists

func Exists(path string) bool

Exists checks if a file or directory exists at the given path.

path: the path to the file or directory. bool: returns true if the file or directory exists, false otherwise.

func ExistsMakeDir

func ExistsMakeDir(path string) error

ExistsMakeDir checks if a directory exists at the given path and creates it if it doesn't.

path: the path to the directory. error: returns an error if the directory cannot be created or accessed.

func Filename

func Filename(path string) string

Filename returns the filename from a given path.

It takes a string parameter `path` which represents the path of the file. It returns a string which is the filename extracted from the path.

func GOSetup

func GOSetup() error

GOSetup sets up the Go environment.

It checks if Go is installed and if not, it downloads and installs it. The function takes no parameters and does not return anything.

func GetArchitecture

func GetArchitecture() string

GetArchitecture returns the corresponding pacman architecture for the current GOARCH.

func GetDirSize

func GetDirSize(path string) (int64, error)

GetDirSize calculates the size of a directory in kilobytes.

It takes a path as a parameter and returns the size of the directory in kilobytes and an error if any.

func GetFileType

func GetFileType(binary string) string

GetFileType uses readelf to determine the type of the binary file.

func GitClone

func GitClone(dloadFilePath, sourceItemURI, sshPassword string,
	referenceName plumbing.ReferenceName) error

GitClone clones a Git repository from the given sourceItemURI to the specified dloadFilePath.

Parameters: - sourceItemURI: the URI of the Git repository to clone. - dloadFilePath: the file path to clone the repository into. - sshPassword: the password for SSH authentication (optional). - referenceName: the reference name for the clone operation.

func IsEmptyDir

func IsEmptyDir(path string, dirEntry os.DirEntry) bool

IsEmptyDir checks if a directory is empty.

It takes in two parameters: path, a string representing the directory path, and dirEntry, an os.DirEntry representing the directory entry. It returns a boolean value indicating whether the directory is empty or not.

func IsStaticLibrary

func IsStaticLibrary(binary string) bool

isStaticLibrary checks if the binary is a static library.

func Open

func Open(path string) (*os.File, error)

Open opens a file at the specified path and returns a pointer to the file and an error.

The path parameter is a string representing the file path to be opened. The function returns a pointer to an os.File and an error.

func PullContainers

func PullContainers(distro string) error

PullContainers pulls the specified container image.

distro: the name of the container image to pull. error: returns an error if the container image cannot be pulled.

func RunScript

func RunScript(cmds string) error

RunScript runs a shell script.

It takes a string parameter `cmds` which represents the shell script to be executed. The function returns an error if there was an issue running the script.

func StringifyArray

func StringifyArray(node *syntax.Assign) []string

StringifyArray generates a string representation of an array in the given syntax.

node: A pointer to the syntax.Assign node representing the array. []string: An array of strings representing the stringified elements of the array.

func StringifyAssign

func StringifyAssign(node *syntax.Assign) string

StringifyAssign returns a string representation of the given *syntax.Assign node.

It takes a pointer to a *syntax.Assign node as its parameter. It returns a string.

func StringifyFuncDecl

func StringifyFuncDecl(node *syntax.FuncDecl) string

StringifyFuncDecl converts a syntax.FuncDecl node to a string representation.

It takes a pointer to a syntax.FuncDecl node as a parameter and returns a string.

func StripFile

func StripFile(binary string, args ...string) error

StripFile strips the binary file using the strip command.

func StripLTO

func StripLTO(binary string, args ...string) error

StripLTO strips LTO-related sections from the binary file.

func Unarchive

func Unarchive(source, destination string) error

Unarchive is a function that takes a source file and a destination. It opens the source archive file, identifies its format, and extracts it to the destination.

Returns an error if there was a problem extracting the files.

Types

type FileContent

type FileContent struct {
	Source      string
	Destination string
	Type        string
	FileInfo    *FileInfo
}

FileContent describes the source and destination of one file to copy into a package.

type FileInfo

type FileInfo struct {
	Owner string
	Group string
	Mode  os.FileMode
	MTime time.Time
	Size  int64
}

type OSRelease

type OSRelease struct {
	ID string
}

OSRelease represents the contents of the /etc/os-release file.

func ParseOSRelease

func ParseOSRelease() (OSRelease, error)

ParseOSRelease reads the /etc/os-release file and populates the OSRelease struct.

Jump to

Keyboard shortcuts

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