commit 2d09f20b4137a7d98d0b4de40934ecd7cda8543e
Author: David Sorber <david.sorber@gmail.com>
Date:   Thu Jan 24 10:13:09 2019 -0500

    Fix minor bug in calculating the queued duration. Add dependency
    checking to the install script (with a lot of bash syntax help from
    stackoverflow!).

diff --git a/software/hbkcd/hbkcd/daemon.py b/software/hbkcd/hbkcd/daemon.py
index 3076b61..d10d7cf 100755
--- a/software/hbkcd/hbkcd/daemon.py
+++ b/software/hbkcd/hbkcd/daemon.py
@@ -134,7 +134,7 @@ def main():
             elapsed_str = datetime_diff(item.encode_finished, item.encode_started)
             
             # Calculated queued time
-            queued_str = datetime_diff(item.encode_finished, item.time_added)            
+            queued_str = datetime_diff(item.encode_started, item.time_added)            
             
             # Print success or failure message to the log depending on the
             # HandBrake process's return code
diff --git a/software/hbkcd/install.sh b/software/hbkcd/install.sh
index 85f9d88..f0bcfa6 100755
--- a/software/hbkcd/install.sh
+++ b/software/hbkcd/install.sh
@@ -1,25 +1,111 @@
 #!/bin/bash
 
+BOLD='\033[1m'
+ENDC='\033[0m'
+RED='\033[0;31m'
+BOLD_RED='\033[1;31m'
+
 echo -e "hbkcd Install Script\n"
 
 if [[ $EUID -ne 0 ]]; then
-    echo "ERROR: This script must be run as root" 
+    echo -e "${BOLD_RED}ERROR:${ENDC} This script must be run as root" 
     exit 1
 fi
 
-# TODO: check and install prereqs if needed
+# Package and python module dependencies
+declare -a pkg_deps=("python3-setuptools" "python3-pip" "libmagic-dev" "pbzip2")
+declare -A pip_deps=( [python-magic]=magic )
+
+# Check each package dependency
+echo "Checking package dependencies"
+to_install=""
+for package in "${pkg_deps[@]}"
+do
+    printf "    $package..."
+    dpkg -l | grep "$package" > /dev/null
+    if [ "$?" -ne 0 ]; then
+        printf "${BOLD_RED}NOT INSTALLED${ENDC}\n"
+        if [[ -z "$to_install" ]]; then
+            to_install="$package"
+        else        
+            to_install="$to_install $package"
+        fi
+    else
+        printf "${BOLD}INSTALLED${ENDC}\n"
+    fi
+done
+printf "\n"
+
+# Attempt to install any missing packages
+if [[ -z "${to_install// }" ]]; then
+    printf "All required packages are installed.\n"
+else
+    printf "Attempting to install missing packages: $to_install\n\n"
+    sudo apt -y install "$to_install"
+    if [[ "$?" -eq 0 ]]; then
+        printf "\n\nPackage dependencies installed successfully.\n"
+    else
+        printf "\n\n${BOLD_RED}ERROR:${ENDC} unable to install package dependencies\n\n"
+        exit -1
+    fi 
+fi
+
+printf "\n\n"
+
+# Check each Python module dependency
+echo "Checking Python module dependencies"
+to_install=""
+for module in "${!pip_deps[@]}"
+do
+    printf "    $module..."
+    python3 -c "import ${pip_deps[$module]}" 2> /dev/null
+    if [ "$?" -ne 0 ]; then
+        printf "${BOLD_RED}NOT INSTALLED${ENDC}\n"
+        if [[ -z "$to_install" ]]; then
+            to_install="$module"
+        else        
+            to_install="$to_install $module"
+        fi
+    else
+        printf "${BOLD}INSTALLED${ENDC}\n"
+    fi
+done
+printf "\n"
+
+# Attempt to install any missing Python modules
+if [[ -z "${to_install// }" ]]; then
+    printf "All required Python modules are installed.\n"
+else
+    printf "Attempting to install missing Python modules: $to_install\n\n"
+    sudo pip3 install "$to_install"
+    if [[ "$?" -eq 0 ]]; then
+        printf "\n\nPython module dependencies installed successfully.\n"
+    else
+        printf "\n\n${BOLD_RED}ERROR:${ENDC} unable to install Python module dependencies\n\n"
+        exit -1
+    fi 
+fi
+
+printf "\n\n"
 
 # Install systemd config
+printf "Installing hbkcd systemd service..."
 cp conf/systemd/hbkcd.service /etc/systemd/system/
 systemctl daemon-reload
+printf "DONE\n"
+printf "\n\n"
 
 # Install hbkcd Python module
 ./setup.py install
+printf "\n\n"
 
 # Install scripts
+printf "Installing hbkcd scripts..."
 install -m 755 scripts/hbkcd_add.sh /usr/local/bin/hbkcd_add
 install -m 755 scripts/hbkcd_queue.sh /usr/local/bin/hbkcd_queue
 install -m 755 scripts/hbkcd_remove.sh /usr/local/bin/hbkcd_remove
+printf "DONE\n"
+printf "\n\n"
 
 # Start or restart hbckd 
 systemctl status hbkcd
@@ -32,4 +118,4 @@ else
     systemctl restart hbkcd
 fi
 
-echo -e "\n[complete]\n"
+printf "\n${BOLD}[complete]${ENDC}\n\n"
diff --git a/software/hbkcd/setup.py b/software/hbkcd/setup.py
index d9da1ac..aaff392 100755
--- a/software/hbkcd/setup.py
+++ b/software/hbkcd/setup.py
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
 
 setup(
     name = 'hbkcd',
-    version = '0.1.3',
+    version = '0.2.0',
     description = 'HandBrake Control Daemon',
     packages = find_packages(),
     python_requires = '>=3.6.0',
