whatprovides/whatprovides

58 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -e
SCRIPT_NAME=$(basename "$(realpath "$0")")
DB_PATH="/data/data/com.termux/files/usr/var/lib/whatprovides/whatprovides.db"
DB_UPDATES_URL="https://dl.bintray.com/termux/metadata/whatprovides-db/whatprovides.db.gz"
show_usage () {
echo
echo "Usage: $SCRIPT_NAME [options] path/to/file"
echo
echo "Find out packages using specific files."
echo
echo "Options:"
echo
echo " -h Show this help."
echo " -p [package] List files of package."
echo " -u Update the database."
echo
}
update_database() {
if [ -e "${DB_PATH}.gz" ]; then
echo "[*] Cleaning up the remaining temporary files..."
rm -f "${DB_PATH}.gz"
fi
echo "[*] Downloading the new database..."
echo
curl --fail --retry 5 --retry-connrefused --retry-delay 5 --location \
--output "${DB_PATH}.gz" "${DB_UPDATES_URL}"
echo
echo "[*] Installing..."
rm -f "${DB_PATH}"
zcat "${DB_PATH}.gz" > "${DB_PATH}"
rm -f "${DB_PATH}.gz"
echo "[*] Finished."
}
while getopts :hp:u option; do
case "$option" in
p) cat "${DB_PATH}/${OPTARG}"; exit 0;;
u) update_database; exit 0;;
h) show_usage; exit 0;;
*) show_usage; exit 1;;
esac
done
if [ $# -ge 1 ]; then
echo "SELECT owned_file FROM 'whatprovides' WHERE package_name == '${1}' ORDER BY owned_file;" | \
sqlite3 "${DB_PATH}" | awk "{ print \"${1}: \"\$0 }"
else
show_usage
exit 1
fi