#!/usr/bin/env bash
# --- T2-COPYRIGHT-NOTE-BEGIN ---
# T2 SDE: scripts/Find-Pkg
# Copyright (C) 2004 - 2023 The T2 SDE Project
# 
# This Copyright note is generated by scripts/Create-CopyPatch,
# more information can be found in the files COPYING and README.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.
# --- T2-COPYRIGHT-NOTE-END ---

matched=0

echo "Searching for matching package names ..."
pkg="`echo "$1" | tr A-Z a-z`"
x="`cd package/; ls -d */*$pkg* 2>/dev/null`"

if [ -n "$x" ]; then
	echo -e "$x\n"
	matched=1
fi

echo "Searching in package descriptions (may take some time) ..."
# grep --color does not work with -i (at least not in GNU sed 2.5.1),
# so colorize via sed
grep -i "[(\I\|T\)].*$1" package/*/*/*.desc | sed "/$1/I s//\o033[31;1m&\o033[0m/g"
[ $? -eq 0 ] && matched=1

[ $matched = 0 ] && echo "No match found ..."