Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: cache apt file cleaner  (Read 2299 times)

Offline ralul

  • User
  • Posts: 1.809
cache apt file cleaner
« on: 2011/01/07, 17:03:10 »
Alte Versionen werden gelöscht ohne Vorwarnung!

zBeispiel in der cron.monthly:
cleandistfiles /var/cache/apt/archives

Wenn man die Säuberung von deb-Dateien via aptitude oder apt-get dann unterlässt, hat man eine gute Chance einen alten schon deinstallierten Kernel wiederzufinden:
Code: [Select]
#!/bin/bash
# CleanDistfiles - Version2 - Copyleft GPL2 - Ralph Ulrich
# Warning:   Löscht alte Versionen ohne Bestätigung!
#            Die gelöschten Namen werden angezeigt
# Beispiel:  cleandistfiles /var/cache/apt/archives

function versionInt {
  a="$1"
  a="${a/amd64/ }" # get rid of non version numbers - Ubuntu
  a="${a/x86/ }"
  a="${a/i386/ }"
  a="${a/i686/ }"
  a="${a%bz2}"
  a="${a//[[:punct:]]/ }" # remove points
  a="${a/[Rr][Cc]/ -10 }" # reduce value for release candidates
  a="${a/[Bb]eta/ -20 }"
  a="${a/alpha/ -30 }"
  a="${a//[[:alpha:]]/ }" # remove letters
  echo $a
}

function nameStr {
  a="$1"
  a="${a//[[:punct:]]/ }" # remove points
  a="${a/r[0-9]/ }" # remove Gentoo -r1, better more
  a="${a//[Rr][Cc]/ }" # remove version letters
  a="${a/[Bb]eta/ }"
  a="${a/alpha/ }"
  a="${a//[[:digit:]]/ }" # remove all digits
  a="${a//[[:blank:]]/ }" # remove additional blanks
  echo $a
}

[ -z "$1" ] && echo -e "$0 <Dir>\nGive a directory name to remove older source files there!" && exit 1
cd "$1" || exit 2
h='hhhh'
r=0
s=0
for f in $( find . -maxdepth 1 -type f -iname '*.tbz2' -o -iname '*.deb' -o -iname '*.rpm' -o -iname '*.srpm' | sort ); do
  s=$(( $s + 1 ))
  [ -L "$f" ] && continue
  if [ "$(nameStr $f)" = "$(nameStr $h)" ] ; then   # some have names after version
    v=( $(versionInt $f) )
    w=( $(versionInt $h) )
    [ ${#v[@]} -gt ${#w[@]} ] && m=${#v[@]} || m=${#w[@]}
    for (( i=0 ; $i < $m ; i+=1 )) ; do
        [ -z "${v[$i]}" ] && v[$i]=0
        [ -z "${w[$i]}" ] && w[$i]=0
        [ ${v[$i]} -lt ${w[$i]} ] && rm "$f" && r=$(( $r + 1 )) && echo -e " -remove $f \n +++keep $h" && continue 2
        [ ${w[$i]} -lt ${v[$i]} ] && rm "$h" && r=$(( $r + 1 )) && echo -e " -remove $h \n +++keep $f" && h="$f" && continue 2
    done
    echo " +++keep ambigous_WARN  $h"
    echo " +++keep ambigous_WARN  $f"
  fi
  h="$f"
done
echo -e "$s\tfiles found"
echo -e "$r\tfiles removed by $(basename $0)"

@Agaida, extra für Dich :)
Ich hatte mir das eigentlich für Gentoo gebastelt...
experiencing siduction runs better than my gentoo makes me know I know nothing