1 # Ivan 'ico' Rako <irako@srce.hr>
2 # Zoran 'jelly' Dzelajlija <jelly@srce.hr>
5 LC_MESSAGES=hr_HR dialog --backtitle "$title" --msgbox "$*" 18 75
9 LC_MESSAGES=hr_HR dialog --backtitle "$title" --yesno "$msg_first_warning" 18 75
11 log "Upgrade canceled."
18 dpkg -l "$1" 2> /dev/null | egrep -q "^.i" || return 1
19 [ -z "$2" ] && return 0
20 version=$(dpkg -s "$1" | awk '/^Version:/ {print $2}')
21 dpkg --compare-versions "$version" "$2" "$3" 2>&1 > /dev/null
26 logfile=${logfile:=/var/log/carnet-upgrade.log}
31 echo "$(date +'%Y-%m-%d %H:%M:%S') $*" >> $logfile
38 # find first free uid/gid in range
39 # find_id passwd 100 999
41 local i db first last ids
45 ids=$(getent $db | awk -F: "\$3 >= $first && \$3 <= $last {print \$3}")
46 for i in $(seq $first $last)
48 if ! echo $ids | grep -q $i; then
58 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
67 [ -e "$i" ] || continue
68 egrep -q "$s" "$i" || continue
69 [ -h "$i" ] && i=$(readlink -f "$i")
70 sed "$sedcmd" "$i" > "$i.dpkg-tmp"
71 chown --reference "$i" "$i.dpkg-tmp"
72 chmod --reference "$i" "$i.dpkg-tmp"
76 if [ "$ret" -eq 0 ]; then
77 log "Done \"$sedcmd\" to $*"
83 # Update uid for user from reserved system range (0-99) to dynamic system
84 # range (100-999). Optionally update ownerships of given directories.
85 # $0 user [directory ...]
87 check_and_update_ugid() {
88 local user newgid newuid
90 if [ "$(getent passwd $user | awk -F: '$3 >= 100 {print "ok"; exit 0}')" ]; then
94 newgid=$(find_id group 100 999)
95 newuid=$(find_id passwd 100 999)
96 # other directories/files
97 chown -R $newuid:$newgid $*
98 groupmod -g $newgid $user
99 usermod -u $newuid -g $newgid $user
100 log "Fixed $user user uid/gid."
104 [ -n "$*" ] || return 0
105 log "Installing $* ..."
106 apt-get -y$s install $* || {
109 apt-get -y$s install $*
114 [ -n "$*" ] || return 0
116 apt-get -y$s --purge remove $* || {
119 apt-get -y$s --purge remove $*
124 [ -n "$*" ] || return 0
125 log "Removing $* ..."
126 apt-get -y$s remove $* || {
129 apt-get -y$s remove $*
135 log "Running apt-get update ..."
136 apt-get -y$s update || {
144 log "Running apt-get download ..."
145 apt-get -dy$s dist-upgrade
149 log "Running dist-upgrade ..."
150 apt-get -y$s dist-upgrade || {
152 apt-get -y$s dist-upgrade
157 LC_MESSAGES=hr_HR dialog --backtitle "$title" --yesno "$msg_remove_x" 18 75
158 if [ $? -eq 0 ]; then
159 log "Removing X Window System"
162 log "Skipping X Window System removal"
167 local to_remove add_this i j n text to_show cmd tmpfile installed
168 local update_selections pkgs_to_deselect pkgs_to_remove oldifs pkglist
169 text="$msg_remove_bloat"
171 [ "$DEBUG" ] && set -x
173 pkglist=$(mktemp /var/lib/carnet-upgrade/pkglist.XXXXXX)
174 COLUMNS=200 dpkg -l | awk '$1 ~ /^.i/ { print $2 }' > $pkglist
175 for i in $(echo "$bloats" | sed 's/ */ /g'| awk -F' ' '{print $2}')
177 if grep -q "^$i$" $pkglist; then
178 installed="$installed $i"
179 add_this="$(echo "$bloats" | egrep " .*\b${i}\b" | sed 's/ */ /g'| awk -F' ' '{print $1}')"
180 if ! echo "$to_show" | grep -q "$add_this"; then
181 to_show="$to_show \"$add_this\" \"\" on"
186 [ "$DEBUG" ] || rm -f $pkglist
187 [ -z "$to_show" ] && return 0
189 tmpfile=$(mktemp /var/lib/carnet-upgrade/dialog-tmp.XXXXXX)
190 cmd="LC_MESSAGES=hr_HR dialog --nocancel --backtitle \""$title"\" --checklist \""$text"\" 20 75 $n $to_show"
191 [ "$DEBUG" ] && set +x
192 eval $cmd 2> $tmpfile
193 [ "$DEBUG" ] && set -x
194 to_remove="$(cat $tmpfile | sed 's/\"\ \"/ /g; s/\"\ *//g; s/\\//g')"
195 [ "$DEBUG" ] || rm -f $tmpfile
196 [ "$DEBUG" ] && echo "DEBUG: to_remove=$to_remove" 1>&2
199 for i in $(echo "$to_remove")
202 for j in $(echo "$bloats" | grep "^$i" | sed 's/ */ /g'| awk -F' ' '{print $2}')
204 # hopefully this will tell apt not to reinstall them at upgrade time
205 update_selections="${update_selections}
207 pkgs_to_deselect="$pkgs_to_deselect $j"
208 # only remove those that really are installed
209 if echo "$installed" | grep -q "$j"; then
210 pkgs_to_remove="$pkgs_to_remove $j"
214 [ "$DEBUG" ] && echo "DEBUG: pkgs_to_remove=$pkgs_to_remove" 1>&2
215 # Finally, remove those
216 if [ -n "$update_selections" ]; then
217 echo "$update_selections" | dpkg --set-selections
218 log "Deselected:${pkgs_to_deselect}"
220 eval pkgrm $pkgs_to_remove
224 local installed pkg cn_pkgs dialog_list selection cn_del to_del del_pkgs
226 # get installed packages
227 installed=$(mktemp /var/lib/carnet-upgrade/pkglist.XXXXXX)
228 COLUMNS=200 dpkg -l | awk '$1 ~ /^.i/ { print $2 }' >$installed
230 # detect installed CN packagees
231 for pkg in $(echo "$cn_bloats" | cut -d' ' -f1); do
232 if grep -qx $pkg $installed; then
233 cn_pkgs="$cn_pkgs $pkg"
234 dialog_list="$dialog_list $pkg '' off"
239 # report status or finish if no CN packages found
240 if [ "$cn_pkgs" ]; then
241 log "Found CN packages:$cn_pkgs"
243 log "No CN packages found."
247 # user selects the packages to delete
248 selection=$(mktemp /var/lib/carnet-upgrade/selection.XXXXXX)
249 eval LC_MESSAGES=hr_HR dialog --nocancel --backtitle \""$title"\" \
250 --checklist \""$msg_remove_cn_bloat"\" 20 75 6 $dialog_list 2>$selection
252 # expand the package list to include the services
253 for pkg in $(cat $selection); do
256 cn_del="$cn_del $pkg"
257 to_del=$(echo "$cn_bloats" | grep ^$pkg)
258 del_pkgs="$del_pkgs $to_del"
262 # report selection or finish if no service selected
263 if [ "$cn_del" ]; then
264 log "Removing CN services:$cn_del"
266 log "No CN services selected for removal."
270 # delete the cn packages and relevant services
275 touch "$post_upgrade_queuetab"
276 if ! grep -q "true $*" "$post_upgrade_queuetab"; then
277 echo "true $*" >> "$post_upgrade_queuetab"
282 if [ -f "$post_upgrade_queuetab" ]; then
283 run_actions post_upgrade "$post_upgrade_queuetab"
284 mv "$post_upgrade_queuetab" "${post_upgrade_queuetab}.done.$(date '+%Y-%m-%d.%H:%M:%S')"
291 local line lineno lineno2 f n name action checkmsg check
292 [ "$DEBUG" ] && set -vx
295 [ -f "$f" ] || return 2 # no such file
296 n=$(wc -l "$f" | awk '{print $1}')
297 [ "$n" -lt 1 ] && return 1 # no lines to process
298 log "run_actions ($name) started, processing $n lines from \"$f\"."
302 while [ "$lineno" -lt "$n" ]
304 lineno=$(($lineno+1))
306 line=$(head -$lineno "$f" | tail -1)
307 if echo $line | grep -q '^#'; then # comment
310 while echo "$line" | egrep -q '\\$' # continuation
312 lineno2=$(($lineno2+1))
313 line=$(echo -n "$line"| sed 's/\\$//'; head -$lineno2 "$f" | tail -1)
315 check=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $1}')
316 action=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $2}')
318 [ "$check" != "true" ] && checkmsg="if '$check'"
320 log "$(printf 'action %02d' $lineno) starting: '${action}' $checkmsg "
321 if ! eval $action; then
322 log "$(printf 'action %02d' $lineno) failed: '${action}' $checkmsg "
323 display_action_failure "$action"
326 log "$(printf 'action %02d' $lineno) finished: '${action}' $checkmsg"
329 log "$(printf 'action %02d' $lineno) skipping: '${action}' $checkmsg"
331 [ "$lineno2" -gt "$lineno" ] && lineno=$lineno2
333 log "run_actions ($1) finished"
337 # report action failure
338 display_action_failure () {
342 Doslo je do greske prilikom izvrsavanja akcije '$action'. Detalje problema moguce je vidjeti u log datotekama:
344 /var/log/carnet-upgrade.log
345 /var/log/carnet-upgrade.typescript
347 Da bi dovrsili zapocete operacije nad paketima pokrenite:
349 # dpkg --configure -a
352 Nakon toga ponovno pozovite carnet-upgrade skriptu."
355 # funkcija vraca popis paketa koje treba upgradeati
357 local IFSOLD name version package
359 for package in `echo "$needed_versions" | awk '{print $1}'| grep -v ^$`; do
362 read name version <<-EOPTS
363 $(echo "$needed_versions" | sed 's/ */ /g' | grep ^$package)
366 if pkg "$name" lt "$version"; then
372 # funkcija za ispis paketa koje treba upgradeati
375 upgrade=${1:-"`what_upgrade`"}
377 if [ "$upgrade" ]; then
379 Prije prelaska na Debian Lenny potrebno je napraviti nadogradnju ovih paketa:
384 # apt-get dist-upgrade
387 # apt-get install${upgrade}
389 Nakon toga ponovno pozovite ovu skriptu."
390 log "carnet-upgrade aborted, upgrade of$upgrade needed."
395 # update sarge urls in sources list
396 fix_sarge_sources () {
397 local apt_sources='/etc/apt/sources.list'
398 local fixed_sources=$(mktemp /var/lib/carnet-upgrade/sources.list.XXXXXX)
400 # sarge (oldstable) was archived recently -> sources.list needs update
401 awk -v archive='http://archive.debian.org/debian' \
402 -v security='http://archive.debian.org/debian-security' \
403 '$3 == "sarge" && $2 ~ /[/]debian$/ { $2 = archive }
404 $3 == "sarge/updates" && $2 ~ /security\.debian\.org$/ { $2 = security }
405 { print }' $apt_sources > $fixed_sources
407 # did anything get updated
408 if ! cmp $apt_sources $fixed_sources >/dev/null; then
409 log "sources.list fixed to use archive.debian.org"
411 # backup current version
412 if [ ! -f "$apt_sources.$backup_ext.sarge" ]; then
413 cp -av $apt_sources "$apt_sources.$backup_ext.sarge"
416 # install fixed version
417 cp -av $fixed_sources $apt_sources
419 # update the database
427 # try to check if we are using the latest version of carnet-upgrade script
428 check_my_version () {
429 local packages latest_version
431 packages=$(mktemp /var/lib/carnet-upgrade/Packages.XXXXXX)
432 if wget -q -O$packages $packages_uri; then
433 latest_version=$(sed -ne \
434 '/Package: carnet-upgrade/,/Description:/{ /Version: /s///p }' \
438 if [ "$latest_version" ]; then
439 log "Running carnet-upgrade version is $version"
440 log "Latest carnet-upgrade version is $latest_version"
441 if dpkg --compare-versions "$version" lt "$latest_version"; then
442 check_upgrade " carnet-upgrade"
443 else log "Already using the latest carnet-upgrade version."; fi
444 else log "Failed to get latest version, skipping check."; fi
445 else log "Failed to download Packages file, skipping check."; fi
450 # if php is installed make sure it's version 5
451 check_php_version () {
453 if pkg php4-cn && ! pkg php5-cn; then
455 Prije prelaska na Debian Lenny potrebno je napraviti nadogradnju sa PHP 4 na PHP 5.
459 # apt-get install php5-cn
461 Nakon sto provjerite da sve web aplikacije rade ispravno, ponovno pozovite ovu skriptu."
462 log "carnet-upgrade aborted, upgrade to php5-cn needed."
467 # if grsec is installed make sure it is fresh
468 check_grsec_kernel () {
471 log "Kernel version: $ver"
472 if [ "$ver" = "${ver%-grsec}" ]; then
477 if [ "$ver" = "${ver#2.6.2[4-9]}" ]; then
480 Prije prelaska na Debian Lenny potrebno je napraviti nadogradnju na najnoviji kernel.
484 # apt-get install kernel-2.6-cn
487 Nakon toga ponovno pozovite ovu skriptu."
488 log "carnet-upgrade aborted, kernel upgrade needed."
494 reboot_required || return 0
496 LC_MESSAGES=hr_HR dialog --backtitle "$title" --yesno "$reboot_warning" 18 +75
497 if [ $? -eq 0 ]; then
498 log "Reboot before continuing."
501 log "Proceed without reboot."
505 # check if the latest kernel is booted
507 local default_kernel kernel_package running_release running_version
509 # try to get default kernel from lilo
510 if type lilo >/dev/null 2>&1; then
511 default_kernel=$( lilo -t -v 2>/dev/null \
513 | sed -n -e '/^Boot image: / { s///p; q; }' )
516 # fallback to grub if lilo not installed
517 if [ -z "$default_kernel" -a -r "/boot/grub/menu.lst" ]; then
518 default_kernel=$( awk '
519 $1 == "default" { default = $2;
520 if (default !~ /^[0-9]+$/) { exit } }
521 $1 == "title" { title+=1 }
522 $1 == "kernel" && title==default+1 { print $2; exit }' \
523 /boot/grub/menu.lst 2>/dev/null )
526 if [ -z "$default_kernel" ]; then
527 log "Could not find default kernel"
531 log "Default kernel image: $default_kernel"
533 if [ ! -e "$default_kernel" ]; then
534 log "Default kernel image doesn't exist!?"
538 kernel_package=$( dpkg -S $default_kernel | cut -d: -f 1 )
540 if [ -z "$kernel_package" ]; then
541 log "Default kernel not installed from a package"
545 log "Default kernel package: $kernel_package"
547 running_release=$( uname -r )
548 running_version=$( uname -v )
549 log "Running kernel: $running_release $running_version"
551 if grep -q "$running_release .* $running_version" $default_kernel; then
552 log "Latest kernel version is running."
555 log "Reboot to latest version required."
561 local i to_install packages
564 packages="$packages_first"
567 packages="$packages_second"
573 for i in $(echo $packages)
575 pkg $i && to_install="$to_install $i"
578 if [ -n "$to_install" ];then
579 eval pkgadd $to_install
585 # funkcija utrpa ispravan sources.list
586 create_sources_list () {
588 sl=/etc/apt/sources.list
589 sl_new=/usr/share/carnet-upgrade/files/etc/apt/sources.list
591 # check if already installed
592 if ! cmp $sl $sl_new >/dev/null; then
595 if [ -f $sl -a ! -f $sl.$backup_ext ]; then
596 cp -av $sl $sl.$backup_ext
599 # install new version
601 notice "Novi sadrzaj datoteke /etc/apt/sources.list:
603 `cat /etc/apt/sources.list`"
608 # funkcija koja brise grupu proc
609 remove_group_proc () {
610 if getent group proc > /dev/null; then
611 groupdel proc || true
612 log "groupdel proc (temporarily)"
613 post_upgrade add_group_proc
618 if ! getent group proc > /dev/null; then
619 # grsec uses gid 99 for /proc files
621 log "groupadd -g 99 proc"
623 # update oidentd so it uses the proc group
624 if [ -x /etc/init.d/oidentd ]; then
625 if gpasswd -a oident proc; then
626 /etc/init.d/oidentd restart
632 # backup ldap database
634 local ldap_backup=/var/backups/slapcat.$backup_ext.gz
635 local old_umask result
637 if [ ! -f $ldap_backup ]; then
638 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius stop || true
640 if [ -x /etc/init.d/slapd -a -d /var/lib/ldap ]; then
641 /etc/init.d/slapd stop || true
643 umask 0077 # protect the backup file
644 slapcat | gzip --best > $ldap_backup
647 /etc/init.d/slapd start || true
649 if [ "$result" -eq 0 ]; then
650 log "$ldap_backup created"
651 notice "Napravljen backup slapd baze u $ldap_backup."
653 log "$ldap_backup was not created"
654 notice "Backup slapd baze u $ldap_backup nije uspio."
659 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius start || true
661 log "slapd backup already at $ldap_backup, skipping."
662 notice "Backup slapd baze u $ldap_backup vec postoji!"
666 # backup etc direktorija
668 local etc_backup=/var/backups/etc.$backup_ext.tar.gz
671 if [ ! -f $etc_backup ]; then
673 umask 0077 # protect the backup file
675 if tar cfz $etc_backup /etc 2> /dev/null; then
676 log "$etc_backup created"
677 notice "Napravljen backup /etc direktorija u $etc_backup."
679 log "$etc_backup was not created"
680 notice "Backup /etc direktorija u $etc_backup nije uspio."
685 log "/etc backup already present in $etc_backup, skipping."
686 notice "Backup /etc direktorija u $etc_backup vec postoji!"
690 # fixaj /etc/default/raid2
691 fix_etc_default_raid2 () {
692 if [ -f /etc/default/raid2 ]; then
693 sed "s/^AUTOSTART.*/AUTOSTART=true/g" /etc/default/raid2 > /etc/default/raid2.$backup_ext.$$
694 chown --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
695 chmod --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
697 if ! cmp -s /etc/default/raid2.$backup_ext.$$ /etc/default/raid2; then
698 log "Fixed /etc/default/raid2 AUTOSTART option."
699 mv -v /etc/default/raid2.$backup_ext.$$ /etc/default/raid2
701 rm -v /etc/default/raid2.$backup_ext.$$
706 # restore original config file (if the new package version is not
709 local file file_backup file_expect file_restore config_changed
710 local cn_package cn_version package version
712 # check if new package version is installed
717 if [ "$cn_package" ]; then
718 if ! pkg $cn_package; then
719 # do nothing if cn package is not installed
724 if [ "$package" ]; then
725 if [ "$version" ]; then
726 # do nothing if package is already upgraded to new version
727 pkg $package lt $version || return 0
729 # do nothing if package is not installed
730 pkg $package || return 0
735 # restore package files
737 file_expect=/usr/share/carnet-upgrade/files/$file.expect
738 file_restore=/usr/share/carnet-upgrade/files/$file.restore
739 file_backup=$file.$backup_ext
741 # is config files are there
742 if ! [ -e $file -a -e $file_expect -a -e $file_restore ]; then
747 if ! cmp $file_expect $file >/dev/null; then
752 if [ ! -e $file_backup ]; then
753 log "Restoring config file $file"
755 # backup local changes
756 cp -av $file $file_backup
759 cp -v $file_restore $file
765 # force reconfiguration at the end if package is not upgraded automatically
766 if [ "$config_changed" -a "$cn_package" ]; then
767 cn_version=$( dpkg -s "$cn_package" | awk '/^Version:/ {print $2}' )
768 post_upgrade "pkg $cn_package gt $cn_version || dpkg-reconfigure $cn_package"
772 # restore modified config to their package defaults
773 # so the upgrade doesn't complain so much
775 local hostname domain template config_new
778 # restore simple configs
779 restore_config kernel-2.6-cn procps 1:3.2.7-11 /etc/sysctl.conf
780 restore_config ntp-cn ntp 1:4.2.4p4+dfsg-8 /etc/ntp.conf
781 restore_config apache2-cn apache2.2-common 2.2.9-10+lenny2 /etc/apache2/ports.conf
782 restore_config postfix-cn sasl2-bin 2.1.22.dfsg1-23 /etc/default/saslauthd
783 restore_config bind9-cn bind9 1:9.5.1.dfsg.P1-1 /etc/bind/named.conf.options
784 restore_config amavisd-cn amavisd-new 1:2.6.1.dfsg-1 /etc/cron.daily/amavisd-new
785 rm -f /etc/cron.daily/amavisd-new.$backup_ext
786 restore_config spamassassin-cn razor 1:2.85-1 /etc/razor/razor-agent.conf
787 restore_config kernel-2.6-cn libpam-modules 1.0.1-5 /etc/security/limits.conf
788 restore_config samba-cn samba-common 2:3.2.5-4lenny2 /etc/samba/smb.conf
789 restore_config '' base-files 5lenny2 /etc/issue /etc/issue.net
791 # check if monitrc is template based
792 if [ -f /etc/monit/monitrc -a ! -f /etc/monit/monitrc.$backup_ext ]; then
793 template=/usr/share/carnet-upgrade/files/etc/monit/monitrc.template
794 config_new=$(mktemp /var/lib/carnet-upgrade/monitrc.XXXXXX)
796 domain=$(hostname --domain)
798 # generate config from template
799 cp $template $config_new
800 check_and_sed "@localhost" \
801 "s/@localhost/@$hostname.$domain/g" $config_new || true
803 # compare with running config
804 if cmp -s /etc/monit/monitrc $config_new; then
805 # restore if running config is generated template
806 log "Restoring config file /etc/monit/monitrc"
807 cp -av /etc/monit/monitrc /etc/monit/monitrc.$backup_ext
808 cp -v /usr/share/carnet-upgrade/files/etc/monit/monitrc.restore \
814 # restore_config login 1:4.0.18.1 /etc/pam.d/login
815 # restore_config mysql-server 5.0.3 /etc/init.d/mysql \
816 # /etc/logrotate.d/mysql-server \
818 # restore_config ntpdate 1:4.2.2 /etc/default/ntpdate
819 # restore_config oidentd 2.0.8 /etc/default/oidentd
820 # restore_config slapd 2.3.30 /etc/default/slapd /etc/init.d/slapd
821 # restore_config squirrelmail 2:1.4.9a /etc/squirrelmail/apache.conf
822 # restore_config vsftpd 2.0.5 /etc/vsftpd.conf
823 # restore_config xinetd 1:2.3.14 /etc/xinetd.conf
825 # # orphaned config file - no owner
826 # if pkg logcheck-database lt 1.2.54; then
827 # rm -vf /etc/logcheck/ignore.d.server/imap
830 # # aide switched to ucf, move old configs aside
831 # if pkg aide lt 0.13.1; then
832 # for file in /etc/aide/aide.conf \
833 # /etc/cron.daily/aide \
836 # if [ ! -e "$file.$backup_ext" ]; then
837 # mv -v "$file" "$file.$backup_ext"
844 # # register cn changes in ucf managed files
845 # for config in /etc/apache/modules.conf \
846 # /etc/clamav/clamd.conf \
847 # /etc/clamav/freshclam.conf
849 # config_backup=$config.$backup_ext
850 # if [ -e $config -a ! -e $config_backup ]; then
851 # log "Saving config file $config"
852 # cp -av $config $config_backup
853 # ucf $config_backup $config
858 # temporary disable listchanges packages to reduce clutter during upgrade
860 local file command=$1
862 for file in /etc/apt/apt.conf.d/20listchanges \
863 /etc/apt/apt.conf.d/20listchanges-cn
867 if [ -f $file ]; then
868 dpkg-divert --local --rename --divert $file.$backup_ext \
874 if [ -f $file.$backup_ext ]; then
875 dpkg-divert --remove $file || true
882 # make a silent installation of carnet and srce keyrings
883 install_keyrings () {
884 pkgadd carnet-keyring srce-keyring debian-archive-keyring
885 pkgadd dpkg apt debconf python-apt
887 dpkg-reconfigure carnet-keyring srce-keyring debian-archive-keyring
891 # remove skey (not supported anymore)
893 pkgrm skey-cn libpam-skey
895 if getent group skey > /dev/null; then
896 groupdel skey || true
901 # remove unsupported php version
903 # leave the configuration just in case
904 pkgrm_only php4-common
907 # check if package is orphaned (nothing depends on it)
912 deps=$(apt-get remove -s $package | grep ^Remv | wc -l)
913 if [ "$deps" -eq 1 ]; then
920 # remove old and unused libraries
924 for package in $orphaned_packages; do
925 if is_orphaned $package; then
931 # monit it causing problems for postinst scripts
932 # restarting daemons so try to disable it
934 if pkg monit-cn; then
935 pkgrm monit-cn # disables monit in prerm
938 # if configured manually
940 # remove the binary but leave the config
941 apt-get remove --yes monit
943 pkill -9 monit || true
947 # make a silent upgrade to new libc6
949 DEBIAN_FRONTEND=noninteractive pkgadd libc6 tzdata
952 # upgrade apache2 to etch
954 local package packages
957 libapache2-mod-php4 \
966 if pkg $package; then
967 packages="$packages $package"
971 # enable suhosin downgrade to etch version
972 if pkg php4-suhosin; then
973 pkgrm php4-suhosin php-suhosin-cn
976 eval pkgadd $packages
982 # remove init script diversion before upgrade
983 if pkg amavisd-cn lt 3:2.6.1-1; then
984 if [ -L /etc/init.d/amavis -a -f /etc/init.d/amavis.amavisd-new ]; then
985 rm -vf /etc/init.d/amavis
986 dpkg-divert --remove /etc/init.d/amavis
990 # move old config aside
991 for conf in /etc/amavisd.conf /etc/amavis/amavisd.conf; do
992 if [ -e $conf -a ! -e $conf.$backup_ext ]; then
993 mv -v $conf $conf.$backup_ext
997 # install new packages
998 pkgadd amavisd-cn amavisd-new
1001 check_and_sed '^clamd.*5.clamav.log$' \
1002 's/^\(clamd.*\)5.clamav.log$/\14\tsocket/g' \
1003 /etc/init.d/amavisd-cn || true
1005 # check if link got lost
1006 if pkg amavisd-cn && [ ! -L /etc/init.d/amavis ]; then
1007 apt-get install --reinstall --yes amavisd-cn
1010 # start new packages
1011 /etc/init.d/amavis restart
1014 # handle freerdius config files upgrade
1015 upgrade_freeradius () {
1016 local template config_new password realm
1018 pkg freeradius-aai lt 2.1.3-0lenny0 || return 0
1020 # handle static configs
1021 restore_config freeradius-aai freeradius 2.1.3-0lenny0 \
1022 /etc/freeradius/clients.conf \
1023 /etc/freeradius/hints \
1024 /etc/freeradius/ldap.attrmap \
1025 /etc/freeradius/radiusd.conf
1027 # handle template based configs
1028 template=/usr/share/carnet-upgrade/files/etc/freeradius/eap.conf.template
1029 config_new=$(mktemp /var/lib/carnet-upgrade/eap.conf.XXXXXX)
1030 password=$(grep -s '^[[:space:]]*private_key_password[[:space:]]*=' \
1031 /etc/freeradius/eap.conf)
1032 cp $template $config_new
1033 sed -i "s/.*#PASSWORD#.*/$password/" $config_new
1034 if cmp -s $config_new /etc/freeradius/eap.conf >/dev/null; then
1035 log "Restoring config file /etc/freeradius/eap.conf"
1036 cp -v /usr/share/carnet-upgrade/files/etc/freeradius/eap.conf.restore \
1037 /etc/freeradius/eap.conf
1041 template=/usr/share/carnet-upgrade/files/etc/freeradius/proxy.conf.template
1042 config_new=$(mktemp /var/lib/carnet-upgrade/proxy.conf.XXXXXX)
1043 realm=$(sed -n '/^[[:space:]]*suffix[[:space:]]*/ {
1044 s///; s/"//g; s/,dc=/./g; s/dc=//; s/.hr$//; p; q }' /etc/ldap/slapd.conf)
1045 cp $template $config_new
1046 sed -i "s/#REALM#/$realm/" $config_new
1047 if cmp -s $config_new /etc/freeradius/proxy.conf >/dev/null; then
1048 log "Restoring config file /etc/freeradius/proxy.conf"
1049 cp -v /usr/share/carnet-upgrade/files/etc/freeradius/proxy.conf.restore \
1050 /etc/freeradius/proxy.conf
1054 # install the new packages
1055 if ! apt-get -y install freeradius; then
1056 # freeradius upgrade fails here, try to fix it by creating certificates
1057 [ -x /etc/freeradius/certs/bootstrap ] && /etc/freeradius/certs/bootstrap
1060 apt-get -y -f install
1063 # finally try to cleanup this mess
1064 pkgadd freeradius-aai
1067 # prepare for slapd upgrade (caused by freeradius installation)
1068 prepare_openldap () {
1069 pkg openldap-aai lt 2.4 || return 0
1071 # openldap-aai expects org.ldif to exists
1072 local ldif=/var/lib/ldap/org.ldif
1073 local ldif_backup=/var/lib/carnet-upgrade/org.ldif
1074 if [ -f $ldif ]; then
1075 cp -v $ldif $ldif_backup
1079 # fix openldap-aai postinst user handling
1080 upgrade_openldap () {
1081 pkg openldap-aai lt 2.4 || return 0
1083 # slapd postinst fails if move_old_database is false
1084 echo 'slapd slapd/move_old_database boolean true' | debconf-set-selections
1087 # slapd removes org.ldif during switch from ldap -> openldap user
1088 local ldif=/var/lib/ldap/org.ldif
1089 local ldif_backup=/var/lib/carnet-upgrade/org.ldif
1090 if [ -f $ldif_backup -a ! -f $ldif ]; then
1091 cp -v $ldif_backup $ldif
1094 # openldap-aai postinst fails here because of database permissions
1095 apt-get -y install openldap-aai || true
1096 chown -R openldap:openldap /var/lib/ldap
1097 /etc/init.d/slapd restart
1100 # remove ldap user if openldap works
1101 if getent passwd ldap > /dev/null && \
1102 getent passwd openldap > /dev/null && \
1103 pgrep -U openldap slapd > /dev/null
1105 log "userdel ldap (replaced by openldap)"
1106 userdel ldap || true
1110 # fix postgresql deinstallation during upgrade
1111 upgrade_postgresql () {
1112 if check_services show 2>&1 | grep -qw postgresql; then
1113 apt-get install -y postgresql || apt-get -yf install
1118 upgrade_postfix () {
1121 if pkg postgrey; then
1122 pkgrm postgrey # not used by postfix-cn anymore
1127 local name=$1 file=$2 val
1129 if [ -f "$file" ]; then
1130 val=$(sed -n "/^[[:space:]]*$name[[:space:]]*=/s/[[:space:]]*//gp" $file)
1137 # preserve mail location on upgrade
1138 upgrade_dovecot () {
1139 local default_mail_env mail_location
1141 # check if already upgraded
1142 if ! pkg dovecot-common lt 1.0; then
1146 # save old mail location
1147 default_mail_env=$(get_variable default_mail_env /etc/dovecot/dovecot.conf)
1149 # silently upgrade package
1150 restore_config dovecot-cn dovecot-common 1.0 /etc/dovecot/dovecot.conf
1153 # insert old mail location
1154 mail_location=$(get_variable mail_location /etc/dovecot/dovecot.conf)
1155 if [ "$default_mail_env" -a ! "$mail_location" ]; then
1156 check_and_sed '^#mail_location[[:space:]]*=' \
1157 "s|#mail_location[[:space:]]*=.*|mail_location = $default_mail_env|" /etc/dovecot/dovecot.conf || return 0
1159 if [ -x /etc/init.d/dovecot ]; then
1160 if [ -x /usr/sbin/invoke-rc.d ]; then
1161 /usr/sbin/invoke-rc.d dovecot restart
1163 /etc/init.d/dovecot restart
1169 # restore munin configs for silent upgrade
1171 local config backup hostname domain
1173 for pkg_name in munin munin-node; do
1174 pkg $pkg_name lt '1.2.6-10~lenny1' || continue
1176 config=/etc/munin/$pkg_name.conf
1177 backup=$config.$backup_ext
1178 if [ -f $config -a ! -f $backup ]; then
1179 hostname=$(hostname)
1180 domain=$(hostname --domain)
1182 cp -av $config $backup
1183 check_and_sed "$hostname.$domain" \
1184 "s/$hostname.$domain/localhost.localdomain/g" $config
1189 # force localhost -> hostname replacement in config files
1191 dpkg-reconfigure munin-cn
1194 # udev.preinst fails if devfs configs still exist
1198 for config in /etc/udev/rules.d/devfs.rules \
1199 /etc/udev/rules.d/compat-full.rules \
1200 /etc/udev/rules.d/compat.rules
1202 if [ -e $config ]; then
1207 if [ -f /etc/udev/udev.rules -a ! -f /etc/udev/rules.d/udev.rules ]; then
1208 ln -sfv ../udev.rules /etc/udev/rules.d/
1214 # fix /etc/dpkg/dpkg.cfg
1215 comment_force_overwrite () {
1216 if [ -f /etc/dpkg/dpkg.cfg ]; then
1217 if check_and_sed '^force-overwrite' \
1218 's,\(^force-overwrite\),#\1,' \
1219 /etc/dpkg/dpkg.cfg; then
1220 notice "$msg_comment_force_overwrite"
1226 cat > /etc/issue <<EOF
1227 Debian GNU/Linux 5.0 (CARNet Debian 5.0) \\n \\l
1231 cat > /etc/issue.net <<EOF
1232 Debian GNU/Linux 5.0 (CARNet Debian 5.0) %h
1236 check_archives_space() {
1237 local available_disk_space archives_size
1238 available_disk_space=$(free_space /var/cache/apt/archives/)
1239 archives_size=$(download_size dist-upgrade)
1241 if [ $? -ne 0 ]; then
1242 log "Failed to get download size, skipping check."
1246 log "Archives space: ${available_disk_space}MB"
1247 log "Download size: ${archives_size}MB"
1249 if [ $available_disk_space -lt $archives_size ]; then
1250 log "carnet-upgrade aborted: not enough space in /var/cache/apt/archives/ (have ${available_disk_space}MB, need ${archives_size}MB)"
1251 notice "Premalo slobodnog mjesta u /var/cache/apt/archives/ za skidanje paketa (potrebno je barem ${archives_size}MB). Procitajte poglavlje 'Izvanredne situacije' u dokumentaciji."
1256 check_kernel_space() {
1257 local available_disk_space kernel_size
1258 available_disk_space=$(free_space /)
1259 kernel_size=$(installed_size kernel-2.6-cn)
1261 if [ $? -ne 0 ]; then
1262 log "Failed to get installed size, skipping check."
1266 log "Free space in /: ${available_disk_space}MB"
1267 log "Kernel size: ${kernel_size}MB"
1269 if LC_ALL=C apt-get --yes --print-uris install kernel-2.6-cn \
1270 | grep -q '^kernel-2.6-cn is already the newest version.$'
1272 log "Not checking free space in /: kernel-2.6-cn already installed"
1276 if [ $available_disk_space -lt $kernel_size ]; then
1277 log "carnet-upgrade aborted: not enough space in / (have ${available_disk_space}MB, need ${kernel_size}MB)"
1278 notice "Premalo mjesta u / za instalaciju kernela (potrebno je barem ${kernel_size}MB). Procitajte poglavlje 'Izvanredne situacije' u dokumentaciji."
1284 df --portability --block-size=1M "$1" | tail -1 | awk '{print $4}'
1289 size=$(LC_ALL=C apt-get --yes --print-uris "$@" | grep '^Need to get ')
1291 if [ $? -ne 0 ]; then
1292 log "Failed to get download size for 'apt-get $@'."
1296 size=${size#Need to get }
1299 size_to_mb "${size}B"
1305 size=$(apt-cache show $package | grep '^Installed-Size:')
1307 if [ $? -ne 0 ]; then
1308 log "Failed to get installed size for '$package'."
1314 size_to_mb "${size}kB"
1320 if [ -z "$size" ]; then
1324 if [ "${size%kB}" != "$size" ]; then
1325 size=$(round ${size%kB})
1326 size=$(($size/1024+1))
1327 elif [ "${size%MB}" != "$size" ]; then
1328 size=$(round ${size%MB})
1329 elif [ "${size%GB}" != "$size" ]; then
1330 size=$(round ${size%GB})
1331 size=$(($size*1024))
1332 elif [ "${size%[0-9]B}" != "$size" ]; then
1333 size=$(round ${size%B})
1334 size=$(($size/1024/1024+1))
1336 log "unrecognized size unit: $size"
1347 if [ "${num%.*}" != "$num" ]; then