From a15294f52fc01f32e55378ef8f3ef8973700e743 Mon Sep 17 00:00:00 2001 From: Valentin Vidic Date: Mon, 13 Feb 2012 13:10:42 +0100 Subject: [PATCH] Kernel and init script cleanup. --- src/actions/main.queue | 2 + src/functions.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++-- src/messages.sh | 21 +++++++++++ 3 files changed, 116 insertions(+), 4 deletions(-) diff --git a/src/actions/main.queue b/src/actions/main.queue index b4bd0e3..313bcf0 100644 --- a/src/actions/main.queue +++ b/src/actions/main.queue @@ -46,7 +46,9 @@ true remove_orphaned # ocisti stare libove nakon sto su cn paketi nadogradje # i ostatak true add_group_proc # za oidentd true enable_monit +true clean_old_kernels pkg kernel-2.6-cn dpkg-reconfigure kernel-2.6-cn +true clean_initd_packages true dpkg-reconfigure sysv-rc # ovo bi trebalo biti predzadnje na popisu # - izvrsi sve uvjetne post_upgrade akcije diff --git a/src/functions.sh b/src/functions.sh index 6beb99b..0fee7ca 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -1062,16 +1062,29 @@ check_archives_space() { fi } -check_kernel_space() { - local available_disk_space kernel_size linux_images metapkg pkg ret - available_disk_space=$(free_space /) +# calculate the list of linux-image packages from kernel-2.6-cn dependencies +get_cn_kernels() { + local cn_kernels linux_images metapkg pkg + + cn_kernels= linux_images=$(apt-cache show kernel-2.6-cn | grep ^Depends: \ | grep -o 'linux-image[^, ]*') for metapkg in $linux_images; do pkg=$(apt-cache show $metapkg | grep ^Depends: \ | grep -o 'linux-image[^, ]*' | head -1) - [ "$pkg" ] || continue + [ "$pkg" ] && cn_kernels="$cn_kernels $pkg" + done + + echo $cn_kernels +} +# check if there is enough space on / for the new kernel package +check_kernel_space() { + local available_disk_space kernel_size linux_images pkg ret + available_disk_space=$(free_space /) + + linux_images=$( get_cn_kernels ) + for pkg in $linux_images; do kernel_size=$(installed_size $pkg) ret=$? [ $ret -eq 0 ] && break @@ -1100,6 +1113,82 @@ check_kernel_space() { fi } +# free some space on / partition by cleaning old unused kernels +clean_old_kernels() { + local installed keep pkg keep remove delete name dialog_list selection + + # find all installed kernels + installed=$( + dpkg -l | egrep '^ii linux-image-[0-9]+[.][0-9]+[.][0-9]+-' \ + | awk '{print $2}' + ) + log "Found kernel packages: $installed" + + # leave current and new kernels + keep="linux-image-$(uname -r) $(get_cn_kernels)" + log "Keep kernel packages: $keep" + + # check what to remove + remove= + for pkg in $installed; do + delete=yes + for name in $keep; do + [ "$pkg" = "$name" ] && delete= + done + if [ "$delete" = yes ]; then + remove="$remove $pkg" + fi + done + log "Obsolete kernel packages: $remove" + + if [ "$remove" ]; then + for pkg in $remove; do + dialog_list="$dialog_list $pkg '' off" + done + + # user selects the packages to delete + selection=$( mktemp /var/lib/carnet-upgrade/selection.XXXXXX ) + eval LC_MESSAGES=hr_HR dialog --nocancel --backtitle \""$title"\" \ + --checklist \""$msg_remove_kernels"\" 20 75 6 $dialog_list 2>$selection + + selected=$( tr -d \" < $selection ) + rm -f $selection + + if [ "$selected" ]; then + log "Removing kernel packages: $selected" + pkgrm $selected + fi + fi +} + +# prevent sysv-rc migration problems +clean_initd_packages() { + local list removed pkg dialog_list selection selected + + list=$( dpkg -S /etc/init.d/\* | grep -v ^diversion | cut -d: -f1 | sort -u ) + removed=$( dpkg -l $list | sed -n 's/^r.[[:space:]]\+\([^[:space:]]\+\).*/\1/p' ) + log "Found removed packages: $removed" + + if [ "$removed" ]; then + for pkg in $removed; do + dialog_list="$dialog_list $pkg '' off" + done + + # user selects the packages to delete + selection=$( mktemp /var/lib/carnet-upgrade/selection.XXXXXX ) + eval LC_MESSAGES=hr_HR dialog --nocancel --backtitle \""$title"\" \ + --checklist \""$msg_remove_initd"\" 20 75 6 $dialog_list 2>$selection + + selected=$( tr -d \" < $selection ) + rm -f $selection + + if [ "$selected" ]; then + log "Purging packages: $selected" + dpkg -P $selected + fi + fi +} + free_space() { df --portability --block-size=1M "$1" | tail -1 | awk '{print $4}' } diff --git a/src/messages.sh b/src/messages.sh index 8e4bc8c..23ea728 100644 --- a/src/messages.sh +++ b/src/messages.sh @@ -45,6 +45,27 @@ neki od navedenih servisa ukljucite oznaku ispred imena odgovarajuceg paketa. Odaberite servise koje zelite UKLONITI: " +msg_remove_kernels="Da bi se izbjeglo zapunjenje / particije preporuca se brisanje starih \ +kernela. U ovom koraku nudi se mogucnost uklanjanja nekoristenih \ +kernel paketa sa vaseg posluzitelja. Ukoliko zelite ukloniti neki od \ +trenutno instaliranih kernela ukljucite oznaku ispred imena odgovarajuceg \ +paketa. + +Odaberite pakete koje zelite UKLONITI: +" + +msg_remove_initd="Nova inacica Debiana donosi mogucnost paralelnog pokretanja servisa \ +kod pokretanja posluzitelja. Da bi se proveo prijelaz na sustav paralelnog \ +pokretanja potrebno je obrisati nekoristene init skripte. Obicno \ +se radi o skriptama koje su ostale nakon nepotpunog brisanja paketa. \ +U ovom koraku nudi se mogucnost brisanja konfiguracija i init skripti \ +paketa koji su djelomicno obrisani. Ukoliko zelite ukloniti datoteke \ +preostale nakon brisanja paketa ukljucite oznaku ispred imena odgovarajuceg \ +paketa. + +Odaberite pakete cije konfiguracije i init skripte zelite UKLONITI: +" + msg_comment_force_overwrite="U vasem /etc/dpkg/dpkg.cfg je pronadjena opcija\ force-overwrite koja nije preporucljiva za uobicajen rad. Ukoliko\ zelite, odkomentirajte je nakon zavrsetka rada skripte." -- 1.7.10.4