updateplatform

package
v0.0.0-...-0761a4b Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckEnv         int = 1
	GetUpdateEvent   int = 2
	StartDownload    int = 3
	DownloadComplete int = 4
	StartBackUp      int = 5
	BackUpComplete   int = 6
	StartInstall     int = 7
)
View Source
const (
	CacheVersion = "/var/lib/lastore/os-version.b"

	KeyNow      string = "now"      // 立即更新
	KeyShutdown string = "shutdown" // 关机更新
	KeyLayout   string = "15:04"
)

需要注意cache文件的同步时机,所有数据应该不会从os-version和os-baseline获取

View Source
const (
	ReleaseVersion  = 1
	UnstableVersion = 2
)
View Source
const (
	GetVersion requestType = iota
	GetUpdateLog
	GetTargetPkgLists // 系统软件包清单
	GetCurrentPkgLists
	GetPkgCVEs // CVE 信息
	PostProcess
	PostProcessEvent
	PostResult
)
View Source
const (
	OemNotCustomState = "0"
	OemCustomState    = "1"
)
View Source
const (
	BlockSize = 32
)

Variables

View Source
var CVEs map[string]CEVInfo // 保存全局cves信息,方便查询
View Source
var Urls = map[requestType]requestContent{
	GetVersion: {
		"/api/v1/version",
		"GET",
	},
	GetTargetPkgLists: {
		"/api/v1/package",
		"GET",
	},
	GetCurrentPkgLists: {
		"/api/v1/package",
		"GET",
	},
	GetUpdateLog: {
		"/api/v1/systemupdatelogs",
		"GET",
	},
	GetPkgCVEs: {
		"/api/v1/cve/sync",
		"GET",
	},
	PostProcess: {
		"/api/v1/process",
		"POST",
	},
	PostProcessEvent: {
		"/api/v1/process/events",
		"POST",
	},
	PostResult: {
		"/api/v1/update/status",
		"POST",
	},
}

Functions

func EncryptMsg

func EncryptMsg(data []byte) ([]byte, error)

func GetArchInfo

func GetArchInfo() (string, error)

func GetHardwareId

func GetHardwareId(includeDiskInfo bool, getByHelper bool) string

func GetOSVersionInfo

func GetOSVersionInfo(filePath string) (map[string]string, error)

func GetRandomBytes

func GetRandomBytes(length uint32) ([]byte, error)

GetRandomBytes 根据需要长度,生成随机字符

func IsForceUpdate

func IsForceUpdate(tp UpdateTp) bool

func PKCS7Encode

func PKCS7Encode(text []byte, blockSize int) []byte

PKCS7Encode 对需要加密的明文进行填充补位 * @param text 需要进行填充补位操作的明文 * @return 补齐明文字符串

func Substr

func Substr(str string, start int, length int) string

Substr 截取字符串 start 起点下标 length 需要截取的长度

func UpdateTokenConfigFile

func UpdateTokenConfigFile(includeDiskInfo bool, getHardwareIdByHelper bool) string

UpdateTokenConfigFile 更新 99lastore-token.conf 文件的内容

Types

type CEVInfo

type CEVInfo struct {
	SyncTime       string `json:"synctime"`       // "CVE类型"
	CveId          string `json:"cveId"`          // "CVE编号"
	Source         string `json:"source"`         // "包名"
	FixedVersion   string `json:"fixedVersion"`   // "修复版本"
	Archs          string `json:"archs"`          // "架构信息"
	Score          string `json:"score"`          // "评分"
	Status         string `json:"status"`         // "修复状态"
	VulCategory    string `json:"vulCategory"`    // "漏洞类型"
	VulName        string `json:"vulName"`        // "漏洞名称"
	VulLevel       string `json:"vulLevel"`       // "⻛险等级"
	PubTime        string `json:"pubTime"`        // "CVE公开时间"
	Binary         string `json:"binary"`         // "二进制包"
	Description    string `json:"description"`    // "漏洞描述"
	CveDescription string `json:"cveDescription"` // "漏洞描述(英文)"
}

type CVEMeta

type CVEMeta struct {
	DateTime string    `json:"dateTime"`
	Cves     []CEVInfo `json:"cves"`
}

type ClientPollSetting

type ClientPollSetting struct {
	CheckPolicyInterval int   `json:"checkPolicyInterval"`
	StartCheckRange     []int `json:"startCheckRange"`
}

