mirror of https://github.com/jetkvm/kvm.git
feat: allow configuration to be reset during update
This commit is contained in:
parent
f6b0b7297d
commit
1e9dcc1986
|
|
@ -177,6 +177,13 @@ func (s *State) doUpdate(ctx context.Context, params UpdateParams) error {
|
||||||
if s.rebootNeeded {
|
if s.rebootNeeded {
|
||||||
scopedLogger.Info().Msg("System Rebooting due to OTA update")
|
scopedLogger.Info().Msg("System Rebooting due to OTA update")
|
||||||
|
|
||||||
|
if params.ResetConfig {
|
||||||
|
scopedLogger.Info().Msg("Resetting config")
|
||||||
|
if err := s.resetConfig(); err != nil {
|
||||||
|
return s.componentUpdateError("Error resetting config", err, &scopedLogger)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
postRebootAction := &PostRebootAction{
|
postRebootAction := &PostRebootAction{
|
||||||
HealthCheck: "/device/status",
|
HealthCheck: "/device/status",
|
||||||
RedirectUrl: fmt.Sprintf("/settings/general/update?version=%s", systemUpdate.version),
|
RedirectUrl: fmt.Sprintf("/settings/general/update?version=%s", systemUpdate.version),
|
||||||
|
|
@ -198,6 +205,7 @@ type UpdateParams struct {
|
||||||
Components []string `json:"components,omitempty"`
|
Components []string `json:"components,omitempty"`
|
||||||
IncludePreRelease bool `json:"includePreRelease"`
|
IncludePreRelease bool `json:"includePreRelease"`
|
||||||
CheckOnly bool `json:"checkOnly"`
|
CheckOnly bool `json:"checkOnly"`
|
||||||
|
ResetConfig bool `json:"resetConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) getUpdateStatus(
|
func (s *State) getUpdateStatus(
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,9 @@ type RPCState struct {
|
||||||
// HwRebootFunc is a function that reboots the hardware
|
// HwRebootFunc is a function that reboots the hardware
|
||||||
type HwRebootFunc func(force bool, postRebootAction *PostRebootAction, delay time.Duration) error
|
type HwRebootFunc func(force bool, postRebootAction *PostRebootAction, delay time.Duration) error
|
||||||
|
|
||||||
|
// ResetConfigFunc is a function that resets the config
|
||||||
|
type ResetConfigFunc func() error
|
||||||
|
|
||||||
// GetHTTPClientFunc is a function that returns the HTTP client
|
// GetHTTPClientFunc is a function that returns the HTTP client
|
||||||
type GetHTTPClientFunc func() *http.Client
|
type GetHTTPClientFunc func() *http.Client
|
||||||
|
|
||||||
|
|
@ -117,6 +120,7 @@ type State struct {
|
||||||
reboot HwRebootFunc
|
reboot HwRebootFunc
|
||||||
getLocalVersion GetLocalVersionFunc
|
getLocalVersion GetLocalVersionFunc
|
||||||
onStateUpdate OnStateUpdateFunc
|
onStateUpdate OnStateUpdateFunc
|
||||||
|
resetConfig ResetConfigFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTargetVersion sets the target version for a component
|
// SetTargetVersion sets the target version for a component
|
||||||
|
|
@ -199,6 +203,7 @@ type Options struct {
|
||||||
OnProgressUpdate OnProgressUpdateFunc
|
OnProgressUpdate OnProgressUpdateFunc
|
||||||
HwReboot HwRebootFunc
|
HwReboot HwRebootFunc
|
||||||
ReleaseAPIEndpoint string
|
ReleaseAPIEndpoint string
|
||||||
|
ResetConfig ResetConfigFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewState creates a new OTA state
|
// NewState creates a new OTA state
|
||||||
|
|
@ -215,6 +220,7 @@ func NewState(opts Options) *State {
|
||||||
getLocalVersion: opts.GetLocalVersion,
|
getLocalVersion: opts.GetLocalVersion,
|
||||||
componentUpdateStatuses: components,
|
componentUpdateStatuses: components,
|
||||||
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
|
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
|
||||||
|
resetConfig: opts.ResetConfig,
|
||||||
}
|
}
|
||||||
go s.confirmCurrentSystem()
|
go s.confirmCurrentSystem()
|
||||||
return s
|
return s
|
||||||
|
|
|
||||||
|
|
@ -1153,7 +1153,7 @@ var rpcHandlers = map[string]RPCHandler{
|
||||||
"getUpdateStatus": {Func: rpcGetUpdateStatus},
|
"getUpdateStatus": {Func: rpcGetUpdateStatus},
|
||||||
"getUpdateStatusChannel": {Func: rpcGetUpdateStatusChannel},
|
"getUpdateStatusChannel": {Func: rpcGetUpdateStatusChannel},
|
||||||
"tryUpdate": {Func: rpcTryUpdate},
|
"tryUpdate": {Func: rpcTryUpdate},
|
||||||
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly"}},
|
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly", "resetConfig"}},
|
||||||
"cancelDowngrade": {Func: rpcCancelDowngrade},
|
"cancelDowngrade": {Func: rpcCancelDowngrade},
|
||||||
"getDevModeState": {Func: rpcGetDevModeState},
|
"getDevModeState": {Func: rpcGetDevModeState},
|
||||||
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
|
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
|
||||||
|
|
|
||||||
6
ota.go
6
ota.go
|
|
@ -30,6 +30,7 @@ func initOta() {
|
||||||
},
|
},
|
||||||
GetLocalVersion: GetLocalVersion,
|
GetLocalVersion: GetLocalVersion,
|
||||||
HwReboot: hwReboot,
|
HwReboot: hwReboot,
|
||||||
|
ResetConfig: rpcResetConfig,
|
||||||
OnStateUpdate: func(state *ota.RPCState) {
|
OnStateUpdate: func(state *ota.RPCState) {
|
||||||
triggerOTAStateUpdate(state)
|
triggerOTAStateUpdate(state)
|
||||||
},
|
},
|
||||||
|
|
@ -144,14 +145,15 @@ func rpcTryUpdate() error {
|
||||||
return rpcTryUpdateComponents(tryUpdateComponents{
|
return rpcTryUpdateComponents(tryUpdateComponents{
|
||||||
AppTargetVersion: "",
|
AppTargetVersion: "",
|
||||||
SystemTargetVersion: "",
|
SystemTargetVersion: "",
|
||||||
}, config.IncludePreRelease, false)
|
}, config.IncludePreRelease, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rpcTryUpdateComponents(components tryUpdateComponents, includePreRelease bool, checkOnly bool) error {
|
func rpcTryUpdateComponents(components tryUpdateComponents, includePreRelease bool, checkOnly bool, resetConfig bool) error {
|
||||||
updateParams := ota.UpdateParams{
|
updateParams := ota.UpdateParams{
|
||||||
DeviceID: GetDeviceID(),
|
DeviceID: GetDeviceID(),
|
||||||
IncludePreRelease: includePreRelease,
|
IncludePreRelease: includePreRelease,
|
||||||
CheckOnly: checkOnly,
|
CheckOnly: checkOnly,
|
||||||
|
ResetConfig: resetConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info().Interface("components", components).Msg("components")
|
logger.Info().Interface("components", components).Msg("components")
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,8 @@ export default function SettingsAdvancedRoute() {
|
||||||
},
|
},
|
||||||
includePreRelease: devChannel,
|
includePreRelease: devChannel,
|
||||||
checkOnly: true,
|
checkOnly: true,
|
||||||
|
// no need to reset config for a check only update
|
||||||
|
resetConfig: false,
|
||||||
};
|
};
|
||||||
send("tryUpdateComponents", params, (resp: JsonRpcResponse) => {
|
send("tryUpdateComponents", params, (resp: JsonRpcResponse) => {
|
||||||
if ("error" in resp) {
|
if ("error" in resp) {
|
||||||
|
|
@ -199,6 +201,8 @@ export default function SettingsAdvancedRoute() {
|
||||||
}
|
}
|
||||||
const pageParams = new URLSearchParams();
|
const pageParams = new URLSearchParams();
|
||||||
pageParams.set("downgrade", "true");
|
pageParams.set("downgrade", "true");
|
||||||
|
// TODO: implement this
|
||||||
|
pageParams.set("resetConfig", "true");
|
||||||
pageParams.set("components", updateTarget == "both" ? "app,system" : updateTarget);
|
pageParams.set("components", updateTarget == "both" ? "app,system" : updateTarget);
|
||||||
|
|
||||||
// Navigate to update page
|
// Navigate to update page
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ export default function SettingsGeneralUpdateRoute() {
|
||||||
},
|
},
|
||||||
includePreRelease: true,
|
includePreRelease: true,
|
||||||
checkOnly: false,
|
checkOnly: false,
|
||||||
|
// TODO: implement this
|
||||||
|
resetConfig: false,
|
||||||
});
|
});
|
||||||
setModalView("updating");
|
setModalView("updating");
|
||||||
}, [send, setModalView, updateComponents]);
|
}, [send, setModalView, updateComponents]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue