Documentation
¶
Index ¶
- Constants
- Variables
- func EncryptMsg(data []byte) ([]byte, error)
- func GetArchInfo() (string, error)
- func GetHardwareId(includeDiskInfo bool, getByHelper bool) string
- func GetOSVersionInfo(filePath string) (map[string]string, error)
- func GetRandomBytes(length uint32) ([]byte, error)
- func IsForceUpdate(tp UpdateTp) bool
- func PKCS7Encode(text []byte, blockSize int) []byte
- func Substr(str string, start int, length int) string
- func UpdateTokenConfigFile(includeDiskInfo bool, getHardwareIdByHelper bool) string
- type CEVInfo
- type CVEMeta
- type ClientPollSetting
- type DMI
- type Hardware
- type MsgPostStatus
- type Policy
- type PreInstalledPkgMeta
- type ProcessEvent
- type ProjectInfo
- type ShellCheck
- type StatusMessage
- type SystemInfo
- type UpdateLogMeta
- type UpdatePlatformManager
- func (m *UpdatePlatformManager) CreateJobPostMsgInfo(uuid string, updateType system.UpdateType)
- func (m *UpdatePlatformManager) GenUpdatePolicyByToken(updateInRelease bool) error
- func (m *UpdatePlatformManager) GetCVEUpdateLogs(pkgs []string) map[string]CEVInfo
- func (m *UpdatePlatformManager) GetSystemMeta() map[string]system.PackageInfo
- func (m *UpdatePlatformManager) GetUpdateTarget() string
- func (m *UpdatePlatformManager) PostProcessEventMessage(body ProcessEvent)
- func (m *UpdatePlatformManager) PostStatusMessage(message StatusMessage, forceUpload bool)
- func (m *UpdatePlatformManager) PostSystemUpgradeMessage(uuid string)
- func (m *UpdatePlatformManager) PostUpdateLogFiles(files []string)
- func (m *UpdatePlatformManager) PostUpgradeStatus(uuid string, upgradeStatus UpgradeResult, Description string)
- func (m *UpdatePlatformManager) PrepareCheckScripts()
- func (m *UpdatePlatformManager) RecoverVersionLink()
- func (m *UpdatePlatformManager) ReplaceVersionCache()
- func (m *UpdatePlatformManager) RetryPostHistory()
- func (m *UpdatePlatformManager) SaveCache(c *Config)
- func (m *UpdatePlatformManager) SaveJobPostMsgByUUID(uuid string, upgradeStatus UpgradeResult, Description string)
- func (m *UpdatePlatformManager) SetInhibitAutoQuit()
- func (m *UpdatePlatformManager) UpdateAllPlatformDataSync() error
- func (m *UpdatePlatformManager) UpdateBaseline()
- func (m *UpdatePlatformManager) UpdateBaselineCache()
- func (m *UpdatePlatformManager) UpdateSourceList()
- type UpdateTp
- type UpgradePostMsg
- type UpgradeResult
- type Version
Constants ¶
const ( CheckEnv int = 1 GetUpdateEvent int = 2 StartDownload int = 3 DownloadComplete int = 4 StartBackUp int = 5 BackUpComplete int = 6 StartInstall int = 7 )
const ( CacheVersion = "/var/lib/lastore/os-version.b" KeyNow string = "now" // 立即更新 KeyShutdown string = "shutdown" // 关机更新 KeyLayout string = "15:04" )
需要注意cache文件的同步时机,所有数据应该不会从os-version和os-baseline获取
const ( ReleaseVersion = 1 UnstableVersion = 2 )
const ( GetVersion requestType = iota GetUpdateLog GetTargetPkgLists // 系统软件包清单 GetCurrentPkgLists GetPkgCVEs // CVE 信息 PostProcess PostProcessEvent PostResult )
const ( OemNotCustomState = "0" OemCustomState = "1" )
const (
BlockSize = 32
)
Variables ¶
var CVEs map[string]CEVInfo // 保存全局cves信息,方便查询
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 GetArchInfo ¶
func GetHardwareId ¶
func GetRandomBytes ¶
GetRandomBytes 根据需要长度,生成随机字符
func IsForceUpdate ¶
func PKCS7Encode ¶
PKCS7Encode 对需要加密的明文进行填充补位 * @param text 需要进行填充补位操作的明文 * @return 补齐明文字符串
func UpdateTokenConfigFile ¶
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 ClientPollSetting ¶
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 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 ProjectInfo ¶
type ProjectInfo struct {
Id string `json:"id"`
}
type ShellCheck ¶
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 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:
- Cleans up existing script directories to remove stale scripts
- Creates fresh directories only when scripts exist for a stage
- Decodes base64-encoded script content from memory
- 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 (*UpdatePlatformManager) RecoverVersionLink ¶
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 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 )