1 # last update: 2005-07-03
2 # Ivan 'ico' Rako <irako@srce.hr>
3 # Zoran 'jelly' Dzelajlija <jelly@srce.hr>
6 dialog --backtitle "$title" --msgbox "$*" 18 75
10 dialog --backtitle "$title" --yesno "$msg_first_warning" 18 75
15 dpkg -l "$1" 2> /dev/null | egrep -q "^.i" || return 1
16 [ -z "$2" ] && return 0
17 version=$(dpkg -s "$1" | awk '/^Version:/ {print $2}')
18 dpkg --compare-versions "$version" "$2" "$3" 2>&1 > /dev/null
22 logfile=${logfile:=/var/log/carnet-upgrade.log}
24 echo "$(date +'%Y-%m-%d %H:%M:%S') $*" >> $logfile
28 # find first free uid/gid in range
29 # find_id passwd 100 999
31 local db first last ids
35 ids=$(getent $db | awk -F: "\$3 >= $first && \$3 <= $last {print \$3}")
36 for i in $(seq $first $last)
38 if ! echo $ids |grep -q $i; then
48 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
57 [ -e "$i" ] || continue
58 egrep -q "$s" "$i" || continue
59 [ -h "$i" ] && i=$(readlink -f "$i")
60 sed "$sedcmd" "$i" > "$i.dpkg-tmp"
61 chown --reference "$i" "$i.dpkg-tmp"
62 chmod --reference "$i" "$i.dpkg-tmp"
66 if [ "$ret" -eq 0 ]; then
67 log "Done \"$sedcmd\" to $*"
73 # Update uid for user from reserved system range (0-99) to dynamic system
74 # range (100-999). Optionally update ownerships of given directories.
75 # $0 user [directory ...]
77 check_and_update_ugid() {
78 local user newgid newuid
80 if [ "$(getent passwd $user | awk -F: '$3 >= 100 {print "ok"; exit 0}')" ]; then
84 newgid=$(find_id group 100 999)
85 newuid=$(find_id passwd 100 999)
86 # other directories/files
87 chown -R $newuid:$newgid $*
88 groupmod -g $newgid $user
89 usermod -u $newuid -g $newgid $user
90 log "Fixed $user user uid/gid."
94 [ -n "$*" ] || return 0
95 log "Installing $* ..."
96 apt-get -y$s install $* || {
99 apt-get -y$s install $*
104 [ -n "$*" ] || return 0
105 log "Removing $* ..."
106 apt-get -y$s --purge remove $* || {
109 apt-get -y$s --purge remove $*
114 log "Running apt-get update ..."
115 apt-get -y$s update || {
120 apt-get -dy$s dist-upgrade
124 log "Running dist-upgrade ..."
125 apt-get -y$s dist-upgrade || {
127 apt-get -y$s dist-upgrade
132 local to_remove add_this i j n text to_show cmd tmpfile installed
133 local update_selections pkgs_to_deselect oldifs
134 text="$msg_remove_bloat"
136 [ "$DEBUG" ] && set -x
138 for i in $(echo "$bloats" | sed 's/ */ /g'| awk -F' ' '{print $2}')
141 installed="$installed $i"
142 add_this="$(echo "$bloats" | egrep " .*\b${i}\b" | sed 's/ */ /g'| awk -F' ' '{print $1}')"
143 if ! echo "$to_show" | grep -q "$add_this"; then
144 to_show="$to_show \"$add_this\" \"\" on"
149 [ -z "$to_show" ] && return 0
150 tmpfile=$(mktemp /var/lib/carnet-upgrade/dialog-tmp.XXXXXX)
151 cmd="dialog --nocancel --backtitle \""$title"\" --checklist \""$text"\" 20 75 $n $to_show"
152 [ "$DEBUG" ] && set +x
153 eval $cmd 2> $tmpfile
154 [ "$DEBUG" ] && set -x
155 to_remove="$(cat $tmpfile | sed 's/\"\ \"/ /g; s/\"\ *//g; s/\\//g')"
156 [ "$DEBUG" ] || rm -f $tmpfile
157 [ "$DEBUG" ] && echo "DEBUG: to_remove=$to_remove" 1>&2
160 for i in $(echo "$to_remove")
163 for j in $(echo "$bloats" | grep "^$i" | sed 's/ */ /g'| awk -F' ' '{print $2}')
165 # hopefully this will tell apt not to reinstall them at upgrade time
166 update_selections="${update_selections}
168 pkgs_to_deselect="$pkgs_to_deselect $j"
169 # only remove those that really are installed
170 if echo "$installed" | grep -q "$j"; then
171 pkgs_to_remove="$pkgs_to_remove $j"
175 [ "$DEBUG" ] && echo "DEBUG: pkgs_to_remove=$pkgs_to_remove" 1>&2
176 # Finally, remove those
177 if [ -n "$update_selections" ]; then
178 echo "$update_selections" | dpkg --set-selections
179 log "Deselected:${pkgs_to_deselect}"
181 eval pkgrm $pkgs_to_remove
185 touch "$post_upgrade_queuetab"
186 if ! grep -q "true $*" "$post_upgrade_queuetab"; then
187 echo "true $*" >> "$post_upgrade_queuetab"
192 if [ -f "$post_upgrade_queuetab" ]; then
193 run_actions post_upgrade "$post_upgrade_queuetab"
194 mv "$post_upgrade_queuetab" "${post_upgrade_queuetab}.done.$(date '+%Y-%m-%d.%H:%M:%S')"
201 local line lineno lineno2 f n name action testmsg
202 [ "$DEBUG" ] && set -vx
205 [ -f "$f" ] || return 2 # no such file
206 n=$(wc -l "$f" | awk '{print $1}')
207 [ "$n" -lt 1 ] && return 1 # no lines to process
208 log "run_actions ($name) started, processing $n lines from \"$f\"."
212 while [ "$lineno" -lt "$n" ]
214 lineno=$(($lineno+1))
216 line=$(head -$lineno "$f" | tail -1)
217 if echo $line | grep -q '^#'; then # comment
220 while echo "$line" | egrep -q '\\$' # continuation
222 lineno2=$(($lineno2+1))
223 line=$(echo -n "$line"| sed 's/\\$//'; head -$lineno2 "$f" | tail -1)
225 test=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $1}')
226 action=$(echo "$line" | sed 's/ */ /g'| awk -F' ' '{print $2}')
228 [ "$test" != "true" ] && testmsg="if '$test'"
230 log "$(printf 'action %02d' $lineno) starting: '${action}' $testmsg "
232 log "$(printf 'action %02d' $lineno) finished: '${action}' $testmsg"
234 log "$(printf 'action %02d' $lineno) skipping: '${action}' $testmsg"
236 [ "$lineno2" -gt "$lineno" ] && lineno=$lineno2
238 log "run_actions ($1) finished"
242 # funkcija vraca popis paketa koje treba upgradeati
244 local IFSOLD name version package
246 for package in `echo "$needed_versions" | awk '{print $1}'| grep -v ^$`; do
249 read name version <<-EOPTS
250 $(echo "$needed_versions" | sed 's/ */ /g' | grep ^$package)
253 if pkg "$name" lt "$version"; then
259 # funkcija za ispis paketa koje treba upgradeati
262 upgrade="`what_upgrade`"
264 if [ "$upgrade" ]; then
266 Prije prelaska na Debian Etch potrebno je napraviti nadogradnju ovih paketa:
270 'apt-get dist-upgrade'
272 'apt-get install${upgrade}'
274 Nakon toga ponovno pozovite ovu skriptu."
275 log "carnet-upgrade aborted, upgrade of$upgrade needed."
281 local to_install packages
284 packages="$packages_first"
287 packages="$packages_second"
295 pkg $i && to_install="$to_install $i"
298 if [ -n "$to_install" ];then
299 eval pkgadd $to_install
305 # funkcija utrpa ispravan sources.list
306 create_sources_list () {
308 sl=/etc/apt/sources.list
309 sl_new=/usr/share/carnet-upgrade/files/etc/apt/sources.list
311 # check if already installed
312 if ! cmp $sl $sl_new >/dev/null; then
315 if [ -f $sl -a ! -f $sl.$backup_ext ]; then
316 cp -a $sl $sl.$backup_ext
319 # install new version
321 notice "Novi sadrzaj datoteke /etc/apt/sources.list:
323 `cat /etc/apt/sources.list`"
328 # funkcija koja brise grupu proc
329 remove_group_proc () {
330 if getent group proc > /dev/null; then
331 groupdel proc || true
332 log "groupdel proc (temporarily)"
333 post_upgrade add_group_proc
338 if ! getent group proc > /dev/null; then
339 # grsec uses gid 99 for /proc files
341 log "groupadd -g 99 proc"
343 # update oidentd so it uses the proc group
344 if [ -x /etc/init.d/oidentd ]; then
345 if gpasswd -a oident proc; then
346 /etc/init.d/oidentd restart
352 # backup ldap database
354 local ldap_backup=/var/backups/slapcat.$backup_ext
355 local old_umask result
357 if [ ! -f $ldap_backup ]; then
358 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius stop || true
360 if [ -x /etc/init.d/slapd -a -d /var/lib/ldap ]; then
361 /etc/init.d/slapd stop || true
363 umask 0077 # protect the backup file
364 slapcat -l $ldap_backup
367 /etc/init.d/slapd start || true
369 if [ "$result" eq 0 ]; then
370 log "$ldap_backup created"
371 notice "Napravljen backup slapd baze u $ldap_backup."
373 log "$ldap_backup was not created"
374 notice "Backup slapd baze u $ldap_backup nije uspio."
379 [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius start || true
381 log "slapd backup already at $ldap_backup, skipping."
382 notice "Backup slapd baze u $ldap_backup vec postoji!"
386 # backup etc direktorija
388 local etc_backup=/var/backups/etc.$backup_ext.tar.gz
391 if [ ! -f $etc_backup ]; then
393 umask 0077 # protect the backup file
395 if tar cfz $etc_backup /etc 2> /dev/null; then
396 log "$etc_backup created"
397 notice "Napravljen backup /etc direktorija u $etc_backup."
399 log "$etc_backup was not created"
400 notice "Backup /etc direktorija u $etc_backup nije uspio."
405 log "/etc backup already present in $etc_backup, skipping."
406 notice "Backup /etc direktorija u $etc_backup vec postoji!"
410 # fixaj /etc/default/raid2
411 fix_etc_default_raid2 () {
412 if [ -f /etc/default/raid2 ]; then
413 sed "s/^AUTOSTART.*/AUTOSTART=true/g" /etc/default/raid2 > /etc/default/raid2.$backup_ext.$$
414 chown --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
415 chmod --reference=/etc/default/raid2 /etc/default/raid2.$backup_ext.$$
417 if ! cmp -s /etc/default/raid2.$backup_ext.$$ /etc/default/raid2; then
418 log "Fixed /etc/default/raid2 AUTOSTART option."
419 mv /etc/default/raid2.$backup_ext.$$ /etc/default/raid2
421 rm /etc/default/raid2.$backup_ext.$$
426 # restore original config file (if the new package version is not
429 local file file_backup file_orig
434 # check package version
435 pkg $pkg lt $ver || return 0
437 # create new files safely
441 # restore package files
443 file_orig=/usr/share/carnet-upgrade/files/$file
444 file_backup=$file.$backup_ext
446 if cmp $file_orig $file >/dev/null; then
447 continue # original file is already in place
450 if [ -e $file -a ! -e $file_backup ]; then
452 mv $file $file_backup
455 log Restoring config file $file
457 chown --reference $file_backup $file
458 chmod --reference $file_backup $file
465 # restore modified config to their package defaults
466 # so the upgrade doesn't complain so much
468 restore_config base-files 4 /etc/issue /etc/issue.net
469 restore_config bind9 1:9.3.4 /etc/bind/named.conf.options
470 restore_config dovecot-common 1.0 /etc/dovecot/dovecot.conf
471 restore_config libapache-mod-php4 6:4.4.4 /etc/php4/apache/php.ini
472 restore_config libpam-modules 0.79 /etc/security/limits.conf
473 restore_config login 1:4.0.18.1 /etc/pam.d/login
474 restore_config mysql-server 5.0.3 /etc/init.d/mysql \
475 /etc/logrotate.d/mysql-server \
477 restore_config ntp 1:4.2.2 /etc/ntp.conf
478 restore_config ntpdate 1:4.2.2 /etc/default/ntpdate
479 restore_config oidentd 2.0.8 /etc/default/oidentd
480 restore_config php4-cgi 6:4.4.4 /etc/php4/cgi/php.ini
481 restore_config php4-cli 6:4.4.4 /etc/php4/cli/php.ini
482 restore_config postgrey 1.27 /etc/default/postgrey \
483 /etc/postgrey/whitelist_clients
484 restore_config procps 1:3.2.7 /etc/sysctl.conf
485 restore_config sasl2-bin 2.1.22 /etc/default/saslauthd
486 restore_config slapd 2.3.30 /etc/default/slapd /etc/init.d/slapd
487 restore_config squirrelmail 2:1.4.9a /etc/squirrelmail/apache.conf
488 restore_config vsftpd 2.0.5 /etc/vsftpd.conf
489 restore_config xinetd 1:2.3.14 /etc/xinetd.conf
491 # orphaned config file - no owner
492 if pkg logcheck-database lt 1.2.54; then
493 rm -f /etc/logcheck/ignore.d.server/imap
496 # aide switched to ucf, move old configs aside
497 if pkg aide lt 0.13.1; then
498 for file in /etc/aide/aide.conf \
499 /etc/cron.daily/aide \
502 if [ ! -e "$file.$backup_ext" ]; then
503 mv "$file" "$file.$backup_ext"
511 # temporary disable listchanges packages to reduce clutter during upgrade
513 local file command=$1
515 for file in /etc/apt/apt.conf.d/20listchanges \
516 /etc/apt/apt.conf.d/20listchanges-cn
520 if [ -f $file ]; then
521 dpkg-divert --local --rename --divert $file.$backup_ext \
527 if [ -f $file.$backup_ext ]; then
528 dpkg-divert --remove $file || true
535 # make a silent installation of carnet and srce keyrings
536 install_keyrings () {
537 pkgadd carnet-keyring srce-keyring
538 pkgadd dpkg apt debconf
540 dpkg-reconfigure carnet-keyring srce-keyring
544 # remove skey (not supported anymore)
546 pkgrm skey-cn libpam-skey
548 if getent group skey > /dev/null; then
549 groupdel skey || true
554 # make a silent upgrade to new libc6
556 DEBIAN_FRONTEND=noninteractive pkgadd libc6
559 # upgrade apache -> apache2
562 # bugfix for apache2-cn postinst
563 mkdir -p /etc/apache2
564 touch /etc/apache2/httpd.conf
566 # register cn changes in modules.conf
567 modules_conf=/etc/apache/modules.conf
568 if [ ! -e "$modules_conf.$backup_ext" ]; then
569 cp -a "$modules_conf" "$modules_conf.$backup_ext"
570 ucf $modules_conf $modules_conf
573 # temporary remove packages conflicting with apache2
575 for p in aosi-aai aosi-www-aai \
576 php4-cn php4-odbc php4-xslt \
579 # remember installed packages
585 # remove problematic stuff
586 if [ "$delpkg" ]; then
587 eval apt-get --yes remove $delpkg
591 pkgrm apache apache-common
593 # install new packages
594 eval pkgadd apache2-cn apache2-mpm-prefork \
595 php4-cn libapache2-mod-php4 \
600 # remove init script diversion
601 if [ -L /etc/init.d/amavis -a -f /etc/init.d/amavis.amavisd-new ]; then
602 rm -f /etc/init.d/amavis
603 dpkg-divert --quiet --remove /etc/init.d/amavis
606 # move old config aside
607 local conf=/etc/amavis/amavisd.conf
608 if [ -e $conf -a ! -e $conf.$backup_ext ]; then
609 mv $conf $conf.$backup_ext
612 # install new packages
613 pkgadd amavisd-cn amavisd-new
616 check_and_sed '^clamd.*5.clamav.log$' \
617 's/^\(clamd.*\)5.clamav.log$/\14\tsocket/g' \
618 /etc/init.d/amavisd-cn || true
621 /etc/init.d/amavis restart
624 # fix openldap-aai postinst user handling
625 upgrade_openldap () {
626 #pkgrm openldap-cn # deprecated
627 apt-get -y$s install openldap-aai || true # postinst fails
628 chown -R openldap:openldap /var/lib/ldap # fix slapd
629 /etc/init.d/slapd restart
630 dpkg --configure -a # try postinst again
633 # fix /etc/dpkg/dpkg.cfg
634 comment_force_overwrite () {
635 if [ -f /etc/dpkg/dpkg.cfg ]; then
636 if check_and_sed '^force-overwrite' \
637 's,\(^force-overwrite\),#\1,' \
638 /etc/dpkg/dpkg.cfg; then
639 notice "$msg_comment_force_overwrite"
645 cat > /etc/issue <<EOF
646 Debian GNU/Linux 4.0 (CARNet Debian 4.0) \\n \\l
649 cat > /etc/issue.net <<EOF
650 Debian GNU/Linux 4.0 (CARNet Debian 4.0) %h
655 local available_disk_space
656 available_disk_space=$(df -m /var|tail -1|awk '{print $4}')
657 if [ $available_disk_space -lt $min_var_space ]; then
658 log "carnet-upgrade aborted: not enough space on /var (need ${min_var_space}MB)"
659 notice "Premalo mjesta na /var particiji. Potrebno je imati barem ${min_var_space}MB."