Skip to content

Instantly share code, notes, and snippets.

@gtfunes
Created May 14, 2019 13:59
Show Gist options
  • Save gtfunes/a83b0ad8925585ec149af9c964c9ae38 to your computer and use it in GitHub Desktop.
Save gtfunes/a83b0ad8925585ec149af9c964c9ae38 to your computer and use it in GitHub Desktop.
A bash script for low-end machines (mostly RPis) that sometimes crash when updating too many packages at the same time
#!/bin/bash
# - Runs apt-get upgrade for each individual package to avoid killing low-end machines -
DATA=$(apt-get upgrade -s -y -q | grep "Inst " | cut -d ' ' -f 2)
PACKAGES=(${DATA// / })
Z=0
for package in "${PACKAGES[@]}";
do
echo ""
echo ""
echo "apt-get install -y -q $package"
bash -c "nice apt-get install -y -q $package"
bash -c "nice apt-get clean -y -q"
Z=$((Z+1))
# update only first 50 packages, just to be sure that we won't kill our machine by running this script
if [[ $Z -eq 50 ]];
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment