b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Warning, problems can occur if the device restarts in the middle of this uci-default script |
| 4 | |
| 5 | # install YANG modules |
| 6 | SYSREPOCTL=`which sysrepoctl` |
| 7 | MODDIR="/etc/netopeer2/modules" |
| 8 | PERMS=600 |
| 9 | OWNER=root |
| 10 | GROUP=root |
| 11 | |
| 12 | # array of modules to install |
| 13 | MODULES="\ |
| 14 | ietf-netconf-acm@2018-02-14.yang |
| 15 | ietf-netconf@2013-09-29.yang -e writable-running -e candidate -e rollback-on-error -e validate -e startup -e url -e xpath |
| 16 | ietf-netconf-monitoring@2010-10-04.yang |
| 17 | ietf-netconf-nmda@2019-01-07.yang -e origin -e with-defaults |
| 18 | nc-notifications@2008-07-14.yang |
| 19 | notifications@2008-07-14.yang |
| 20 | ietf-x509-cert-to-name@2014-12-10.yang |
| 21 | ietf-crypto-types@2019-07-02.yang |
| 22 | ietf-keystore@2019-07-02.yang -e keystore-supported |
| 23 | ietf-truststore@2019-07-02.yang -e truststore-supported -e x509-certificates |
| 24 | ietf-tcp-common@2019-07-02.yang -e keepalives-supported |
| 25 | ietf-ssh-server@2019-07-02.yang -e local-client-auth-supported |
| 26 | ietf-tls-server@2019-07-02.yang -e local-client-auth-supported |
| 27 | ietf-netconf-server@2019-07-02.yang -e ssh-listen -e tls-listen -e ssh-call-home -e tls-call-home" |
| 28 | |
| 29 | # functions |
| 30 | INSTALL_MODULE() { |
| 31 | local module=`echo "$1" | sed 's/\s.*$//'` |
| 32 | $SYSREPOCTL -a -i $MODDIR/$module -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2 |
| 33 | local rc=$? |
| 34 | if [ $rc -ne 0 ]; then |
| 35 | exit $rc |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | UPDATE_MODULE() { |
| 40 | $SYSREPOCTL -a -U $MODDIR/$1 -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2 |
| 41 | local rc=$? |
| 42 | if [ $rc -ne 0 ]; then |
| 43 | exit $rc |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | ENABLE_FEATURE() { |
| 48 | $SYSREPOCTL -a -c $1 -e $2 -v2 |
| 49 | local rc=$? |
| 50 | if [ $rc -ne 0 ]; then |
| 51 | exit $rc |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | ENABLE_FEATURES() { |
| 56 | # parse sysrepoctl features and add extra space at the end for easier matching |
| 57 | local sctl_features="`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{6\}\(.*\)/\2/'` " |
| 58 | # parse features we want to enable |
| 59 | local features=`echo "$1" | sed 's/[^ ]* \(.*\)/\1/'` |
| 60 | while [ "${features:0:3}" = "-e " ]; do |
| 61 | # skip "-e " |
| 62 | features=${features:3} |
| 63 | # parse feature |
| 64 | local feature=`echo "$features" | sed 's/\([^[:space:]]*\).*/\1/'` |
| 65 | |
| 66 | # enable feature if not already |
| 67 | sctl_feature=`echo "$sctl_features" | grep " ${feature} "` |
| 68 | if [ -z "$sctl_feature" ]; then |
| 69 | # enable feature |
| 70 | ENABLE_FEATURE $name $feature |
| 71 | fi |
| 72 | |
| 73 | # next iteration, skip this feature |
| 74 | features=`echo "$features" | sed 's/[^[:space:]]* \(.*\)/\1/'` |
| 75 | done |
| 76 | } |
| 77 | |
| 78 | # get current modules |
| 79 | SCTL_MODULES=`$SYSREPOCTL -l` |
| 80 | |
| 81 | IFS=$'\n' |
| 82 | for i in $MODULES; do |
| 83 | name=`echo "$i" | sed 's/\([^@]*\).*/\1/'` |
| 84 | |
| 85 | SCTL_MODULE=`echo "$SCTL_MODULES" | grep "^$name \+|[^|]*| I"` |
| 86 | if [ -z "$SCTL_MODULE" ]; then |
| 87 | # install module |
| 88 | INSTALL_MODULE "$i" |
| 89 | ENABLE_FEATURES "$i" |
| 90 | continue |
| 91 | fi |
| 92 | |
| 93 | sctl_revision=`echo "$SCTL_MODULE" | sed 's/[^|]*| \([^ ]*\).*/\1/'` |
| 94 | revision=`echo "$i" | sed 's/[^@]*@\([^\.]*\).*/\1/'` |
| 95 | if [ "$sctl_revision" \< "$revision" ]; then |
| 96 | # update module without any features |
| 97 | file=`echo "$i" | cut -d' ' -f 1` |
| 98 | UPDATE_MODULE $file |
| 99 | fi |
| 100 | |
| 101 | ENABLE_FEATURES "$i" |
| 102 | done |
| 103 | |
| 104 | unset IFS |
| 105 | |
| 106 | exit 0 |