type DMI

type DMI struct {
	BiosVendor     string `json:"bios_vendor"`
	BiosVersion    string `json:"bios_version"`
	BiosDate       string `json:"bios_date"`
	BoardName      string `json:"board_name"`
	BoardSerial    string `json:"board_serial"`
	BoardVendor    string `json:"board_vendor"`
	BoardVersion   string `json:"board_version"`
	ProductName    string `json:"product_name"`
	ProductFamily  string `json:"product_family"`
	ProductSerial  string `json:"product_serial"`
	ProductUUID    string `json:"product_uuid"`
	ProductVersion string `json:"product_version"`
}

type Hardware

type Hardware struct {
	ID              string `json:"id"`
	Hostname        string `json:"hostname"`
	Username        string `json:"username"`
	OS              string `json:"os"`
	CPU             string `json:"cpu"`
	Laptop          bool   `json:"laptop"`
	Memory          int64  `json:"memory"`
	DiskTotal       int64  `json:"disk_total"`
	NetworkCardList string `json:"network_cards"`
	DiskList        string `json:"disk_list"`
	DMI             DMI    `json:"dmi"`
}

type MsgPostStatus

type MsgPostStatus string

MsgPostStatus 更新结果上报状态

const (
	NotReady    MsgPostStatus = "not ready"
	WaitPost    MsgPostStatus = "wait post"
	PostSuccess MsgPostStatus = "post success"
	PostFailure MsgPostStatus = "post failure"
)

type Policy

type Policy struct {
	Tp UpdateTp `json:"tp"`

	Data policyData `json:"data"`
}

type PreInstalledPkgMeta

type PreInstalledPkgMeta struct {
	PreCheck          []ShellCheck `json:"preCheck"`          // "更新前检查脚本"
	MidCheck          []ShellCheck `json:"midCheck"`          // "更新后检查脚本"
	PostCheck         []ShellCheck `json:"postCheck"`         // "更新完成重启后检查脚本"
	PreUpdateCheck    []ShellCheck `json:"preUpdateCheck"`    // "检查更新前检查脚本"
	PostUpdateCheck   []ShellCheck `json:"postUpdateCheck"`   // "检查更新后检查脚本"
	PreDownloadCheck  []ShellCheck `json:"preDownloadCheck"`  // "下载更新前检查脚本"
	PostDownloadCheck []ShellCheck `json:"postDownloadCheck"` // "下载更新后检查脚本"
	PreBackupCheck    []ShellCheck `json:"preBackupCheck"`    // "备份前检查脚本"
	PostBackupCheck   []ShellCheck `json:"postBackupCheck"`   // "备份后检查脚本"
	Packages          packageLists `json:"packages"`          // "基线软件包清单"
}

type ProcessEvent

type ProcessEvent struct {
	TaskID       int    `json:"taskID"`
	EventType    int    `json:"eventType"`
	EventStatus  bool   `json:"eventStatus"`
	EventContent string `json:"eventContent"`
}

type ProjectInfo

type ProjectInfo struct {
	Id string `json:"id"`
}

type ShellCheck

type ShellCheck struct {
	Name  string `json:"name"`  //检查脚本的名字
	Shell string `json:"shell"` //检查脚本的内容
}

type StatusMessage

type StatusMessage struct {
	Type           string `json:"type"`           //消息类型,info,warning,error
	UpdateType     string `json:"updateType"`     //system.UpdateType类型
	JobDescription string `json:"jobDescription"` //job.Description
	Detail         string `json:"detail"`         //消息详情
}

发送给更新平台的状态信息

type SystemInfo

type SystemInfo struct {
	SystemName      string
	ProductType     string
	EditionName     string
	Version         string
	HardwareId      string
	Processor       string
	Arch            string
	Custom          string
	SN              string
	HardwareVersion string
	OEMID           string
	ProjectId       string
	Baseline        string
	SystemType      string
	MachineType     string
	Mac             string
}

type UpdateLogMeta

type UpdateLogMeta struct {
	Baseline      string    `json:"baseline"`
	ShowVersion   string    `json:"showVersion"`
	CnLog         string    `json:"cnLog"`
	EnLog         string    `json:"enLog"`
	LogType       int       `json:"logType"`
	IsUnstable    int       `json:"isUnstable"`
	SystemVersion string    `json:"systemVersion"`
	PublishTime   time.Time `json:"publishTime"`
}

