refactor 'whatprovides' script
- Properly handle arguments. - Remove functions where not necessary. - Update help info.
This commit is contained in:
parent
b6d1503aa6
commit
8ad9e1cbf9
51
whatprovides
51
whatprovides
|
@ -1,40 +1,33 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SCRIPTNAME=whatprovides
|
set -e
|
||||||
TWSRC="$PREFIX/opt/whatprovides/db"
|
|
||||||
package () {
|
|
||||||
cat "$TWSRC/$@"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
finder () {
|
SCRIPT_NAME=$(basename "$(realpath "$0")")
|
||||||
abs=`realpath $@`
|
DB_PATH="/data/data/com.termux/files/usr/share/whatprovides/db"
|
||||||
grep -rwh $abs $TWSRC
|
|
||||||
}
|
|
||||||
|
|
||||||
show_usage () {
|
show_usage () {
|
||||||
echo "Usage: $SCRIPTNAME [options] filepath"
|
echo
|
||||||
echo "$SCRIPTNAME is a whatprovides of termux."
|
echo "Usage: $SCRIPT_NAME [options] path/to/file"
|
||||||
echo " "
|
echo
|
||||||
echo "-p [Package] list files of package."
|
echo "Find out packages using specific files."
|
||||||
echo "-h show this help"
|
echo
|
||||||
|
echo "Options:"
|
||||||
|
echo
|
||||||
|
echo " -h Show this help."
|
||||||
|
echo " -p [package] List files of package."
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts :hp:f: option; do
|
while getopts :hp:f: option; do
|
||||||
case $option in
|
case "$option" in
|
||||||
p)
|
p) cat "${DB_PATH}/${OPTARG}"; exit 0;;
|
||||||
pkg=$OPTARG
|
?|h) show_usage; exit 0;;
|
||||||
package $pkg
|
*) show_usage; exit 1;;
|
||||||
;;
|
|
||||||
h) show_usage;;
|
|
||||||
?) show_usage
|
|
||||||
exit ;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $@ == "" ]]
|
if [ $# -ge 1 ]; then
|
||||||
then
|
grep -rwh "$(realpath "$1")" "$DB_PATH"
|
||||||
|
else
|
||||||
show_usage
|
show_usage
|
||||||
elif [[ ! $@ =~ ^\-.+ ]]
|
exit 1
|
||||||
then
|
|
||||||
finder $@
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue