blob: 759b35f74aad76824a401edc4f8592ef0f43b6f3 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/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
6SYSREPOCTL=`which sysrepoctl`
7MODDIR="/etc/netopeer2/modules"
8PERMS=600
9OWNER=root
10GROUP=root
11
12# array of modules to install
13MODULES="\
14ietf-netconf-acm@2018-02-14.yang
15ietf-netconf@2013-09-29.yang -e writable-running -e candidate -e rollback-on-error -e validate -e startup -e url -e xpath
16ietf-netconf-monitoring@2010-10-04.yang
17ietf-netconf-nmda@2019-01-07.yang -e origin -e with-defaults
18nc-notifications@2008-07-14.yang
19notifications@2008-07-14.yang
20ietf-x509-cert-to-name@2014-12-10.yang
21ietf-crypto-types@2019-07-02.yang
22ietf-keystore@2019-07-02.yang -e keystore-supported
23ietf-truststore@2019-07-02.yang -e truststore-supported -e x509-certificates
24ietf-tcp-common@2019-07-02.yang -e keepalives-supported
25ietf-ssh-server@2019-07-02.yang -e local-client-auth-supported
26ietf-tls-server@2019-07-02.yang -e local-client-auth-supported
27ietf-netconf-server@2019-07-02.yang -e ssh-listen -e tls-listen -e ssh-call-home -e tls-call-home"
28
29# functions
30INSTALL_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
39UPDATE_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
47ENABLE_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
55ENABLE_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
79SCTL_MODULES=`$SYSREPOCTL -l`
80
81IFS=$'\n'
82for 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"
102done
103
104unset IFS
105
106exit 0