Skip to content

Instantly share code, notes, and snippets.

@K-Ko
Last active December 25, 2019 12:01
Show Gist options
  • Save K-Ko/f247facdc73392e3c736a2e09d3136ed to your computer and use it in GitHub Desktop.
Save K-Ko/f247facdc73392e3c736a2e09d3136ed to your computer and use it in GitHub Desktop.
Update debian based systems shell script
#!/bin/bash
###
### sudo wget -qO /usr/local/bin/sysup https://gist.github.com/K-Ko/f247facdc73392e3c736a2e09d3136ed/raw/sysup
### sudo chmod +x /usr/local/bin/sysup
###
e () {
echo "::: ----------------------------------------------------------------------"
echo "::: $@"
}
if [ $(id -u) -ne 0 ]; then
e Become root
sudo $0 $@
exit 0
fi
if [ "$1" == "-u" ]; then
e Self update
wget -qO $0 https://gist.github.com/K-Ko/f247facdc73392e3c736a2e09d3136ed/raw/sysup
e Done
exit 0
fi
e Update package lists
apt update || exit
e Upgrade
apt upgrade || exit
apt dist-upgrade || exit
if [ "$1" ]; then
e Install add. packages
apt install $@
fi
e Clean up ...
e Orphan packages, run until all was removed
[ "$(which deborphan)" ] || apt -y install deborphan >/dev/null 2>&1
while [ "$(deborphan)" ]; do
deborphan | tr '\n' ' ' | xargs apt -y purge
done
e Automatic installed packages
apt -y autoremove
e Clean up packages
apt autoclean
apt clean
e Done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment