Fix typo in script
[integration/distribution.git] / karaf-scripts / src / main / assembly / bin / check_modules.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Lumina Networks, Inc. and others. All rights reserved.
4 #
5 # This program and the accompanying materials are made available under the
6 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 # and is available at http://www.eclipse.org/legal/epl-v10.html
8 #
9 #
10 # This script checks the YANG modules collected by the extract_modules.sh
11 # script. The check is done by the pyang tool and an error text file is
12 # generated for every opendaylight project so proper actions can be taken
13 # to fix the modules.
14 #
15
16 BIN_DIR=`dirname $0`
17 OUTPUT="$BIN_DIR/../opendaylight-models"
18
19 # Exit if yang module folder is not found
20 [ ! -d "$OUTPUT" ] && echo "ERROR: no modules found, run extract_module.sh first" && exit 1
21
22 # Assemble the pyang command options
23 flags=""
24 PROJECTS=`ls -d $OUTPUT/*`
25 for proj in $PROJECTS; do
26     proj=`basename $proj`
27     flags="$flags -p  $OUTPUT/$proj"
28 done
29
30 # Run pyang on opendaylight yang modules and generate error file per project
31 for proj in $PROJECTS; do
32     proj=`basename $proj`
33     [ -f "$OUTPUT/$proj/errors.txt" ] && rm $OUTPUT/$proj/errors.txt
34     touch $OUTPUT/$proj/errors.txt
35     YANGS=`find $OUTPUT/$proj -type f -name '*.yang'`
36     for yang in $YANGS; do
37         less $yang | grep -q namespace.*opendaylight &&
38         echo $yang && pyang $flags $yang 2>> $OUTPUT/$proj/errors.txt
39     done
40     echo "Write error file: $OUTPUT/$proj/errors.txt"
41 done