-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
confd: refactor yang modules setup script for better modularity and m…
…aintainability - Moved setup.sh and yang_modules files from infix/src/confd/scripts/ to infix/utils/ to streamline the repository structure - Updated confd.mk to correctly reference the new location of the setup script - Introduced yang_modules_<type>.inc file to list all YANG modules for improved clarity and maintainability - Modified the new setup script to dynamically source module lists from yang_modules_<type>.inc
- Loading branch information
1 parent
8baca7d
commit 7d9257f
Showing
4 changed files
with
214 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
MODULES=( | ||
"[email protected] -e authentication -e local-users -e ntp -e ntp-udp-port -e timezone-name" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected] -e keepalives-supported" | ||
"[email protected] -e if-mib" | ||
"[email protected] -e ipv6-privacy-autoconf" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected] -e origin -e with-defaults" | ||
"[email protected] -e encode-xml -e replay -e subtree -e xpath" | ||
"[email protected] -e on-change" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected] -e bfd -e explicit-router-id" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected] -e hardware-state" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
"[email protected]" | ||
# from sysrepo | ||
"[email protected]" | ||
# from netopeer | ||
"[email protected]" | ||
"[email protected] -e encrypted-private-keys" | ||
"[email protected] -e ssh-listen -e tls-listen -e ssh-call-home -e tls-call-home" | ||
"[email protected]" | ||
"[email protected] -e writable-running -e candidate -e rollback-on-error -e validate -e startup -e url -e xpath -e confirmed-commit" | ||
"[email protected] -e central-truststore-supported -e certificates" | ||
"[email protected] -e central-keystore-supported -e inline-definitions-supported -e asymmetric-keys -e symmetric-keys" | ||
"[email protected] -e local-user-auth-password -e local-user-auth-publickey" | ||
"[email protected] -e server-ident-raw-public-key -e server-ident-x509-cert" | ||
"[email protected]" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MODULES=( | ||
"[email protected] -e vlan-filtering -e containers" | ||
"[email protected]" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env bash | ||
set -x | ||
# This is based on scripts/setup.sh from Netopeer2/libnetconf2 | ||
# env variables NP2_MODULE_DIR, NP2_MODULE_PERMS must be defined and NP2_MODULE_OWNER, NP2_MODULE_GROUP will be used if | ||
# defined when executing this script! | ||
#if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" ]; then | ||
# echo "Required environment variables not defined!" | ||
# exit 1 | ||
#fi | ||
|
||
|
||
# Source the provided file, which is expected to contain the list of YANG modules and their features. | ||
# This file, specified by the first argument to the script ($1), is sourced to populate the MODULES | ||
# array with the modules and their respective features to be processed by this script. | ||
# The file typically includes definitions in the form of module@revision with optional features to enable, | ||
# e.g., module@revision -e feature1 -e feature2. | ||
source $1 | ||
|
||
# optional env variable override | ||
if [ -n "$SYSREPOCTL_EXECUTABLE" ]; then | ||
SYSREPOCTL="$SYSREPOCTL_EXECUTABLE" | ||
# avoid problems with sudo PATH | ||
elif [ `id -u` -eq 0 ] && [ -n "$USER" ] && [ `command -v su` ]; then | ||
SYSREPOCTL=`command -v sysrepoctl -l $USER` | ||
else | ||
SYSREPOCTL=`command -v sysrepoctl` | ||
fi | ||
|
||
MODDIR=${SEARCH_PATH} | ||
PERMS="660" | ||
#OWNER=root | ||
#GROUP=wheel | ||
|
||
CMD_INSTALL= | ||
|
||
# functions | ||
INSTALL_MODULE_CMD() { | ||
if [ -z "${CMD_INSTALL}" ]; then | ||
CMD_INSTALL="'$SYSREPOCTL' -s $MODDIR -v2" | ||
fi | ||
CMD_INSTALL="$CMD_INSTALL -i $MODDIR/$1 -p '$PERMS'" | ||
if [ ! -z "${OWNER}" ]; then | ||
CMD_INSTALL="$CMD_INSTALL -o '$OWNER'" | ||
fi | ||
if [ ! -z "${GROUP}" ]; then | ||
CMD_INSTALL="$CMD_INSTALL -g '$GROUP'" | ||
fi | ||
} | ||
|
||
UPDATE_MODULE() { | ||
CMD="'$SYSREPOCTL' -U $MODDIR/$1 -s '$MODDIR -v2" | ||
eval $CMD | ||
local rc=$? | ||
if [ $rc -ne 0 ]; then | ||
exit $rc | ||
fi | ||
} | ||
|
||
CHANGE_PERMS() { | ||
CMD="'$SYSREPOCTL' -c $1 -p '$PERMS' -v2" | ||
if [ ! -z "${OWNER}" ]; then | ||
CMD="$CMD -o '$OWNER'" | ||
fi | ||
if [ ! -z "${GROUP}" ]; then | ||
CMD="$CMD -g '$GROUP'" | ||
fi | ||
eval $CMD | ||
local rc=$? | ||
if [ $rc -ne 0 ]; then | ||
exit $rc | ||
fi | ||
} | ||
|
||
ENABLE_FEATURE() { | ||
"$SYSREPOCTL" -c $1 -e $2 -v2 | ||
local rc=$? | ||
if [ $rc -ne 0 ]; then | ||
exit $rc | ||
fi | ||
} | ||
|
||
# get current modules | ||
SCTL_MODULES=`$SYSREPOCTL -l` | ||
for i in "${MODULES[@]}"; do | ||
name=`echo "$i" | sed 's/\([^@]*\).*/\1/'` | ||
|
||
SCTL_MODULE=`echo "$SCTL_MODULES" | grep "^$name \+|[^|]*| I"` | ||
if [ -z "$SCTL_MODULE" ]; then | ||
# prepare command to install module with all its features | ||
INSTALL_MODULE_CMD "$i" | ||
continue | ||
fi | ||
|
||
sctl_revision=`echo "$SCTL_MODULE" | sed 's/[^|]*| \([^ ]*\).*/\1/'` | ||
revision=`echo "$i" | sed 's/[^@]*@\([^\.]*\).*/\1/'` | ||
if [ "$sctl_revision" \< "$revision" ]; then | ||
# update module without any features | ||
file=`echo "$i" | cut -d' ' -f 1` | ||
UPDATE_MODULE "$file" | ||
fi | ||
|
||
sctl_owner=`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{3\} \([^:]*\).*/\2/'` | ||
sctl_group=`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{3\}[^:]*:\([^ ]*\).*/\2/'` | ||
sctl_perms=`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{4\} \([^ ]*\).*/\2/'` | ||
if [ "$sctl_perms" != "$PERMS" ]; then | ||
# change permissions/owner | ||
CHANGE_PERMS "$name" | ||
fi | ||
|
||
# parse sysrepoctl features and add extra space at the end for easier matching | ||
sctl_features="`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{6\}\(.*\)/\2/'` " | ||
# parse features we want to enable | ||
features=`echo "$i" | sed 's/[^ ]* \(.*\)/\1/'` | ||
while [ "${features:0:3}" = "-e " ]; do | ||
# skip "-e " | ||
features=${features:3} | ||
# parse feature | ||
feature=`echo "$features" | sed 's/\([^[:space:]]*\).*/\1/'` | ||
|
||
# enable feature if not already | ||
sctl_feature=`echo "$sctl_features" | grep " ${feature} "` | ||
if [ -z "$sctl_feature" ]; then | ||
# enable feature | ||
ENABLE_FEATURE $name $feature | ||
fi | ||
|
||
# next iteration, skip this feature | ||
features=`echo "$features" | sed 's/[^[:space:]]* \(.*\)/\1/'` | ||
done | ||
done | ||
# install all the new modules | ||
if [ ! -z "${CMD_INSTALL}" ]; then | ||
eval $CMD_INSTALL | ||
rc=$? | ||
if [ $rc -ne 0 ]; then | ||
exit $rc | ||
fi | ||
fi |