ietf-factory-default: Implement factory reset

fixes #157, fixes #156
This commit is contained in:
Mattias Walström
2023-10-24 12:25:38 +02:00
committed by Joachim Wiberg
parent d66740250c
commit f224d0d03d
6 changed files with 46 additions and 0 deletions
+12
View File
@@ -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
View File
@@ -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 \
+3
View File
@@ -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;
+3
View File
@@ -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);
+22
View File
@@ -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
View File
@@ -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"/>