Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # Cleanup temporary files on a Linux Mint 15 Olivia installation.
  4. #
  5. # This script will happily wipe all root/user temporary files, old kernels,
  6. # browser caches and cpan/cpanm build directories. Review before running
  7. # blindly.
  8. #
  9. # Though, so far, there are no Linux Mint 15 Olivia specific cleanups here,
  10. # this script ensures, that we're really running under this distribution. Feel
  11. # free to disable this check.
  12.  
  13. indent() {
  14. sed -u 's/^/ /'
  15. }
  16.  
  17. sep() {
  18. echo "-----> $@"
  19. }
  20.  
  21. OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
  22. CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
  23. LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
  24. METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
  25. OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
  26.  
  27. YELLOW="\033[1;33m"
  28. RED="\033[0;31m"
  29. ENDCOLOR="\033[0m"
  30.  
  31. # Ensure, we're running under Linux Mint 15 Olivia.
  32. if ! $(lsb_release -as 2>/dev/null | grep -q 'Linux Mint 15 Olivia'); then
  33. echo "ERROR: This script is intended to run on Linux Mint 15 Olivia." 1>&2
  34. exit 1
  35. fi
  36.  
  37. # Root privileges required.
  38. if [ `id -u` != "0" ]; then
  39. echo "ERROR: You must have root privileges in order to run this script." 1>&2
  40. exit 1
  41. fi
  42.  
  43. sep "Cleaning apt cache"
  44. apt-get clean 2>&1 | indent
  45.  
  46. sep "Purging configuration files for removed packages"
  47. apt-get remove --purge $OLDCONF 2>&1 | indent
  48.  
  49. sep "Purging old kernels"
  50. apt-get remove --purge $OLDKERNELS 2>&1 | indent
  51.  
  52. sep "Emptying trashes"
  53. for d in /home/* /root; do
  54. rm -rf $d/.local/share/Trash/*
  55. done &>/dev/null
  56.  
  57. sep "Emptying thumbnail caches"
  58. for d in /home/* /root; do
  59. rm -rf $d/.cache/thumbnails/*
  60. done &>/dev/null
  61.  
  62. sep "Emptying cpan/cpanm build and source directories"
  63. for d in /home/* /root; do
  64. rm -rf $d/.cpan/sources/*
  65. rm -rf $d/.cpan/build/*
  66. rm -rf $d/.cpanm/work/*
  67. rm -rf $d/.cpanm/build.log
  68. rm -rf $d/.cpan/CPAN/MyConfig.pm~
  69. done &>/dev/null
  70.  
  71. sep "Emptying browser cache directories"
  72. for d in /home/* /root; do
  73. rm -rf $d/.cache/mozilla/firefox/*
  74. rm -rf $d/.cache/google-chrome/*
  75. done &>/dev/null
  76.  
  77. sep "All done"
  78. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement