From 6f7d97c654aa3500f285f69497ee37fa6405ff6a Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 17 Jun 2024 16:30:46 +0300 Subject: [PATCH] [#2914] extended documentation with for loops in scripts --- doc/sphinx/arm/hooks-run-script.rst | 38 ++++++++++++++++++++- src/hooks/dhcp/run_script/run_script.dox | 42 +++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/arm/hooks-run-script.rst b/doc/sphinx/arm/hooks-run-script.rst index 8ec790695b..d1b424a7b8 100644 --- a/doc/sphinx/arm/hooks-run-script.rst +++ b/doc/sphinx/arm/hooks-run-script.rst @@ -85,7 +85,7 @@ An example of a script implementing all hook points is presented below: :: - #!/bin/bash + #!/bin/sh unknown_handle() { echo "Unhandled function call ${*}" @@ -625,3 +625,39 @@ at 0. LEASE6_PREFERRED_LIFETIME LEASE6_PREFIX_LEN LEASE6_TYPE + +The leases4_committed hook point needs for loops to handle the list of addresses. +This can be achived in the following way: + +:: + + leases4_committed() { + for i in $(seq 0 $((LEASES4_SIZE-1))); do + LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS") + ... + done + + for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do + DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS") + ... + done + exit 0 + } + +The leases6_committed hook point needs for loops to handle the list of addresses. +This can be achived in the following way: + +:: + + leases6_committed() { + for i in $(seq 0 $((LEASES6_SIZE-1))); do + LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS") + ... + done + + for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do + DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS") + ... + done + exit 0 + } \ No newline at end of file diff --git a/src/hooks/dhcp/run_script/run_script.dox b/src/hooks/dhcp/run_script/run_script.dox index 3fbcd12ffe..585c983a13 100644 --- a/src/hooks/dhcp/run_script/run_script.dox +++ b/src/hooks/dhcp/run_script/run_script.dox @@ -101,7 +101,7 @@ the hook point. An example of a script implementing all hook points is presented below. @code -#!/bin/bash +#!/bin/sh unknown_handle() { echo "Unhandled function call ${*}" @@ -666,6 +666,46 @@ LEASE6_TYPE @endcode +The leases4_committed hook point needs for loops to handle the list of addresses. +This can be achived in the following way: + +@code + +leases4_committed() { + for i in $(seq 0 $((LEASES4_SIZE-1))); do + LEASE4_ADDRESS=$(eval "echo \$LEASES4_AT${i}_ADDRESS") + ... + done + + for i in $(seq 0 $((DELETED_LEASES4_SIZE-1))); do + DELETED_LEASE4_ADDRESS=$(eval "echo \$DELETED_LEASES4_AT${i}_ADDRESS") + ... + done + exit 0 +} + +@endcode + +The leases6_committed hook point needs for loops to handle the list of addresses. +This can be achived in the following way: + +@code + +leases6_committed() { + for i in $(seq 0 $((LEASES6_SIZE-1))); do + LEASE6_ADDRESS=$(eval "echo \$LEASES6_AT${i}_ADDRESS") + ... + done + + for i in $(seq 0 $((DELETED_LEASES6_SIZE-1))); do + DELETED_LEASE6_ADDRESS=$(eval "echo \$DELETED_LEASES6_AT${i}_ADDRESS") + ... + done + exit 0 +} + +@endcode + @section libdhcp_run_scriptMTCompatibility Multi-Threading Compatibility The Run Script hooks library is compatible with multi-threading. -- 2.47.2