type UpdatePlatformManager

type UpdatePlatformManager struct {
	PreUpgradeCheck   []ShellCheck                  // 更新前检查脚本
	MidUpgradeCheck   []ShellCheck                  // 更新后检查脚本
	PostUpgradeCheck  []ShellCheck                  // 更新完成重启后检查脚本
	PreUpdateCheck    []ShellCheck                  // 检查更新前检查脚本
	PostUpdateCheck   []ShellCheck                  // 检查更新后检查脚本
	PreDownloadCheck  []ShellCheck                  // 下载更新前检查脚本
	PostDownloadCheck []ShellCheck                  // 下载更新后检查脚本
	PreBackupCheck    []ShellCheck                  // 备份前检查脚本
	PostBackupCheck   []ShellCheck                  // 备份后检查脚本
	TargetCorePkgs    map[string]system.PackageInfo // 必须安装软件包信息清单  	对应dut的core list
	BaselinePkgs      map[string]system.PackageInfo // 当前版本的核心软件包清单	对应dut的baseline
	SelectPkgs        map[string]system.PackageInfo // 可选软件包清单
	FreezePkgs        map[string]system.PackageInfo // 禁止升级包清单
	PurgePkgs         map[string]system.PackageInfo // 删除软件包清单

	SystemUpdateLogs []UpdateLogMeta // 更新注记

	Token string

	Tp             UpdateTp  // 更新策略类型:1.非强制更新,2.强制更新/立即更新,3.强制更新/关机或重启时更新,4.强制更新/指定时间更新
	UpdateTime     time.Time // 更新时间(指定时间更新时的时间)
	UpdateNowForce bool      // 立即更新

	TimerHasChanged bool

	UnInhibitAutoQuit func()
	// contains filtered or unexported fields
}

func NewUpdatePlatformManager

func NewUpdatePlatformManager(c *Config, updateToken bool) *UpdatePlatformManager

func (*UpdatePlatformManager) CreateJobPostMsgInfo

func (m *UpdatePlatformManager) CreateJobPostMsgInfo(uuid string, updateType system.UpdateType)

CreateJobPostMsgInfo 初始化创建上报信息

func (*UpdatePlatformManager) GenUpdatePolicyByToken

func (m *UpdatePlatformManager) GenUpdatePolicyByToken(updateInRelease bool) error

func (*UpdatePlatformManager) GetCVEUpdateLogs

func (m *UpdatePlatformManager) GetCVEUpdateLogs(pkgs []string) map[string]CEVInfo

func (*UpdatePlatformManager) GetSystemMeta

func (m *UpdatePlatformManager) GetSystemMeta() map[string]system.PackageInfo

func (*UpdatePlatformManager) GetUpdateTarget

func (m *UpdatePlatformManager) GetUpdateTarget() string

func (*UpdatePlatformManager) PostProcessEventMessage

func (m *UpdatePlatformManager) PostProcessEventMessage(body ProcessEvent)

func (*UpdatePlatformManager) PostStatusMessage

func (m *UpdatePlatformManager) PostStatusMessage(message StatusMessage, forceUpload bool)

PostStatusMessage 将检查\下载\安装过程中所有异常状态和每个阶段成功的正常状态上报

func (*UpdatePlatformManager) PostSystemUpgradeMessage

func (m *UpdatePlatformManager) PostSystemUpgradeMessage(uuid string)

PostSystemUpgradeMessage 发送系统更新成功或失败的状态

func (*UpdatePlatformManager) PostUpdateLogFiles

func (m *UpdatePlatformManager) PostUpdateLogFiles(files []string)

PostUpdateLogFiles 将更新日志上传

func (*UpdatePlatformManager) PostUpgradeStatus

func (m *UpdatePlatformManager) PostUpgradeStatus(uuid string, upgradeStatus UpgradeResult, Description string)

func (*UpdatePlatformManager) PrepareCheckScripts

func (m *UpdatePlatformManager) PrepareCheckScripts()

PrepareCheckScripts decodes and deploys base64-encoded check scripts to the filesystem. It processes multiple types of check scripts, including:

  • PreCheck/MidCheck/PostCheck: system update checks
  • preUpdateCheck/postUpdateCheck: before/after checking updates
  • preDownloadCheck/postDownloadCheck: before/after downloading updates
  • preBackupCheck/postBackupCheck: before/after backup

