Remove apache-common (prevents installation of apache2-cn).
[carnet-upgrade.git] / src / functions.sh
index beccd14..beccc6d 100644 (file)
@@ -588,7 +588,7 @@ reboot_required () {
 }
 
 upgrade () {
-  local i to_install packages
+  local packages
   case "$1" in
     first)
       packages="$packages_first"
@@ -600,16 +600,7 @@ upgrade () {
     return 1
   esac
 
-  for i in $(echo $packages)
-  do
-    pkg $i && to_install="$to_install $i"
-  done
-
-  if [ -n "$to_install" ];then
-    eval pkgadd $to_install
-  else
-    return 0
-  fi
+  pkgadd_if_installed $packages
 }
 
 # funkcija utrpa ispravan sources.list
@@ -800,7 +791,7 @@ copy_template () {
 # restore modified config to their package defaults
 # so the upgrade doesn't complain so much
 restore_configs () {
-  local hostname domain template config_new
+  local hostname domain config_new memtotal memlimit
 
   # restore simple configs
   if pkg kernel-2.6-cn && pkg procps lt 1:3.2.7-11; then
@@ -863,16 +854,34 @@ restore_configs () {
      restore_file /etc/issue.net
   fi
 
+  # restore php.ini
+  memtotal=$(awk '$1 == "MemTotal:" { print int($2/1024) }' /proc/meminfo)
+  if [ $memtotal -gt 1024 ]; then
+    memlimit=64
+  elif [ $memtotal -ge 512 ]; then
+    memlimit=32
+  else
+    memlimit=16
+  fi
+  
   if pkg php5-cn && pkg php5-cli lt 5.2.6.dfsg.1-1+lenny2; then
-     if restore_file /etc/php5/cli/php.ini; then
+     config_new=$(copy_template /etc/php5/cli/php.ini)
+     sed -i "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${memlimit}M/" $config_new
+     sed -i "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${memlimit}M/" $config_new
+     if restore_file /etc/php5/cli/php.ini $config_new; then
         postupgrade_reconfigure php5-cn
      fi
+     rm -f $config_new
   fi
 
   if pkg php5-cn && pkg libapache2-mod-php5 lt 5.2.6.dfsg.1-1+lenny2; then
-     if restore_file /etc/php5/apache2/php.ini; then
+     config_new=$(copy_template /etc/php5/apache2/php.ini)
+     sed -i "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${memlimit}M/" $config_new
+     sed -i "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${memlimit}M/" $config_new
+     if restore_file /etc/php5/apache2/php.ini $config_new; then
         postupgrade_reconfigure php5-cn
      fi
+     rm -f $config_new
   fi
 
   # check if monitrc is template based
@@ -886,49 +895,6 @@ restore_configs () {
      restore_file /etc/monit/monitrc $config_new
      rm -f $config_new
   fi
-
-#  restore_config login 1:4.0.18.1 /etc/pam.d/login
-#  restore_config mysql-server 5.0.3 /etc/init.d/mysql \
-#                                    /etc/logrotate.d/mysql-server \
-#                                    /etc/mysql/my.cnf
-#  restore_config ntpdate 1:4.2.2 /etc/default/ntpdate
-#  restore_config oidentd 2.0.8 /etc/default/oidentd
-#  restore_config slapd 2.3.30 /etc/default/slapd /etc/init.d/slapd
-#  restore_config squirrelmail 2:1.4.9a /etc/squirrelmail/apache.conf
-#  restore_config vsftpd 2.0.5 /etc/vsftpd.conf
-#  restore_config xinetd 1:2.3.14 /etc/xinetd.conf
-#
-#  # orphaned config file - no owner
-#  if pkg logcheck-database lt 1.2.54; then
-#      rm -vf /etc/logcheck/ignore.d.server/imap
-#  fi
-#
-#  # aide switched to ucf, move old configs aside
-#  if pkg aide lt 0.13.1; then
-#      for file in /etc/aide/aide.conf \
-#                  /etc/cron.daily/aide \
-#                  /etc/default/aide;
-#      do
-#          if [ ! -e "$file.$backup_ext" ]; then
-#              mv -v "$file" "$file.$backup_ext"
-#          fi
-#
-#          rm -vf "$file"
-#      done
-#  fi
-#
-#  # register cn changes in ucf managed files
-#  for config in /etc/apache/modules.conf \
-#                /etc/clamav/clamd.conf \
-#                /etc/clamav/freshclam.conf
-#  do 
-#      config_backup=$config.$backup_ext
-#      if [ -e $config -a ! -e $config_backup ]; then
-#          log "Saving config file $config"
-#          cp -av $config $config_backup
-#          ucf $config_backup $config
-#      fi
-#  done
 }
 
 # temporary disable listchanges packages to reduce clutter during upgrade
@@ -958,7 +924,7 @@ apt_listchanges () {
 # make a silent installation of carnet and srce keyrings
 install_keyrings () {
   pkgadd carnet-keyring srce-keyring debian-archive-keyring
-  pkgadd dpkg apt debconf python-apt
+  pkgadd_if_installed dpkg apt debconf python-apt dpkg-dev
 
   dpkg-reconfigure carnet-keyring srce-keyring debian-archive-keyring
   apt_update
@@ -975,9 +941,11 @@ remove_skey () {
 }
 
 # remove unsupported php version
+# but leave the configuration just in case
 remove_php4 () {
-  # leave the configuration just in case
-  pkgrm_only php4-common || true
+  if pkg php5-cn && pkg php4-common; then
+     pkgrm_only php4-common
+  fi
 }
 
 # check if package is orphaned (nothing depends on it)
@@ -1020,30 +988,40 @@ disable_monit () {
   fi
 }
 
+# check which of the given packages are installed
+grep_installed () {
+  local package installed
+
+  for package in $*; do
+    if pkg $package; then
+      installed="$installed $package"
+    fi
+  done
+
+  echo $installed
+}
+
+# only upgrade packages if they are already installed
+pkgadd_if_installed () {
+  local packages
+
+  packages=$( grep_installed $* )
+
+  if [ "$packages" ]; then
+    eval pkgadd $packages
+  fi
+}
+
 # make a silent upgrade to new libc6
 upgrade_libc () {
-  DEBIAN_FRONTEND=noninteractive pkgadd libc6 tzdata
+  DEBIAN_FRONTEND=noninteractive pkgadd_if_installed libc6 libc6-dev tzdata
 }
 
-# upgrade apache2 to lenny
+# upgrade apache2/php5 to lenny
 upgrade_apache2 () {
-  local package packages
-
-  for package in \
-      libapache2-mod-php5 \
-      php5-cli \
-      php5-cn \
-      apache2-cn \
-      php5-odbc \
-      php5-suhosin \
-      php-suhosin-cn
-  do
-      if pkg $package; then
-          packages="$packages $package"
-      fi
-  done
-
-  eval pkgadd $packages
+  pkgrm apache-common # prevents installation of apache2-suexec
+  pkgadd_if_installed libapache2-mod-php5 php5-cli php5-cn apache2-cn \
+    php5-odbc php5-suhosin php-suhosin-cn
 }
 
 upgrade_amavis () {