--- /dev/null
+#!/bin/sh
+#
+# Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+
+#
+# This script visits all jars within the OpenDaylight karaf distribution and extracts
+# all production YANG modules (as located in META-INF/yang)
+#
+set -e
+BIN_DIR=`dirname $0`
+OUTPUT="$BIN_DIR/../opendaylight-models"
+INPUT="$BIN_DIR/.."
+
+# FIXME: also wipe output?
+[ -d "$OUTPUT" ] || mkdir "$OUTPUT"
+
+PROJECTS=`ls -d $INPUT/system/org/opendaylight/*`
+for proj in $PROJECTS; do
+ proj=`basename $proj`
+ echo "Extracting yang modules from $proj"
+ JARS=`find $INPUT/system/org/opendaylight/$proj -type f -name '*.jar' | sort -u`
+ [ -d "$OUTPUT/$proj" ] || mkdir $OUTPUT/$proj
+ for jar in $JARS; do
+ unzip -l "$jar" | grep -q -e "\.yang$" &&
+ unzip -q "$jar" 'META-INF/yang/*' -d "$OUTPUT/$proj"
+ done
+ if [ -z "$(ls -A $OUTPUT/$proj)" ]; then
+ rm -rf $OUTPUT/$proj
+ else
+ rm -f $OUTPUT/$proj/*.yang
+ YANGS=`find $OUTPUT/$proj/META-INF/yang/ -type f -name '*.yang'`
+ for yang in $YANGS; do
+ name=`basename $yang`
+ less $yang | grep -q namespace.*opendaylight &&
+ mv $OUTPUT/$proj/META-INF/yang/$name $OUTPUT/$proj &&
+ echo " $name"
+ done
+ rm -rf $OUTPUT/$proj/META-INF
+ fi
+done
+echo -e "\nYang Modules are extracted to `readlink -f $OUTPUT`"
+++ /dev/null
-#!/bin/sh
-#
-# Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
-#
-# This program and the accompanying materials are made available under the
-# terms of the Eclipse Public License v1.0 which accompanies this distribution,
-# and is available at http://www.eclipse.org/legal/epl-v10.html
-#
-
-#
-# This script visits all jars within the OpenDaylight karaf distribution and extracts
-# all production YANG modules (as located in META-INF/yang)
-#
-set -e
-
-# FIXME: make this tuneable
-OUTPUT="opendaylight-models"
-INPUT="."
-
-JARS=`find $INPUT/system/org/opendaylight -type f -name '*.jar' | sort -u`
-
-# FIXME: also wipe output?
-[ -d "$OUTPUT" ] || mkdir "$OUTPUT"
-for jar in $JARS; do
- artifact=`basename $jar | sed 's/.jar$//'`
- echo "Extracting modules from $artifact"
- # FIXME: better control over unzip errors
- unzip -q "$jar" 'META-INF/yang/*' -d "$artifact" \
- 2>/dev/null || true
-
- dir="$artifact/META-INF/yang"
- if [ -d "$dir" ]; then
- for file in `find $dir -type f -name '*.yang'`; do
- module=`basename "$file"`
- echo -e "\t$module"
- # FIXME: better duplicate detection
- mv -n "$file" "$OUTPUT"
- done
- fi
-
- rm -rf "$artifact"
-done
-