Initial commit of the O1 simulator framework.
[sim/o1-interface.git] / ntsimulator / yang / auto-load-yangs.sh
1 #!/bin/bash
2
3 echo "Installing YANG models..."
4
5 set -eu -o pipefail
6
7 shopt -s failglob
8
9 : ${SYSREPOCTL:=sysrepoctl}
10 : ${SYSREPOCFG:=sysrepocfg}
11 : ${SYSREPOAPPSTART:=/opt/dev/sysrepo/build/examples/application_example}
12
13 declare -a excludedModules=()
14
15 sleep 5
16
17 pyang -f clearmust *.yang
18
19 mapfile -t modelList < <(pyang -f depend --depend-recurse *.yang)
20
21 for model in *.yang
22 do
23   echo "Removing config false from $model..."
24   sed -i '/config false;/d' $model
25   echo "Removing mandatory true from $model..."
26   sed -i '/mandatory true;/d' $model
27 done
28
29 if [ ${#modelList[@]} -eq 0 ]; then
30   echo "No models present, nothing to do..."
31   exit 0
32 else
33   for model in ${modelList[@]}
34   do
35     modelName=${model%".yang"}
36     
37     skip_model=false
38     
39     for excluded in ${excludedModules[@]}; do
40       if [ "$excluded" == "$modelName" ]; then
41         skip_model=true
42       fi
43     done
44     
45     if [ "$skip_model" = true ]; then
46       echo "Skipping installation of excluded model $modelName..."
47       continue
48     fi
49     
50     echo "Installing model: $model"
51     $SYSREPOCTL --install --yang=$model --owner=root:root --permissions=666
52     
53         mapfile -t featureList < <(pyang -f listfeature $model)
54   
55     if [ ${#featureList[@]} -eq 0 ]; then
56       echo "No features, nothing to do here..."
57     else
58       for feature in ${featureList[@]}
59       do
60         $SYSREPOCTL --feature-enable=$feature --module=$modelName
61       done
62     fi
63     
64     #if the YANG model contains only typedefs, we do not need to subscribe for datastore changes
65     isTypeOnly=$(pyang -f listfeature --is-type-only $model)
66     
67     if [ "$isTypeOnly" == "False" ]; then
68       printf "\n[program:$modelName]\ncommand=/opt/dev/sysrepo/build/examples/application_example $modelName\nautorestart=false\nredirect_stderr=true\nstartretries=1\npriority=4\n" >> /etc/supervisord.conf  
69     fi
70     
71   done
72 fi
73
74 # Fix for the NETCONF notifications
75 echo "Fixing the NETCONF notifications..."
76 mkdir -p /var/run/sysrepo-subscriptions/ietf-crypto-types
77
78 echo "YANG models installation done!"
79
80 exit 0