Skip to content

Commit ae197c5

Browse files
committed
feat: allow configuration to be reset during update
1 parent e63c7fc commit ae197c5

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

internal/ota/ota.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ func (s *State) doUpdate(ctx context.Context, params UpdateParams) error {
177177
if s.rebootNeeded {
178178
scopedLogger.Info().Msg("System Rebooting due to OTA update")
179179

180+
if params.ResetConfig {
181+
scopedLogger.Info().Msg("Resetting config")
182+
if err := s.resetConfig(); err != nil {
183+
return s.componentUpdateError("Error resetting config", err, &scopedLogger)
184+
}
185+
}
186+
180187
postRebootAction := &PostRebootAction{
181188
HealthCheck: "/device/status",
182189
RedirectUrl: fmt.Sprintf("/settings/general/update?version=%s", systemUpdate.version),
@@ -198,6 +205,7 @@ type UpdateParams struct {
198205
Components []string `json:"components,omitempty"`
199206
IncludePreRelease bool `json:"includePreRelease"`
200207
CheckOnly bool `json:"checkOnly"`
208+
ResetConfig bool `json:"resetConfig"`
201209
}
202210

203211
func (s *State) getUpdateStatus(

internal/ota/state.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ type RPCState struct {
9191
// HwRebootFunc is a function that reboots the hardware
9292
type HwRebootFunc func(force bool, postRebootAction *PostRebootAction, delay time.Duration) error
9393

94+
// ResetConfigFunc is a function that resets the config
95+
type ResetConfigFunc func() error
96+
9497
// GetHTTPClientFunc is a function that returns the HTTP client
9598
type GetHTTPClientFunc func() *http.Client
9699

@@ -117,6 +120,7 @@ type State struct {
117120
reboot HwRebootFunc
118121
getLocalVersion GetLocalVersionFunc
119122
onStateUpdate OnStateUpdateFunc
123+
resetConfig ResetConfigFunc
120124
}
121125

122126
// SetTargetVersion sets the target version for a component
@@ -199,6 +203,7 @@ type Options struct {
199203
OnProgressUpdate OnProgressUpdateFunc
200204
HwReboot HwRebootFunc
201205
ReleaseAPIEndpoint string
206+
ResetConfig ResetConfigFunc
202207
}
203208

204209
// NewState creates a new OTA state
@@ -215,6 +220,7 @@ func NewState(opts Options) *State {
215220
getLocalVersion: opts.GetLocalVersion,
216221
componentUpdateStatuses: components,
217222
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
223+
resetConfig: opts.ResetConfig,
218224
}
219225
go s.confirmCurrentSystem()
220226
return s

jsonrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ var rpcHandlers = map[string]RPCHandler{
11521152
"getUpdateStatus": {Func: rpcGetUpdateStatus},
11531153
"getUpdateStatusChannel": {Func: rpcGetUpdateStatusChannel},
11541154
"tryUpdate": {Func: rpcTryUpdate},
1155-
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly"}},
1155+
"tryUpdateComponents": {Func: rpcTryUpdateComponents, Params: []string{"components", "includePreRelease", "checkOnly", "resetConfig"}},
11561156
"cancelDowngrade": {Func: rpcCancelDowngrade},
11571157
"getDevModeState": {Func: rpcGetDevModeState},
11581158
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},

ota.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func initOta() {
3030
},
3131
GetLocalVersion: GetLocalVersion,
3232
HwReboot: hwReboot,
33+
ResetConfig: rpcResetConfig,
3334
OnStateUpdate: func(state *ota.RPCState) {
3435
triggerOTAStateUpdate(state)
3536
},
@@ -144,14 +145,15 @@ func rpcTryUpdate() error {
144145
return rpcTryUpdateComponents(tryUpdateComponents{
145146
AppTargetVersion: "",
146147
SystemTargetVersion: "",
147-
}, config.IncludePreRelease, false)
148+
}, config.IncludePreRelease, false, false)
148149
}
149150

150-
func rpcTryUpdateComponents(components tryUpdateComponents, includePreRelease bool, checkOnly bool) error {
151+
func rpcTryUpdateComponents(components tryUpdateComponents, includePreRelease bool, checkOnly bool, resetConfig bool) error {
151152
updateParams := ota.UpdateParams{
152153
DeviceID: GetDeviceID(),
153154
IncludePreRelease: includePreRelease,
154155
CheckOnly: checkOnly,
156+
ResetConfig: resetConfig,
155157
}
156158

157159
logger.Info().Interface("components", components).Msg("components")

ui/src/routes/devices.$id.settings.advanced.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ export default function SettingsAdvancedRoute() {
188188
},
189189
includePreRelease: devChannel,
190190
checkOnly: true,
191+
// no need to reset config for a check only update
192+
resetConfig: false,
191193
};
192194
send("tryUpdateComponents", params, (resp: JsonRpcResponse) => {
193195
if ("error" in resp) {
@@ -198,6 +200,8 @@ export default function SettingsAdvancedRoute() {
198200
}
199201
const pageParams = new URLSearchParams();
200202
pageParams.set("downgrade", "true");
203+
// TODO: implement this
204+
pageParams.set("resetConfig", "true");
201205
pageParams.set("components", updateTarget == "both" ? "app,system" : updateTarget);
202206

203207
// Navigate to update page

ui/src/routes/devices.$id.settings.general.update.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default function SettingsGeneralUpdateRoute() {
3737
},
3838
includePreRelease: true,
3939
checkOnly: false,
40+
// TODO: implement this
41+
resetConfig: false,
4042
});
4143
setModalView("updating");
4244
}, [send, setModalView, updateComponents]);

0 commit comments

Comments
 (0)