Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
simplified package check
Browse files Browse the repository at this point in the history
  • Loading branch information
snwh committed May 21, 2018
1 parent f79430b commit 4955183
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion data/favs.list
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ gnome-software-plugin-flatpak
gnome-software-plugin-snap
gnome-sushi
gnome-tweak-tool
inkscape
nautilus
sparkleshare
transmission
10 changes: 8 additions & 2 deletions functions/check_functions
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash

# Check dpkg for package installation status
function check_package_installed() {
# query dpkg for install status and return a value
dpkg-query -W --showformat='${Status}\n' $@ | grep "install ok installed" &> /dev/null; echo $?
}

# Check if single package is installed
function check_package() {
# echo_message header "Starting 'check_package' function"
# if package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
# draw window
if (whiptail \
--title "Install ${1}" \
Expand Down Expand Up @@ -121,7 +127,7 @@ function check_dependencies {
# Check dependencies
for PACKAGE in $(cat $LIST); do
# If package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $PACKAGE | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
echo_message info "This script requires '$PACKAGE' and it is not present on your system."
echo_message question 'Would you like to install it to continue? (Y)es, (N)o : ' && read REPLY
case $REPLY in
Expand Down
6 changes: 3 additions & 3 deletions functions/install_functions
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
function install_package() {
echo_message header "Starting 'install_package' function..."
# If package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
echo_message info "${1} is not installed. Installing..."
if (whiptail \
--title "Install ${2^}" \
Expand Down Expand Up @@ -37,7 +37,7 @@ function install_package() {
function install_remote_package() {
echo_message header "Starting 'install_remote_package' function..."
# If package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $2 | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
echo_message info "$1 is not installed."
# Download Debian file that matches system architecture
case `uname -i` in
Expand Down Expand Up @@ -93,7 +93,7 @@ function install_from_list() {
# Install loop
for PACKAGE in $(cat $LIST); do
# If package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $PACKAGE | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
# Install package
echo_message warning "Package '$PACKAGE' is not installed. Installing..."
# Admin privileges
Expand Down
2 changes: 1 addition & 1 deletion functions/system_cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function purge_unused {
# Remove loop
for PACKAGE in $(cat $LIST); do
# If package is not installed
if [[ $(dpkg-query -W --showformat='${Status}\n' $PACKAGE | grep "install ok installed" &> /dev/null; echo $?) != 0 ]]; then
if [ $(check_package_installed $PACKAGE) != 0 ]; then
# Show already removed message
echo_message info "Package '$PACKAGE' already removed."
else
Expand Down

0 comments on commit 4955183

Please sign in to comment.