check whether db exists before trying to open it

This commit is contained in:
Leonid Pliushch 2020-11-20 03:02:32 +02:00
parent 712f54797f
commit fdcf1f8417
No known key found for this signature in database
GPG Key ID: 45F2964132545795
1 changed files with 10 additions and 0 deletions

View File

@ -39,9 +39,18 @@ update_database() {
echo "[*] Finished."
}
check_database() {
if [ ! -e "${DB_PATH}" ]; then
echo "Error: database is not available."
echo "Please run '${SCRIPT_NAME} -u' to create it."
return 1
fi
}
while getopts :hp:u option; do
case "$option" in
p)
check_database
echo "SELECT owned_file FROM 'whatprovides' WHERE package_name == '${OPTARG}' ORDER BY owned_file;" | \
sqlite3 "${DB_PATH}" | awk "{ print \"${OPTARG}: \"\$0 }"
exit 0
@ -53,6 +62,7 @@ while getopts :hp:u option; do
done
if [ $# -ge 1 ]; then
check_database
echo "SELECT package_name FROM 'whatprovides' WHERE owned_file == '${1}' ORDER BY package_name;" | \
sqlite3 "${DB_PATH}" | awk "{ print \$0\": ${1}\" }"
else