From dead6f12a3b7b92a0b2b3cf0adb8d07007aea5ea Mon Sep 17 00:00:00 2001
From: Krisjanis Rijnieks <krisjanis.rijnieks@gmail.com>
Date: Wed, 27 Apr 2022 19:27:03 +0300
Subject: [PATCH] Use library location from outside the inventory test script

---
 tests/inventory.sh | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/inventory.sh b/tests/inventory.sh
index 16af54c..b269667 100755
--- a/tests/inventory.sh
+++ b/tests/inventory.sh
@@ -5,6 +5,21 @@
 
 # TODO: Create whitelist (some parts from DigiKey are not electronics parts)
 
+# The location of the library can change. Supply it from outside.
+if [[ ! ${1} ]]; then
+  echo "Please specify KiCad library file."
+  echo "Usage: ./inventory.sh ../fab.kicad_sym"
+  exit 1
+fi
+
+# Check if file exists
+if [[ ! -f ${1} ]]; then
+  echo "Library file does not exist."
+  echo "Make sure the path to the library file is correct."
+  exit 1
+fi
+
+LIBRARY_FILE=${1}
 INVENTORY_URL="http://inventory.fabcloud.io/data/inv.json"
 SOURCE="Digi-Key"
 
@@ -19,7 +34,7 @@ ERRORS=0
 echo "This script looks for parts that are not in the KiCad fab library yet. In order to add parts, make sure that the manufacturer number of the part is added to the keywords section of the library symbol."
 
 # Read keywords from all KiCad fab library symbols
-KEYWORD_LINES=$(cat ../fab.kicad_sym | grep --extended-regexp --only-matching -U 'property "ki_keywords" "([^"]*)"')
+KEYWORD_LINES=$(cat ${LIBRARY_FILE} | grep --extended-regexp --only-matching -U 'property "ki_keywords" "([^"]*)"')
 KEYWORDS=""
 IFS=$'\n'
 for LINE in ${KEYWORD_LINES}; do
-- 
GitLab