From 7868cf0a0d35051665cb6ce46cbe23d4cc3910d6 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 10 Feb 2023 11:50:46 +0100 Subject: [PATCH] Docker example: fixed scripts to run multiple instances Fixed parenthesis typo in purge code --- apps/backend/backend_client.c | 1 - docker/example/README.md | 2 +- docker/example/cleanup.sh | 8 ++++---- docker/example/start.sh | 20 ++++++++++---------- lib/src/clixon_xml.c | 28 ++++++++++++++-------------- lib/src/clixon_xml_map.c | 2 +- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 28bca705..919a15f8 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -520,7 +520,6 @@ from_client_edit_config(clicon_handle h, goto done; goto ok; } - /* Cant do this earlier since we dont have a yang spec to * the upper part of the tree, until we get the "config" tree. */ diff --git a/docker/example/README.md b/docker/example/README.md index 90fb3723..740074fb 100644 --- a/docker/example/README.md +++ b/docker/example/README.md @@ -22,7 +22,7 @@ Start the container: If you want to install your pre-existing pub rsa key in the container, and change the name: ``` - $ SSHKEY=true NAME=clixon-example22 ./start.sh + $ SSHKEY=/home/user/.ssh/id_rsa.pub NAME=clixon-example22 ./start.sh ``` You can combine make and start by: diff --git a/docker/example/cleanup.sh b/docker/example/cleanup.sh index 1220a436..abf5d668 100755 --- a/docker/example/cleanup.sh +++ b/docker/example/cleanup.sh @@ -1,7 +1,7 @@ #!/bin/sh +# Name of container +: ${NAME:=clixon-example} + # Kill all controller containers (optionally do `make clean`) -sudo docker kill clixon-example 2> /dev/null # ignore errors - - - +sudo docker kill $NAME 2> /dev/null # ignore errors diff --git a/docker/example/start.sh b/docker/example/start.sh index e6b07280..f6d9ddf7 100755 --- a/docker/example/start.sh +++ b/docker/example/start.sh @@ -30,7 +30,7 @@ # the terms of any one of the Apache License version 2 or the GPL. # # ***** END LICENSE BLOCK ***** - +set -eux # Usage: ./startup.sh # Debug: DBG=1 ./startup.sh # See also cleanup.sh @@ -38,23 +38,23 @@ # Name of container : ${NAME:=clixon-example} -# If true also install your users pubkey -: ${SSHKEY:=false} +# If set to filename also install your users pubkey +: ${SSHKEY:=} >&2 echo "Running script: $0" -sudo docker kill clixon-example 2> /dev/null # ignore errors +sudo docker kill $NAME || true 2> /dev/null # ignore errors # Start clixon-example backend sudo docker run --name ${NAME} --rm -td clixon/clixon-example #|| err "Error starting clixon-example" # Copy rsa pubkey -if $SSHKEY; then +if [ -n "$SSHKEY" ]; then # install user pub key - sudo docker exec -it clixon-example mkdir -m 700 /root/.ssh - sudo docker cp ~/.ssh/id_rsa.pub clixon-example:/root/.ssh/authorized_keys - sudo docker exec -it clixon-example chown root /root/.ssh/authorized_keys - sudo docker exec -it clixon-example chgrp root /root/.ssh/authorized_keys + sudo docker exec -it $NAME mkdir -m 700 /root/.ssh + sudo docker cp $SSHKEY $NAME:/root/.ssh/authorized_keys + sudo docker exec -it $NAME chown root /root/.ssh/authorized_keys + sudo docker exec -it $NAME chgrp root /root/.ssh/authorized_keys fi ->&2 echo "clixon-example started" +>&2 echo "$NAME started" diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index c72fd759..27dfef01 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -350,8 +350,8 @@ xml_name(cxobj *xn) /*! Set name of xnode, name is copied * @param[in] xn xml node * @param[in] name new name, null-terminated string, copied by function - * @retval -1 on error with clicon-err set * @retval 0 OK + * @retval -1 on error with clicon-err set */ int xml_name_set(cxobj *xn, @@ -383,8 +383,8 @@ xml_prefix(cxobj *xn) /*! Set prefix of xnode, prefix is copied * @param[in] xn XML node * @param[in] prefix New prefix, null-terminated string, copied by function - * @retval -1 Error with clicon-err set * @retval 0 OK + * @retval -1 Error with clicon-err set */ int xml_prefix_set(cxobj *xn, @@ -425,8 +425,8 @@ nscache_get(cxobj *x, * @param[in] x XML node * @param[in] namespace * @param[out] prefix - * @retval 0 No prefix found * @retval 1 Prefix found + * @retval 0 No prefix found */ int nscache_get_prefix(cxobj *x, @@ -632,8 +632,8 @@ xml_value(cxobj *xn) /*! Set value of xml node, value is copied * @param[in] xn xml node * @param[in] val new value, null-terminated string, copied by function - * @retval -1 on error with clicon-err set * @retval 0 OK + * @retval -1 on error with clicon-err set */ int xml_value_set(cxobj *xn, @@ -666,8 +666,8 @@ xml_value_set(cxobj *xn, /*! Append value of xnode, value is copied * @param[in] xn xml node * @param[in] val appended value, null-terminated string, copied by function - * @retval NULL on error with clicon-err set, or if value is set to NULL * @retval new value + * @retval NULL on error with clicon-err set, or if value is set to NULL */ int xml_value_append(cxobj *xn, @@ -854,7 +854,6 @@ xml_child_i_set(cxobj *xt, /*! Get the order of child * @param[in] xp xml parent node * @param[in] xc the xml child to look for - * @retval xml The child xml node * @retval i The order of the child * @retval -1 if no such child, or empty child * @see xml_child_i @@ -1342,8 +1341,8 @@ xml_wrap_all(cxobj *xp, * After: xp --> xt(tag) --> xc * @param[in] xp Parent xml node * @param[in] tag Name of new xml child - * @retval NULL Error * @retval xc Return the new child (xc) + * @retval NULL Error * @see xml_addsub (give the parent) * @see xml_wrap_all (wrap all children of a node, not just one) */ @@ -2079,9 +2078,9 @@ cxvec_prepend(cxobj *x, * @param[in] type Matching type or -1 for any * @param[in] fn Callback * @param[in] arg Argument - * @retval -1 Error, aborted at first error encounter - * @retval 0 OK, all nodes traversed (subparts may have been skipped) * @retval 1 OK, aborted on first fn returned 1 + * @retval 0 OK, all nodes traversed (subparts may have been skipped) + * @retval -1 Error, aborted at first error encounter * * @code * int x_fn(cxobj *x, void *arg) @@ -2134,9 +2133,9 @@ xml_apply(cxobj *xn, * @param[in] type Matching type or -1 for any * @param[in] fn Callback * @param[in] arg Argument - * @retval -1 Error, aborted at first error encounter - * @retval 0 OK, all nodes traversed (subparts may have been skipped) * @retval 1 OK, aborted on first fn returned 1 + * @retval 0 OK, all nodes traversed (subparts may have been skipped) + * @retval -1 Error, aborted at first error encounter * @see xml_apply not including top object */ int @@ -2167,9 +2166,9 @@ xml_apply0(cxobj *xn, * @param[in] xn XML node * @param[in] fn Callback * @param[in] arg Argument - * @retval -1 Error, aborted at first error encounter - * @retval 0 OK, all nodes traversed * @retval n OK, aborted at first encounter of first match + * @retval 0 OK, all nodes traversed + * @retval -1 Error, aborted at first error encounter * @code * int x_fn(cxobj *x, void *arg) * { @@ -2207,8 +2206,8 @@ xml_apply_ancestor(cxobj *xn, /*! Is xpp ancestor of x? * @param[in] x XML node * @param[in] xpp Potential ancestor of x in XML tree - * @retval 0 No, xpp is not ancestor of x * @retval 1 Yes, xpp is ancestor of x + * @retval 0 No, xpp is not ancestor of x */ int xml_isancestor(cxobj *x, @@ -2304,6 +2303,7 @@ xml_operation2str(enum operation_type op) return "none"; } } + /*! Map xml insert attribute from string to enumeration * @param[in] instr String, eg "first" * @param[out] ins Enumeration, eg INS_FIRST diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 646c7bfe..58b620dd 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -481,7 +481,7 @@ xml_tree_prune_flagged_sub(cxobj *xt, x = NULL; xprev = x = NULL; while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { - if (xml_flag(x, flag) == test?flag:0){ + if (xml_flag(x, flag) == (test?flag:0)){ /* Pass test */ mark++; xprev = x;