Created
November 11, 2017 02:19
-
-
Save shvchk/15cfe2606a3f8605adbc34a5cdaeac5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env sh | |
DEFAULT_DL_LIMIT="32" # KB/s | |
APT_LAST_UPDATE_FILE="$HOME/.apt-last-update" | |
NICE="nice -n 19 ionice -c 3 trickle -s -d ${1:-$DEFAULT_DL_LIMIT}" | |
if [ -e $APT_LAST_UPDATE_FILE ] && [ $(( $(date +%s) - $(date +%s -r $APT_LAST_UPDATE_FILE) )) -le 3600 ] | |
then | |
echo "APT package lists updated less than an hour ago, skipping" | |
else | |
sudo $NICE apt update | |
touch $APT_LAST_UPDATE_FILE | |
fi | |
UPGRADABLE="$(script -q /dev/null -c 'apt list --upgradable')" | |
if [ $(echo -n "$UPGRADABLE" | grep -c '^') -gt "1" ] | |
then | |
echo -e "$UPGRADABLE" | |
sudo $NICE apt-get -y -d dist-upgrade | |
else | |
echo "System is up to date, no upgrades required" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment