#!/bin/bash

# Make sure they've given us the name of an existing file.
if [[ ! -f "$1" ]]; then
    echo "${0##*/} <deb>"
    exit 0
fi

# Move the file to /tmp, then install it from there. This extra step prevents
# the file from being torn away from us before we're done with it, makes sure
# that we don't try to install the file again on a subsequent reboot (should it
# somehow still be hanging around then), and provides a measurable indication
# that we're processing the file (if anyone cares).
#
# Once we're done with it, delete the file.
#
# Dpkg will exit with error if the file isn't actually a package.
tmpdeb="/tmp/${1##*/}"
mv "$1" "$tmpdeb" && dpkg --install "$tmpdeb"
rm -f "$tmpdeb"
