Debian / Ubuntu … keep it updated and clean

Just for me (and U if you want) … a script that permits to do a full update/upgrade of Debian / Ubuntu packages, and remove the old ones.

#!/bin/bash

#VARIABLES
OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
YELLOW="\033[1;33m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"

# SCRIPT
if [ $USER != root ]; then
  echo -e $RED"Error: must be root"
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  exit 0
fi

echo -e $YELLOW"Update, Upgrade and Check ..."$ENDCOLOR
  apt-get update
  apt-get -y upgrade
  apt-get -y dist-upgrade
  apt-get -y check

echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR
  apt-get clean
  apt-get -y autoclean
  apt-get -y autoremove

echo -e $YELLOW"Removing old config files..."$ENDCOLOR
  apt-get purge $OLDCONF

echo -e $YELLOW"Removing old kernels..."$ENDCOLOR
  apt-get purge $OLDKERNELS

echo -e $YELLOW"Emptying every trashes..."$ENDCOLOR
  rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
  rm -rf /root/.local/share/Trash/*/** &> /dev/null

echo -e $YELLOW"Script Finished!"$ENDCOLOR

For a full clean-up, you can use Ubuntu-Tweak to sanitize your distro.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


*