The function performs the following operations:

  1. Cleans up existing script directories to remove stale scripts
  2. Creates fresh directories only when scripts exist for a stage
  3. Decodes base64-encoded script content from memory
  4. Writes executable script files to the filesystem with 0755 permissions

Script files are organized under /var/lib/lastore/check/ in subdirectories:

  • pre_check/: for pre-update validation scripts (created when present)
  • mid_check/: for mid-update validation scripts (created when present)
  • post_check/: for post-update validation scripts (created when present)
  • pre_update_check/: for pre-update-check validation scripts (created when present)
  • post_update_check/: for post-update-check validation scripts (created when present)
  • pre_download_check/: for pre-download validation scripts (created when present)
  • post_download_check/: for post-download validation scripts (created when present)
  • pre_backup_check/: for pre-backup validation scripts (created when present)
  • post_backup_check/: for post-backup validation scripts (created when present)

Any decode or file write errors are logged as warnings but do not stop the processing of remaining scripts.

func (m *UpdatePlatformManager) RecoverVersionLink()

RecoverVersionLink 安装更新并检查完成后,需要用软连接替换文件

func (*UpdatePlatformManager) ReplaceVersionCache

func (m *UpdatePlatformManager) ReplaceVersionCache()

ReplaceVersionCache 进行安装更新前,需要复制文件替换软连接

func (*UpdatePlatformManager) RetryPostHistory

func (m *UpdatePlatformManager) RetryPostHistory()

func (*UpdatePlatformManager) SaveCache

func (m *UpdatePlatformManager) SaveCache(c *Config)

func (*UpdatePlatformManager) SaveJobPostMsgByUUID

func (m *UpdatePlatformManager) SaveJobPostMsgByUUID(uuid string, upgradeStatus UpgradeResult, Description string)

SaveJobPostMsgByUUID 需要在success或failed状态迁移前调用,保证数据存储

func (*UpdatePlatformManager) SetInhibitAutoQuit

func (m *UpdatePlatformManager) SetInhibitAutoQuit()

func (*UpdatePlatformManager) UpdateAllPlatformDataSync

func (m *UpdatePlatformManager) UpdateAllPlatformDataSync() error

UpdateAllPlatformDataSync 同步获取所有需要从更新平台获取的数据

func (*UpdatePlatformManager) UpdateBaseline

func (m *UpdatePlatformManager) UpdateBaseline()

UpdateBaseline 更新安装并检查成功后,同步baseline文件

func (*UpdatePlatformManager) UpdateBaselineCache

func (m *UpdatePlatformManager) UpdateBaselineCache()

func (*UpdatePlatformManager) UpdateSourceList

func (m *UpdatePlatformManager) UpdateSourceList()

type UpdateTp

type UpdateTp int
const (
	UnknownUpdate   UpdateTp = 0
	NormalUpdate    UpdateTp = 1 // 更新
	UpdateNow       UpdateTp = 2 // 立即更新 // 以下为强制更新
	UpdateShutdown  UpdateTp = 3 // 关机更新
	UpdateRegularly UpdateTp = 4 // 定时更新
)

type UpgradePostMsg

type UpgradePostMsg struct {
	SerialNumber    string        `json:"serialNumber"`
	MachineID       string        `json:"machineId"`
	UpgradeStatus   UpgradeResult `json:"status"`
	UpgradeErrorMsg string        `json:"msg"`
	TimeStamp       int64         `json:"timestamp"`
	SourceUrl       []string      `json:"sourceUrl"`
	Version         string        `json:"version"`

	PreBuild        string `json:"preBuild"`
	NextShowVersion string `json:"nextShowVersion"`
	PreBaseline     string `json:"preBaseline"`
	NextBaseline    string `json:"nextBaseline"`

	UpgradeStartTime int64 `json:"updateStartAt"`
	UpgradeEndTime   int64 `json:"updateFinishAt"`
	TaskId           int

	Uuid       string
	PostStatus MsgPostStatus
	RetryCount uint32
	// contains filtered or unexported fields
}

type UpgradeResult

type UpgradeResult int8
const (
	UpgradeSucceed UpgradeResult = 0
	UpgradeFailed  UpgradeResult = 1
	CheckFailed    UpgradeResult = 2
)

type Version

type Version struct {
	Version  string `json:"version"`
	Baseline string `json:"baseline"`
	TaskID   int    `json:"taskID"`
}

Jump to

Keyboard shortcuts

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