1#!/bin/bash
2# Copyright 2023 Google Inc. All rights reserved.
3
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7
8#     http://www.apache.org/licenses/LICENSE-2.0
9
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This script loops over all dot file in scanning_dir folder and
17# generates all mapped png and svg files with same file names
18# To use this script run ==>  ./graphviz_generator.sh input_fodler_path
19
20scanning_dir=$1
21
22# Find all visgraph dot files recuresively in scanning_dir
23all_dot_file_paths=`find "$scanning_dir" -type f -name "*.dot"`
24
25for file_path in $all_dot_file_paths
26do
27   echo $file_path
28   # Extract file name from file path and remove extensions
29   file_name="$(basename "$file_path" | cut -d. -f1)"
30   # Extract file directory from file path
31   file_dir="$(dirname -- $file_path)"
32   # Generate png and svg output files from input dot file
33   dot -Tpng $file_path > $file_dir/$file_name.png;
34   dot -Tsvg $file_path > $file_dir/$file_name.svg;
35done
36