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 {
|
||||
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{
|
||||
HealthCheck: "/device/status",
|
||||
RedirectUrl: fmt.Sprintf("/settings/general/update?version=%s", systemUpdate.version),
|
||||
|
|
@ -198,6 +205,7 @@ type UpdateParams struct {
|
|||
Components []string `json:"components,omitempty"`
|
||||
IncludePreRelease bool `json:"includePreRelease"`
|
||||
CheckOnly bool `json:"checkOnly"`
|
||||
ResetConfig bool `json:"resetConfig"`
|
||||
}
|
||||
|
||||
func (s *State) getUpdateStatus(
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ type RPCState struct {
|
|||
// HwRebootFunc is a function that reboots the hardware
|
||||
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
|
||||
type GetHTTPClientFunc func() *http.Client
|
||||
|
||||
|
|
@ -117,6 +120,7 @@ type State struct {
|
|||
reboot HwRebootFunc
|
||||
getLocalVersion GetLocalVersionFunc
|
||||
onStateUpdate OnStateUpdateFunc
|
||||
resetConfig ResetConfigFunc
|
||||
}
|
||||
|
||||
// SetTargetVersion sets the target version for a component
|
||||
|
|
@ -199,6 +203,7 @@ type Options struct {
|
|||
OnProgressUpdate OnProgressUpdateFunc
|
||||
HwReboot HwRebootFunc
|
||||
ReleaseAPIEndpoint string
|
||||
ResetConfig ResetConfigFunc
|
||||
}
|
||||
|
||||
// NewState creates a new OTA state
|
||||
|
|
@ -215,6 +220,7 @@ func NewState(opts Options) *State {
|
|||
getLocalVersion: opts.GetLocalVersion,
|
||||
componentUpdateStatuses: components,
|
||||
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
|
||||
resetConfig: opts.ResetConfig,
|
||||
}
|
||||
go s.confirmCurrentSystem()
|
||||
return s
|
||||
|
|
|
|||
|
|
@ -1153,7 +1153,7 @@ var rpcHandlers = map[string]RPCHandler{
|
|||
"getUpdateStatus": {Func: rpcGetUpdateStatus},
|
||||
"getUpdateStatusChannel": {Func: rpcGetUpdateStatusChannel},
|
||||
"tryUpdate": {Func: rpcTryUpdate},
|
||||
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly"}},
|
||||
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly", "resetConfig"}},
|
||||
"cancelDowngrade": {Func: rpcCancelDowngrade},
|
||||
"getDevModeState": {Func: rpcGetDevModeState},
|
||||
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
|
||||
|
|
|
|||
6
ota.go
6
ota.go
|
|
@ -30,6 +30,7 @@ func initOta() {
|
|||
},
|
||||
GetLocalVersion: GetLocalVersion,
|
||||
HwReboot: hwReboot,
|
||||
ResetConfig: rpcResetConfig,
|
||||
OnStateUpdate: func(state *ota.RPCState) {
|
||||
triggerOTAStateUpdate(state)
|
||||
},
|
||||
|
|
@ -144,14 +145,15 @@ func rpcTryUpdate() error {
|
|||
return rpcTryUpdateComponents(tryUpdateComponents{
|
||||
AppTargetVersion: "",
|
||||
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{
|
||||
DeviceID: GetDeviceID(),
|
||||
IncludePreRelease: includePreRelease,
|
||||
CheckOnly: checkOnly,
|
||||
ResetConfig: resetConfig,
|
||||
}
|
||||
|
||||
logger.Info().Interface("components", components).Msg("components")
|
||||
|
|
|
|||
|
|
@ -189,6 +189,8 @@ export default function SettingsAdvancedRoute() {
|
|||
},
|
||||
includePreRelease: devChannel,
|
||||
checkOnly: true,
|
||||
// no need to reset config for a check only update
|
||||
resetConfig: false,
|
||||
};
|
||||
send("tryUpdateComponents", params, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) {
|
||||
|
|
@ -199,6 +201,8 @@ export default function SettingsAdvancedRoute() {
|
|||
}
|
||||
const pageParams = new URLSearchParams();
|
||||
pageParams.set("downgrade", "true");
|
||||
// TODO: implement this
|
||||
pageParams.set("resetConfig", "true");
|
||||
pageParams.set("components", updateTarget == "both" ? "app,system" : updateTarget);
|
||||
|
||||
// Navigate to update page
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ export default function SettingsGeneralUpdateRoute() {
|
|||
},
|
||||
includePreRelease: true,
|
||||
checkOnly: false,
|
||||
// TODO: implement this
|
||||
resetConfig: false,
|
||||
});
|
||||
setModalView("updating");
|
||||
}, [send, setModalView, updateComponents]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue