You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.0 KiB

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