Created
November 11, 2017 02:19
-
-
Save shvchk/22afb8aa958c5a6eb6b30edcfe4fa83d 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 aptitude -y full-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