glbm

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

README

glbm

介绍

glbm的全称是(Go Linux Basic module), 即使用Golang编写的Linux基础模块

Gitee 项目地址

特色

  • 使用全中文注释,即使小白也能轻松上手
  • 完全开源、永久免费

功能清单

详细功能清单请访问pkg.go.Dev

安装

关闭校验

设置环境变量

export GOSUMDB="off"
开始安装

首先进入你的项目根目录,然后执行下面的命令

go err -u gitee.com/liumou_site/glbm

效果如下

➜  demo go err -u gitee.com/liumou_site/glbm
go: downloading gitee.com/liumou_site/glbm v1.3.4
go: gitee.com/liumou_site/glbm upgrade => v1.3.4
go: downloading gitee.com/liumou_site/gcs v1.2.3
go: downloading gitee.com/liumou_site/logger v1.1.1
go: downloading github.com/spf13/cast v1.5.0
➜  demo

使用

Demo

最终请看单元测试案例

其他演示
package main

import (
	"fmt"
	"gitee.com/liumou_site/glbm"
)

// Ju 权限验证
func Ju() {
	g := glbm.CheckSudo("1")
	if g {
		fmt.Println("密码检验正确")
	} else {
		fmt.Println("密码错误或无权限")
	}
	d := glbm.Developer()
	if d {
		fmt.Println("已开启开发者")
	} else {
		fmt.Println("未开启开发者")
	}
}

// GetUser 获取用户信息
func GetUser() {
	err, username, uid, uHome := glbm.GetUserInfo(false)
	if err {
		fmt.Println(username)
		fmt.Println(uid)
		fmt.Println(uHome)
	}
}

// OsInfo 获取系统信息
func OsInfo() {
	osType, osArch, ov := glbm.GetOsInfo()
	fmt.Println(osType)
	fmt.Println(osArch)
	fmt.Println(ov)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSudo

func CheckSudo(password string) bool

CheckSudo 判断是否拥有sudo权限

func CurlToSave

func CurlToSave(url, filename string, cover bool) bool

CurlToSave 使用Curl下载文件到指定路径(cover是否覆盖已有文件)

func Developer

func Developer() bool

Developer UOS系统下检查是否开启开发者模式

func DpkgCheckInstalledKey added in v1.3.3

func DpkgCheckInstalledKey(pac1, pac2 string, debug bool) (bool, string)

DpkgCheckInstalledKey 使用两个关键词查询本地是否已安装某个软件包

func DpkgCheckPackageVersion

func DpkgCheckPackageVersion(package_ string, version string) (status_ bool, ver_ string)

DpkgCheckPackageVersion 使用dpkg检查本地安装版本与标准版本是否一致

func DpkgConfig

func DpkgConfig(password string, realtime bool) *dpkg

DpkgConfig 初始化(realtime: 是否开启实时刷新)

func DpkgGetPackageStatus

func DpkgGetPackageStatus(pacPackage string) (m map[string]string, err error)

DpkgGetPackageStatus 使用 Dpkg查询包状态, 通过res返回字典,通过status返回查询状态,字典key(status/Name/version)

func DpkgInstalled

func DpkgInstalled(pacPackage string) bool

DpkgInstalled 使用Dpkg查询是否已安装(ii)

func GetOsInfo

func GetOsInfo() (osType, osArch string, osVersion int)

GetOsInfo 获取系统信息

func GetUserInfo

func GetUserInfo(display bool) (ok bool, username string, userid int, UserHome string)

GetUserInfo 获取当前系统环境信息(display: 是否显示信息)

func IsIPv4 added in v1.4.3

func IsIPv4(ipAddr string) bool

IsIPv4 判断是否属于IPv4

func IsLoopbackV4 added in v1.4.3

func IsLoopbackV4(ipAddr string) bool

IsLoopbackV4 判断是否属于IPv4

func Version

func Version()

func WgetToSave

func WgetToSave(url, filename string) bool

WgetToSave 使用wget下载文件到指定路径

Types

type AptPassword

type AptPassword struct {
	Sudo gcs.SudoConfig // 执行sudo命令
	// contains filtered or unexported fields
}

AptPassword 定义一个命令行密码结构体

func AptInitConfig

func AptInitConfig(password string, debug, realtime bool) *AptPassword

AptInitConfig Apt 管理初始化

func (*AptPassword) AptInstall

func (a *AptPassword) AptInstall(Package string) (res bool)

AptInstall 使用apt在线安装包

func (*AptPassword) AptInstallList

func (a *AptPassword) AptInstallList(pacList list.List) (ok, failed list.List)

AptInstallList 通过apt安装包(列表传入)

func (*AptPassword) AptInstallSlice

func (a *AptPassword) AptInstallSlice(pacList []string) (ok, failed list.List)

AptInstallSlice 通过apt安装包(切片传入) - 推荐

func (*AptPassword) AptLocalInstallFile

func (a *AptPassword) AptLocalInstallFile(filename, name string) (err error)

AptLocalInstallFile 使用apt安装本地文件(单个),安装之前将会检测文件是否存在

func (*AptPassword) AptLocalInstallStr

func (a *AptPassword) AptLocalInstallStr(installStr, name string) bool

AptLocalInstallStr 使用apt安装本地文件(字符串),直接安装,不会检测文件是否存在

func (*AptPassword) AptUninstall

func (a *AptPassword) AptUninstall(Package string, name string) (res bool)

AptUninstall 通过apt卸载单个包

func (*AptPassword) AptUninstallList

func (a *AptPassword) AptUninstallList(pacList list.List) (ok, failed list.List)

AptUninstallList 通过apt卸载包(列表传入)

func (*AptPassword) AptUninstallSlice added in v1.3.7

func (a *AptPassword) AptUninstallSlice(pacList []string) (ok, failed list.List)

AptUninstallSlice 通过apt卸载包(列表传入)

func (*AptPassword) AptUpdateIndex

func (a *AptPassword) AptUpdateIndex() (res bool)

AptUpdateIndex 更新索引

func (*AptPassword) AptUpgrade

func (a *AptPassword) AptUpgrade() (res bool)

AptUpgrade 更新系统

func (*AptPassword) LocalInstallList added in v1.3.7

func (a *AptPassword) LocalInstallList(fileList []string, name string) bool

LocalInstallList 使用apt安装本地文件(列表传入)

type Connection added in v1.4.3

type Connection struct {
	Name   string // 连接名称(例如: dhcp)
	Types  string // 连接类型(bridge/wifi/ethernet)
	Method string // 连接模式(auto)

	Dns     []string // DNS列表
	Dev     string   // 设备名称
	Gw      string   // 网关地址
	Address string   // IP地址
	Mask    int      // 子网掩码
	// contains filtered or unexported fields
}

func ConnectConfig added in v1.4.3

func ConnectConfig(debug bool) *Connection

ConnectConfig 连接管理

func (*Connection) AddDns added in v1.4.3

func (c *Connection) AddDns() (err error)

AddDns 增加DNS,默认(119.29.29.29 180.76.76.76)

func (*Connection) ConnectAdd added in v1.4.3

func (c *Connection) ConnectAdd() error

ConnectAdd 新增连接

type EthInterface added in v1.4.3

type EthInterface struct {
	Index int    // 网卡设备索引
	Name  string // 网卡名称
	Ipv4  string // IPV4地址
	Mask  int    //子网掩码
	Mac   string // Mac物理地址
}

EthInterface 网卡信息结构体

type NetDevice

type NetDevice struct {
	DefaultGw      string // 当前默认网关
	DefaultDevices string // 当前默认网卡设备
	// contains filtered or unexported fields
}

NetDevice 网卡管理

func NetGetInfo added in v1.4.3

func NetGetInfo() *NetDevice

NetGetInfo 返回一个网卡管理实例

func (*NetDevice) GetConnectionList

func (n *NetDevice) GetConnectionList() bool

GetConnectionList 获取指定设备及类型的连接列表

func (*NetDevice) GetDefaultGw added in v1.4.3

func (n *NetDevice) GetDefaultGw() bool

GetDefaultGw 获取默认网关/网卡设备

func (*NetDevice) GetEthInfo added in v1.4.3

func (n *NetDevice) GetEthInfo() ([]EthInterface, error)

GetEthInfo 获取所有网卡信息(IPV4)

Jump to

Keyboard shortcuts

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