check whether db exists before trying to open it
This commit is contained in:
parent
712f54797f
commit
fdcf1f8417
10
whatprovides
10
whatprovides
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue