#!/bin/bash
#####################################################
#	            WhichPkg 0.1.3			            #
#  WhichPkg is a simple gui to query rpm packages   #
#        	© 2019 lxgator@gmail.com				#
#							                        #
# lxgator@gmail.com © WTFPL 2019 	                #
#							                        #
#####################################################

NAME='WhichPkg'
VERSION='0.1.3'
ICON="/usr/share/pixmaps/whichpkg.png"
FILE='/usr/bin/whichpkg'
TMP='/tmp/installed_pkgs'

CHANGE=$(yad \
--title='WhichPkg Search' \
--window-icon=$ICON \
--text="<b>RPM query a file or folder in the filesystem</b>" \
--file \
--center \
--width=600 \
--height=450 \
--button=Cancel!/usr/share/whichpkg/icons/cancel.svg:1 \
--button=Ok!/usr/share/whichpkg/icons/ok.svg:0)
if [  $? = "0" ]; then
file=`echo $CHANGE`
realfile=$(echo $file | sed -e 's/''\/\///g' -e 's/\%20/\ /g')
pkg=$(rpm -q -f $realfile)
echo "$pkg" 
    else
exit 1
fi
results=$(echo "$pkg"| sed "s/file//g")
pkg=$(rpm -q -f $realfile)
results=$(yad \
--on-top \
--text="\n\n$results" \
--title="WhichPkg Query Results" \
--center \
--width=350 \
--height=130 \
--image=$ICON \
--back=#EDEDED \
--window-icon=$ICON \
--button=About!/usr/share/whichpkg/icons/about.svg:7 \
--button=Info!/usr/share/whichpkg/icons/help.svg:5 \
--button=Search!/usr/share/whichpkg/icons/find.svg:8 \
--button=Cancel!/usr/share/whichpkg/icons/cancel.svg:1) 
if [ $? = "5" ]; then
rpm -qa | sort > /tmp/installed_pkgs
sleep 0.25
`yad --text-info --filename="$TMP" --title="List of Installed RPMS" --window-icon=$ICON --width=600 --height=500 --button=Ok!/usr/share/whichpkg/icons/ok.svg:0`
exec /usr/bin/whichpkg 
fi |
if [ $? = "7" ]; then
`yad \
--title="About" \
--text="                              \
<b>WhichPkg</b>\n                                 \
 0.1.3\n\nWhichPkg is a simple gui to query rpm packages\n\n© 2019 WTFPL  lxgator@gmail.com\n\n" \
--width=450 \
--height=100 \
--image=$ICON \
--center \
--window-icon=$ICON \
--button=Cancel!/usr/share/whichpkg/icons/cancel.svg:1`
exit 0
fi |
if [ $? = "8" ]; then
exec /usr/bin/whichpkg
   fi 
rm -f $TMP > /dev/null 2>&1

