diff --git a/hw.go b/hw.go index d544cf1c..4ee7e495 100644 --- a/hw.go +++ b/hw.go @@ -80,6 +80,21 @@ func GetDeviceID() string { return deviceID } +var deviceSKU string +var deviceSKUOnce sync.Once + +func GetDeviceSKU() string { + deviceSKUOnce.Do(func() { + content, err := os.ReadFile("/etc/jetkvm-sku") + if err != nil || strings.TrimSpace(string(content)) == "" { + deviceSKU = "jetkvm-v2" + } else { + deviceSKU = strings.TrimSpace(string(content)) + } + }) + return deviceSKU +} + func GetDefaultHostname() string { deviceId := GetDeviceID() if deviceId == "unknown_device_id" { diff --git a/internal/ota/ota.go b/internal/ota/ota.go index 4cc0a16d..b921ab61 100644 --- a/internal/ota/ota.go +++ b/internal/ota/ota.go @@ -42,6 +42,9 @@ func (s *State) getUpdateURL(params UpdateParams) (string, error, bool) { query := updateURL.Query() query.Set("deviceId", params.DeviceID) query.Set("prerelease", fmt.Sprintf("%v", params.IncludePreRelease)) + if params.SKU != "" { + query.Set("sku", params.SKU) + } // set the custom versions if they are specified for component, constraint := range params.Components { @@ -305,6 +308,7 @@ func (s *State) doUpdate(ctx context.Context, params UpdateParams) error { // UpdateParams represents the parameters for the update type UpdateParams struct { DeviceID string `json:"deviceID"` + SKU string `json:"sku"` Components map[string]string `json:"components"` IncludePreRelease bool `json:"includePreRelease"` ResetConfig bool `json:"resetConfig"` diff --git a/main.go b/main.go index ac9ec1bb..5ade107d 100644 --- a/main.go +++ b/main.go @@ -155,6 +155,7 @@ func Main() { includePreRelease := config.IncludePreRelease err = otaState.TryUpdate(context.Background(), ota.UpdateParams{ DeviceID: GetDeviceID(), + SKU: GetDeviceSKU(), IncludePreRelease: includePreRelease, }) if err != nil { diff --git a/ota.go b/ota.go index b11ab837..55a6034a 100644 --- a/ota.go +++ b/ota.go @@ -94,6 +94,7 @@ func GetLocalVersion() (systemVersion *semver.Version, appVersion *semver.Versio func getUpdateStatus(includePreRelease bool) (*ota.UpdateStatus, error) { updateStatus, err := otaState.GetUpdateStatus(context.Background(), ota.UpdateParams{ DeviceID: GetDeviceID(), + SKU: GetDeviceSKU(), IncludePreRelease: includePreRelease, RequestID: uuid.New().String(), }) @@ -169,6 +170,7 @@ func rpcTryUpdate() error { func rpcCheckUpdateComponents(params updateParams, includePreRelease bool) (*ota.UpdateStatus, error) { updateParams := ota.UpdateParams{ DeviceID: GetDeviceID(), + SKU: GetDeviceSKU(), IncludePreRelease: includePreRelease, Components: params.Components, } @@ -182,6 +184,7 @@ func rpcCheckUpdateComponents(params updateParams, includePreRelease bool) (*ota func rpcTryUpdateComponents(params updateParams, includePreRelease bool, resetConfig bool) error { updateParams := ota.UpdateParams{ DeviceID: GetDeviceID(), + SKU: GetDeviceSKU(), IncludePreRelease: includePreRelease, ResetConfig: resetConfig, Components: params.Components,