Skip to content

Instantly share code, notes, and snippets.

@Josh5
Last active August 13, 2018 01:12
Show Gist options
  • Save Josh5/f5a3e764b1a6a461cd437c02ab97c66e to your computer and use it in GitHub Desktop.
Save Josh5/f5a3e764b1a6a461cd437c02ab97c66e to your computer and use it in GitHub Desktop.
dpkg-get
#!/bin/bash
#
# @Author: Josh Sunnex
# @Date: 2018-08-13 12:54:13
# @Last Modified by: Josh Sunnex
# @Last Modified time: 2018-08-13 12:54:13
#
NOW="$(date +'%Y-%m-%d_%H.%M.%S')";
DIR="/tmp/dpkg-get/";
CWD="${PWD}";
URL="${1}";
FILE="${URL##*/}-${NOW}.deb";
# Script must be run as root...
if [[ "$EUID" -ne 0 ]]; then
echo "Please run as root";
exit 1;
fi
# Ensure we have curl
if [[ -z $(which curl) ]]; then
echo "Missing dependency 'curl'";
echo "Try running 'apt install curl' first"
exit 1;
fi
# Download
[[ -d ${DIR} ]] || mkdir ${DIR};
cd ${DIR};
curl -SL -o ${DIR}/${FILE} ${URL};
# Install
dpkg -i "${DIR}/${FILE}";
if [[ $? > 0 ]]; then
# If there were issue with the dpkg install, then there were likely missing deps
echo
echo "Errors were detected while installing ${URL}";
echo "Attempting to resolve any missing dependencies...";
echo
sleep 1;
apt-get --fix-broken install;
dpkg -i "${DIR}/${FILE}";
fi
# Cleanup and exit
rm -f ${DIR}/${FILE};
cd ${CWD};
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment