Refactor folder structure.
[sim/o1-interface.git] / ntsimulator / yang / auto-load-yangs.sh
1 #!/bin/bash
2 ################################################################################
3 #
4 # Copyright 2019 highstreet technologies GmbH and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 #     http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ################################################################################
18
19 echo "Installing YANG models..."
20
21 set -eu -o pipefail
22
23 shopt -s failglob
24
25 : ${SYSREPOCTL:=sysrepoctl}
26 : ${SYSREPOCFG:=sysrepocfg}
27 : ${SYSREPOAPPSTART:=/opt/dev/sysrepo/build/examples/application_example}
28
29 declare -a excludedModules=()
30
31 sleep 5
32
33 pyang -f clearmust *.yang
34
35 mapfile -t modelList < <(pyang -f depend --depend-recurse *.yang)
36
37 for model in *.yang
38 do
39   echo "Removing config false from $model..."
40   sed -i '/config false;/d' $model
41   echo "Removing mandatory true from $model..."
42   sed -i '/mandatory true;/d' $model
43 done
44
45 if [ ${#modelList[@]} -eq 0 ]; then
46   echo "No models present, nothing to do..."
47   exit 0
48 else
49   for model in ${modelList[@]}
50   do
51     modelName=${model%".yang"}
52     
53     skip_model=false
54     
55     for excluded in ${excludedModules[@]}; do
56       if [ "$excluded" == "$modelName" ]; then
57         skip_model=true
58       fi
59     done
60     
61     if [ "$skip_model" = true ]; then
62       echo "Skipping installation of excluded model $modelName..."
63       continue
64     fi
65     
66     echo "Installing model: $model"
67     $SYSREPOCTL --install --yang=$model --owner=root:root --permissions=666
68     
69         mapfile -t featureList < <(pyang -f listfeature $model)
70   
71     if [ ${#featureList[@]} -eq 0 ]; then
72       echo "No features, nothing to do here..."
73     else
74       for feature in ${featureList[@]}
75       do
76         $SYSREPOCTL --feature-enable=$feature --module=$modelName
77       done
78     fi
79     
80     #if the YANG model contains only typedefs, we do not need to subscribe for datastore changes
81     isTypeOnly=$(pyang -f listfeature --is-type-only $model)
82     
83     if [ "$isTypeOnly" == "False" ]; then
84       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  
85     fi
86     
87   done
88 fi
89
90 # Fix for the NETCONF notifications
91 echo "Fixing the NETCONF notifications..."
92 mkdir -p /var/run/sysrepo-subscriptions/ietf-crypto-types
93
94 echo "YANG models installation done!"
95
96 exit 0