diff --git a/board/common/rootfs/bin/yorn b/board/common/rootfs/bin/yorn new file mode 100755 index 000000000..e5fc4cab6 --- /dev/null +++ b/board/common/rootfs/bin/yorn @@ -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 diff --git a/src/confd/src/Makefile.am b/src/confd/src/Makefile.am index 2e7e7c6d6..f89fcec48 100644 --- a/src/confd/src/Makefile.am +++ b/src/confd/src/Makefile.am @@ -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 \ diff --git a/src/confd/src/core.c b/src/confd/src/core.c index 236e4c588..6fff8bc78 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -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; diff --git a/src/confd/src/core.h b/src/confd/src/core.h index 0ddff64a4..3a7fa44bc 100644 --- a/src/confd/src/core.h +++ b/src/confd/src/core.h @@ -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); diff --git a/src/confd/src/ietf-factory-default.c b/src/confd/src/ietf-factory-default.c new file mode 100644 index 000000000..39e443484 --- /dev/null +++ b/src/confd/src/ietf-factory-default.c @@ -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; +} diff --git a/src/klish-plugin-infix/xml/infix.xml b/src/klish-plugin-infix/xml/infix.xml index ad97b12e5..e182ab992 100644 --- a/src/klish-plugin-infix/xml/infix.xml +++ b/src/klish-plugin-infix/xml/infix.xml @@ -305,6 +305,11 @@ jq -C . /cfg/startup-config.cfg + + /bin/yorn "This will restore the device to factory state" + /ietf-factory-default:factory-reset + +