1 # Ivan 'ico' Rako <irako@srce.hr>
2 # Zoran 'jelly' Dzelajlija <jelly@srce.hr>
5 dialog --backtitle "$title" --msgbox "$*" 18 75
9 dialog --backtitle "$title" --yesno "$msg_first_warning" 18 75
14 dpkg -l "$1" 2> /dev/null | egrep -q "^.i" || return 1
15 [ -z "$2" ] && return 0
16 version=$(dpkg -s "$1" | awk '/^Version:/ {print $2}')
17 dpkg --compare-versions "$version" "$2" "$3" 2>&1 > /dev/null
21 logfile=${logfile:=/var/log/carnet-upgrade.log}
23 echo "$(date +'%Y-%m-%d %H:%M:%S') $*" >> $logfile
27 # find first free uid/gid in range
28 # find_id passwd 100 999
30 local i db first last ids
34 ids=$(getent $db | awk -F: "\$3 >= $first && \$3 <= $last {print \$3}")
35 for i in $(seq $first $last)
37 if ! echo $ids | grep -q $i; then
47 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
56 [ -e "$i" ] || continue
57 egrep -q "$s" "$i" || continue
58 [ -h "$i" ] && i=$(readlink -f "$i")
59 sed "$sedcmd" "$i" > "$i.dpkg-tmp"
60 chown --reference "$i" "$i.dpkg-tmp"
61 chmod --reference "$i" "$i.dpkg-tmp"
65 if [ "$ret" -eq 0 ]; then
66 log "Done \"$sedcmd\" to $*"
72 # Update uid for user from reserved system range (0-99) to dynamic system
73 # range (100-999). Optionally update ownerships of given directories.
74 # $0 user [directory ...]
76 check_and_update_ugid() {
77 local user newgid newuid
79 if [ "$(getent passwd $user | awk -F: '$3 >= 100 {print "ok"; exit 0}')" ]; then
83 newgid=$(find_id group 100 999)
84 newuid=$(find_id passwd 100 999)
85 # other directories/files
86 chown -R $newuid:$newgid $*
87 groupmod -g $newgid $user
88 usermod -u $newuid -g $newgid $user
89 log "Fixed $user user uid/gid."
93 [ -n "$*" ] || return 0
94 log "Installing $* ..."
95 apt-get -y$s install $* || {
98 apt-get -y$s install $*
103 [ -n "$*" ] || return 0
104 log "Removing $* ..."
105 apt-get -y$s --purge remove $* || {
108 apt-get -y$s --purge remove $*
113 log "Running apt-get update ..."
114 apt-get -y$s update || {
119 apt-get -dy$s dist-upgrade
123 log "Running dist-upgrade ..."
124 apt-get -y$s dist-upgrade || {
126 apt-get -y$s dist-upgrade
131 local to_remove add_this i j n text to_show cmd tmpfile installed
132 local update_selections pkgs_to_deselect pkgs_to_remove oldifs pkglist
133 text="$msg_remove_bloat"
135 [ "$DEBUG" ] && set -x
137 pkglist=$(mktemp /var/lib/carnet-upgrade/pkglist.XXXXXX)
138 COLUMNS=200 dpkg -l | awk '$1 ~ /^.i/ { print $2 }' > $pkglist
139 for i in $(echo "$bloats" | sed 's/ */ /g'| awk -F' ' '{print $2}')
141 if grep -q "^$i$" $pkglist; then
142 installed="$installed $i"
143 add_this="$(echo "$bloats" | egrep " .*\b${i}\b" | sed 's/ */ /g'| awk -F' ' '{print $1}')"
144 if ! echo "$to_show" | grep -q "$add_this"; then
145 to_show="$to_show \"$add_this\" \"\" on"
150 [ "$DEBUG" ] || rm -f $pkglist
151 [ -z "$to_show" ] && return 0
153 tmpfile=$(mktemp /var/lib/carnet-upgrade/dialog-tmp.XXXXXX)
154 cmd="dialog --nocancel --backtitle \""$title"\" --checklist \""$text"\" 20 75 $n $to_show"
155 [ "$DEBUG" ] && set +x
156 eval $cmd 2> $tmpfile
157 [ "$DEBUG" ] && set -x
158 to_remove="$(cat $tmpfile | sed 's/\"\ \"/ /g; s/\"\ *//g; s/\\//g')"
159 [ "$DEBUG" ] || rm -f $tmpfile
160 [ "$DEBUG" ] && echo "DEBUG: to_remove=$to_remove" 1>&2
163 for i in $(echo "$to_remove")
166 for j in $(echo "$bloats" | grep "^$i" | sed 's/ */ /g'| awk -F' ' '{print $2}')
168 # hopefully this will tell apt not to reinstall them at upgrade time
169 update_selections="${update_selections}
171 pkgs_to_deselect="$pkgs_to_deselect $j"
172 # only remove those that really are installed
173 if echo "$installed" | grep -q "$j"; then
174 pkgs_to_remove="$pkgs_to_remove $j"
178 [ "$DEBUG" ] && echo "DEBUG: pkgs_to_remove=$pkgs_to_remove" 1>&2
179 # Finally, remove those
180 if [ -n "$update_selections" ]; then
181 echo "$update_selections" | dpkg --set-selections
182 log "Deselected:${pkgs_to_deselect}"
184 eval pkgrm $pkgs_to_remove
188 touch "$post_upgrade_queuetab"
189 if ! grep -q "true $*" "$post_upgrade_queuetab"; then
190 echo "true $*" >> "$post_upgrade_queuetab"
195 if [ -f "$post_upgrade_queuetab" ]; then
196 run_actions post_upgrade "$post_upgrade_queuetab"
197 mv "$post_upgrade_queuetab" "${post_upgrade_queuetab}.done.$(date '+%Y-%m-%d.%H:%M:%S')"
204 local line lineno lineno2 f n name action checkmsg check
205 [ "$DEBUG" ] && set -vx
208 [ -f "$f" ] || return 2 # no such file
209 n=$(wc -l "$f" | awk '{print $1}')
210 [ "$n" -lt 1 ] && return 1 # no lines to process
211 log "run_actions ($name) started, processing $n lines from \"$f\"."
215 while [ "$lineno" -lt "$n" ]
217 lineno=$(($lineno+1))
219 line=$(head -$lineno "$f" | tail -1)
220 if echo $line | grep -q '^#'; then # comment
223 while echo "$line" | egrep -q '\\$' # continuation
225 lineno2=$(($lineno2+1))
226 line=$(echo -n "$line"| sed 's/\\$//'; head -$lineno2 "$f" | tail -1)
228 check=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $1}')
229 action=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $2}')
231 [ "$check" != "true" ] && checkmsg="if '$check'"
233 log "$(printf 'action %02d' $lineno) starting: '${action}' $checkmsg "
234 if ! eval $action; then
235 log "$(printf 'action %02d' $lineno) failed: '${action}' $checkmsg "
236 display_action_failure "$action"
239 log "$(printf 'action %02d' $lineno) finished: '${action}' $checkmsg"
242 log "$(printf 'action %02d' $lineno) skipping: '${action}' $checkmsg"
244 [ "$lineno2" -gt "$lineno" ] && lineno=$lineno2
246 log "run_actions ($1) finished"
250 # report action failure
251 display_action_failure () {
255 Doslo je do greske prilikom izvrsavanja akcije '$action'. Detalje problema moguce je vidjeti u log datotekama:
257 /var/log/carnet-upgrade.log
258 /var/log/carnet-upgrade.typescript
260 Da bi dovrsili zapocete operacije nad paketima pokrenite:
262 # dpkg --configure -a
265 Nakon toga ponovno pozovite carnet-upgrade skriptu."
268 # funkcija vraca popis paketa koje treba upgradeati
270 local IFSOLD name version package
272 for package in `echo "$needed_versions" | awk '{print $1}'| grep -v ^$`; do
275 read name version <<-EOPTS
276 $(echo "$needed_versions" | sed 's/ */ /g' | grep ^$package)
279 if pkg "$name" lt "$version"; then
285 # funkcija za ispis paketa koje treba upgradeati
288 upgrade="`what_upgrade`"
290 if [ "$upgrade" ]; then
292 Prije prelaska na Debian Etch potrebno je napraviti nadogradnju ovih paketa:
297 # apt-get dist-upgrade
300 # apt-get install${upgrade}
302 Nakon toga ponovno pozovite ovu skriptu."
303 log "carnet-upgrade aborted, upgrade of$upgrade needed."
308 # if apache is installed make sure it's version 2
309 check_apache_version () {
311 if pkg apache-cn && ! pkg apache2-cn; then
313 Prije prelaska na Debian Etch potrebno je napraviti nadogradnju sa Apache 1.3 na Apache 2.0.
317 # apt-get install apache2-cn
319 Nakon toga ponovno pozovite ovu skriptu."
320 log "carnet-upgrade aborted, upgrade to apache2-cn needed."
326 local i to_install packages
329 packages="$packages_first"
332 packages="$packages_second"
338 for i in $(echo $packages)
340 pkg $i && to_install="$to_install $i"
343 if [ -n "$to_install" ];then
344 eval pkgadd $to_install
350 # funkcija utrpa ispravan sources.list
351 create_sources_list () {
353 sl=/etc/apt/sources.list
354 sl_new=/usr/share/carnet-upgrade/files/etc/apt/sources.list
356 # check if already installed
357 if ! cmp $sl $sl_new >/dev/null; then
360 if [ -f $sl -a ! -f $sl.$backup_ext ]; then
361 cp -av $sl $sl.$backup_ext
364 # install new version
366 notice "Novi sadrzaj datoteke /etc/apt/sources.list:
368 `cat /etc/apt/sources.list`"
373 # funkcija koja brise grupu proc
374 remove_group_proc () {
375 if getent group proc > /dev/null; then
376 groupdel proc || true
377 log "groupdel proc (temporarily)"
378 post_upgrade add_group_proc
383 if ! getent group proc > /dev/null; then
384 # grsec uses gid 99 for /proc files
386 log "groupadd -g 99 proc"
388 # update oidentd so it uses the proc group
389 if [ -x /etc/init.d/oidentd ]; then
390 if gpasswd -a oident proc; then
391 /etc/init.d/oidentd restart
397 # backup ldap database
399 local ldap_backup=/var/backups/slapcat.$backup_ext.gz
400 local old_umask result
402 if [ ! -f $ldap_backup ]; then
403 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius stop || true
405 if [ -x /etc/init.d/slapd -a -d /var/lib/ldap ]; then
406 /etc/init.d/slapd stop || true
408 umask 0077 # protect the backup file
409 slapcat | gzip --best > $ldap_backup
412 /etc/init.d/slapd start || true
414 if [ "$result" -eq 0 ]; then
415 log "$ldap_backup created"
416 notice "Napravljen backup slapd baze u $ldap_backup."
418 log "$ldap_backup was not created"
419 notice "Backup slapd baze u $ldap_backup nije uspio."
424 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius start || true
426 log "slapd backup already at $ldap_backup, skipping."
427 notice "Backup slapd baze u $ldap_backup vec postoji!"
431 # backup etc direktorija
433 local etc_backup=/var/backups/etc.$backup_ext.tar.gz
436 if [ ! -f $etc_backup ]; then
438 umask 0077 # protect the backup file
440 if tar cfz $etc_backup /etc 2> /dev/null; then
441 log "$etc_backup created"
442 notice "Napravljen backup /etc direktorija u $etc_backup."
444 log "$etc_backup was not created"
445 notice "Backup /etc direktorija u $etc_backup nije uspio."
450 log "/etc backup already present in $etc_backup, skipping."
451 notice "Backup /etc direktorija u $etc_backup vec postoji!"
455 # fixaj /etc/default/raid2
456 fix_etc_default_raid2 () {
457 if [ -f /etc/default/raid2 ]; then
458 sed "s/^AUTOSTART.*/AUTOSTART=true/g" /etc/default/raid2 > /etc/default/raid2.$backup_ext.$$
459 chown --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
460 chmod --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
462 if ! cmp -s /etc/default/raid2.$backup_ext.$$ /etc/default/raid2; then
463 log "Fixed /etc/default/raid2 AUTOSTART option."
464 mv -v /etc/default/raid2.$backup_ext.$$ /etc/default/raid2
466 rm -v /etc/default/raid2.$backup_ext.$$
471 # restore original config file (if the new package version is not
474 local file file_backup file_orig
477 # create new files safely
481 # restore package files
483 file_orig=/usr/share/carnet-upgrade/files/$file
484 file_backup=$file.$backup_ext
487 if [ ! -e $file ]; then
492 if cmp $file_orig $file >/dev/null; then
497 if [ ! -e $file_backup ]; then
498 log "Restoring config file $file"
500 # backup local changes
501 mv -v $file $file_backup
504 cp -av $file_orig $file
505 chown --reference $file_backup $file
506 chmod --reference $file_backup $file
513 # restore modified config to their package defaults
514 # so the upgrade doesn't complain so much
518 pkg base-files lt 4 && restore_config /etc/issue /etc/issue.net
519 pkg libpam-modules lt 0.79 && restore_config /etc/security/limits.conf
520 pkg login lt 1:4.0.18.1 && restore_config /etc/pam.d/login
521 pkg mysql-server lt 5.0.3 && restore_config /etc/init.d/mysql \
522 /etc/logrotate.d/mysql-server \
524 pkg ntp lt 1:4.2.2 && restore_config /etc/ntp.conf
525 pkg ntpdate lt 1:4.2.2 && restore_config /etc/default/ntpdate
526 pkg oidentd lt 2.0.8 && restore_config /etc/default/oidentd
527 pkg postgrey lt 1.27 && restore_config /etc/default/postgrey \
528 /etc/postgrey/whitelist_clients
529 pkg procps lt 1:3.2.7 && restore_config /etc/sysctl.conf
530 pkg sasl2-bin lt 2.1.22 && restore_config /etc/default/saslauthd
531 pkg slapd lt 2.3.30 && restore_config /etc/default/slapd /etc/init.d/slapd
532 pkg squirrelmail lt 2:1.4.9a && restore_config /etc/squirrelmail/apache.conf
533 pkg vsftpd lt 2.0.5 && restore_config /etc/vsftpd.conf
534 pkg xinetd lt 1:2.3.14 && restore_config /etc/xinetd.conf
536 # orphaned config file - no owner
537 if pkg logcheck-database lt 1.2.54; then
538 rm -vf /etc/logcheck/ignore.d.server/imap
541 # aide switched to ucf, move old configs aside
542 if pkg aide lt 0.13.1; then
543 for file in /etc/aide/aide.conf \
544 /etc/cron.daily/aide \
547 if [ ! -e "$file.$backup_ext" ]; then
548 mv -v "$file" "$file.$backup_ext"
555 # register cn changes in ucf managed files
556 for config in /etc/apache/modules.conf \
557 /etc/clamav/clamd.conf \
558 /etc/clamav/freshclam.conf
560 config_backup=$config.$backup_ext
561 if [ -e $config -a ! -e $config_backup ]; then
562 log "Saving config file $config"
563 cp -av $config $config_backup
564 ucf $config_backup $config
569 # temporary disable listchanges packages to reduce clutter during upgrade
571 local file command=$1
573 for file in /etc/apt/apt.conf.d/20listchanges \
574 /etc/apt/apt.conf.d/20listchanges-cn
578 if [ -f $file ]; then
579 dpkg-divert --local --rename --divert $file.$backup_ext \
585 if [ -f $file.$backup_ext ]; then
586 dpkg-divert --remove $file || true
593 # make a silent installation of carnet and srce keyrings
594 install_keyrings () {
595 pkgadd carnet-keyring srce-keyring
596 pkgadd dpkg apt debconf python-apt
598 dpkg-reconfigure carnet-keyring srce-keyring
602 # remove skey (not supported anymore)
604 pkgrm skey-cn libpam-skey
606 if getent group skey > /dev/null; then
607 groupdel skey || true
612 # monit it causing problems for postinst scripts
613 # restarting daemons so try to disable it
615 if pkg monit-cn; then
616 pkgrm monit-cn # disables monit in prerm
619 # if configured manually
621 # remove the binary but leave the config
622 apt-get remove --yes monit
624 pkill -9 monit || true
628 # make a silent upgrade to new libc6
630 DEBIAN_FRONTEND=noninteractive pkgadd libc6
633 # upgrade apache2 to etch
635 local package packages
638 libapache2-mod-php4 \
647 if pkg $package; then
648 packages="$packages $package"
652 # enable suhosin downgrade to etch version
653 if pkg php4-suhosin; then
654 pkgrm php4-suhosin php-suhosin-cn
657 eval pkgadd $packages
663 # remove init script diversion
664 if [ -L /etc/init.d/amavis -a -f /etc/init.d/amavis.amavisd-new ]; then
665 rm -vf /etc/init.d/amavis
666 dpkg-divert --quiet --remove /etc/init.d/amavis
669 # move old config aside
670 for conf in /etc/amavisd.conf /etc/amavis/amavisd.conf; do
671 if [ -e $conf -a ! -e $conf.$backup_ext ]; then
672 mv -v $conf $conf.$backup_ext
676 # install new packages
677 pkgadd amavisd-cn amavisd-new
680 check_and_sed '^clamd.*5.clamav.log$' \
681 's/^\(clamd.*\)5.clamav.log$/\14\tsocket/g' \
682 /etc/init.d/amavisd-cn || true
685 /etc/init.d/amavis restart
688 # fix openldap-aai postinst user handling
689 upgrade_openldap () {
690 pkg openldap-aai lt 2.3 || return 0
692 # openldap-aai expects org.ldif to exists
693 local ldif=/var/lib/ldap/org.ldif
694 local ldif_backup=/var/lib/carnet-upgrade/org.ldif
695 if [ -f $ldif ]; then
696 cp -v $ldif $ldif_backup
699 # slapd postinst fails if move_old_database is false
700 echo 'slapd slapd/move_old_database boolean true' | debconf-set-selections
703 # slapd removes org.ldif during switch from ldap -> openldap user
704 if [ -f $ldif_backup -a ! -f $ldif ]; then
705 cp -v $ldif_backup $ldif
708 # openldap-aai postinst fails here because of database permissions
709 apt-get -y install openldap-aai || true
710 chown -R openldap:openldap /var/lib/ldap
711 /etc/init.d/slapd restart
714 # remove ldap user if openldap works
715 if getent passwd ldap > /dev/null && \
716 getent passwd openldap > /dev/null && \
717 pgrep -U openldap slapd > /dev/null
719 log "userdel ldap (replaced by openldap)"
724 # fix postgresql deinstallation during upgrade
725 upgrade_postgresql () {
726 if check_services show 2>&1 | grep -qw postgresql; then
727 apt-get install -y postgresql || apt-get -yf install
735 if pkg postgrey; then
736 pkgrm postgrey # not used by postfix-cn anymore
741 local name=$1 file=$2 val
743 if [ -f "$file" ]; then
744 val=$(sed -n "/^[[:space:]]*$name[[:space:]]*=/s/[[:space:]]*//gp" $file)
751 # preserve mail location on upgrade
753 local default_mail_env mail_location
755 # check if already upgraded
756 if ! pkg dovecot-common lt 1.0; then
760 # save old mail location
761 default_mail_env=$(get_variable default_mail_env /etc/dovecot/dovecot.conf)
763 # silently upgrade package
764 restore_config /etc/dovecot/dovecot.conf
767 # insert old mail location
768 mail_location=$(get_variable mail_location /etc/dovecot/dovecot.conf)
769 if [ "$default_mail_env" -a ! "$mail_location" ]; then
770 check_and_sed '^#mail_location[[:space:]]*=' \
771 "s|#mail_location[[:space:]]*=.*|mail_location = $default_mail_env|" /etc/dovecot/dovecot.conf || return 0
773 if [ -x /etc/init.d/dovecot ]; then
774 if [ -x /usr/sbin/invoke-rc.d ]; then
775 /usr/sbin/invoke-rc.d dovecot restart
777 /etc/init.d/dovecot restart
783 # fix /etc/dpkg/dpkg.cfg
784 comment_force_overwrite () {
785 if [ -f /etc/dpkg/dpkg.cfg ]; then
786 if check_and_sed '^force-overwrite' \
787 's,\(^force-overwrite\),#\1,' \
788 /etc/dpkg/dpkg.cfg; then
789 notice "$msg_comment_force_overwrite"
795 cat > /etc/issue <<EOF
796 Debian GNU/Linux 4.0 (CARNet Debian 4.0) \\n \\l
799 cat > /etc/issue.net <<EOF
800 Debian GNU/Linux 4.0 (CARNet Debian 4.0) %h
805 local available_disk_space
806 available_disk_space=$(df -m /var|tail -1|awk '{print $4}')
807 if [ $available_disk_space -lt $min_var_space ]; then
808 log "carnet-upgrade aborted: not enough space on /var (need ${min_var_space}MB)"
809 notice "Premalo mjesta na /var particiji. Potrebno je imati barem ${min_var_space}MB."