Skip to content

Commit

Permalink
ietf-factory-default: Implement factory reset
Browse files Browse the repository at this point in the history
fixes #157, fixes #156
  • Loading branch information
mattiaswal committed Oct 24, 2023
1 parent d667402 commit 6452198
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions board/common/rootfs/bin/yorn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
Q=$@

echo "$Q, are you sure? (y/N)"
read -n1 yorn

if [ x$yorn != "xy" ]; then
echo "Ok, aborting"
exit 1
fi

exit 0
1 change: 1 addition & 0 deletions src/confd/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ confd_plugin_la_SOURCES = \
dagger.c dagger.h \
ietf-interfaces.c \
ietf-system.c \
ietf-factory-default.c \
infix-dhcp.c \
infix-services.c \
infix-factory.c \
Expand Down
3 changes: 3 additions & 0 deletions src/confd/src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
rc = infix_factory_init(&confd);
if (rc)
goto err;
rc = ietf_factory_default_init(&confd);
if(rc)
goto err;
rc = infix_system_sw_init(&confd);
if (rc)
goto err;
Expand Down
3 changes: 3 additions & 0 deletions src/confd/src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ int ietf_system_init(struct confd *confd);
/* infix-dhcp.c */
int infix_dhcp_init(struct confd *confd);

/* ietf-factory-default */
int ietf_factory_default_init(struct confd *confd);

/* infix-factory.c */
int infix_factory_init(struct confd *confd);

Expand Down
22 changes: 22 additions & 0 deletions src/confd/src/ietf-factory-default.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#include "core.h"

static int factory_reset(sr_session_ctx_t *session, uint32_t sub_id, const char *xpath,
const sr_val_t *input, const size_t input_cnt, sr_event_t event,
unsigned request_id, sr_val_t **output, size_t *output_cnt, void *priv)
{
DEBUG("%s", xpath);
return systemf("factory -y");
}

int ietf_factory_default_init(struct confd *confd)
{
int rc;

REGISTER_RPC(confd->session, "/ietf-factory-default:factory-reset", factory_reset, NULL, &confd->fsub);
return SR_ERR_OK;
fail:
ERROR("failed: %s", sr_strerror(rc));
return rc;
}
5 changes: 5 additions & 0 deletions src/klish-plugin-infix/xml/infix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@
<ACTION sym="script">jq -C . /cfg/startup-config.cfg</ACTION>
</COMMAND>
</COMMAND>
<COMMAND name="factory-reset" help="Restore the system to factory state">
<ACTION sym="script" interactive="true">/bin/yorn "This will restore the device to factory state"</ACTION>
<ACTION sym="rpc@infix">/ietf-factory-default:factory-reset</ACTION>
</COMMAND>


<COMMAND name="follow" help="Monitor a log file, use Ctrl-C to abort">
<PARAM name="fn" ptype="/LOGFILES" help="Optional log file to monitor, default: syslog"/>
Expand Down

0 comments on commit 6452198

Please sign in to comment.