Better function name for package upgrade.
[carnet-upgrade.git] / src / functions.sh
index 9040822..9e6b16f 100644 (file)
@@ -600,7 +600,7 @@ upgrade () {
     return 1
   esac
 
-  pkgadd_if_installed $packages
+  pkgupgrade $packages
 }
 
 # install packages introduced in this release
@@ -931,7 +931,7 @@ apt_listchanges () {
 # make a silent installation of carnet and srce keyrings
 install_keyrings () {
   pkgadd carnet-keyring srce-keyring debian-archive-keyring
-  pkgadd_if_installed dpkg apt debconf python-apt dpkg-dev
+  pkgupgrade dpkg apt debconf python-apt dpkg-dev
 
   dpkg-reconfigure carnet-keyring srce-keyring debian-archive-keyring
   apt_update
@@ -1009,7 +1009,7 @@ grep_installed () {
 }
 
 # only upgrade packages if they are already installed
-pkgadd_if_installed () {
+pkgupgrade () {
   local packages
 
   packages=$( grep_installed $* )
@@ -1021,13 +1021,13 @@ pkgadd_if_installed () {
 
 # make a silent upgrade to new libc6
 upgrade_libc () {
-  DEBIAN_FRONTEND=noninteractive pkgadd_if_installed libc6 libc6-dev tzdata
+  DEBIAN_FRONTEND=noninteractive pkgupgrade libc6 libc6-dev tzdata
 }
 
 # upgrade apache2/php5 to lenny
 upgrade_apache2 () {
   pkgrm apache-common # prevents installation of apache2-suexec
-  pkgadd_if_installed libapache2-mod-php5 php5-cli php5-cn apache2-cn \
+  pkgupgrade libapache2-mod-php5 php5-cli php5-cn apache2-cn \
     php5-odbc php5-suhosin php-suhosin-cn
 }
 
@@ -1066,51 +1066,15 @@ upgrade_amavis () {
   /etc/init.d/amavis restart
 }
 
-# handle freerdius config files upgrade
+# handle freerdius upgrade
 upgrade_freeradius () {
   local template config_new password realm hostname basedn
 
   pkg freeradius-aai lt 2.1.3-0lenny0 || return 0
 
-  # handle static configs
-  restore_file /etc/freeradius/clients.conf
-  restore_file /etc/freeradius/hints
-  restore_file /etc/freeradius/ldap.attrmap
-
-  # handle template based configs
-  basedn=$(sed -n '/^[[:space:]]*suffix[[:space:]]*/ { 
-    s///; s/"//g; p; q }' /etc/ldap/slapd.conf)
-  hostname=$(hostname -f)
-  config_new=$(copy_template /etc/freeradius/radiusd.conf)
-  sed -i "s/#HOSTNAME#/$hostname/" $config_new
-  sed -i "s/#BASEDN#/$basedn/" $config_new
-  restore_file /etc/freeradius/radiusd.conf $config_new
-  rm -f $config_new
-
-  password=$(grep -s '^[[:space:]]*private_key_password[[:space:]]*=' \
-    /etc/freeradius/eap.conf)
-  config_new=$(copy_template /etc/freeradius/eap.conf)
-  sed -i "s/.*#PASSWORD#.*/$password/" $config_new
-  restore_file /etc/freeradius/eap.conf $config_new
-  rm -f $config_new
-  
-  realm=$(sed -n '/^[[:space:]]*suffix[[:space:]]*/ { 
-    s///; s/"//g; s/,dc=/./g; s/dc=//; s/.hr$//; p; q }' /etc/ldap/slapd.conf)
-  config_new=$(copy_template /etc/freeradius/proxy.conf)
-  sed -i "s/#REALM#/$realm/" $config_new
-  restore_file /etc/freeradius/proxy.conf $config_new
-  rm -f $config_new
-
-  # install the new packages
-  if ! apt-get -y install freeradius; then
-     # freeradius upgrade fails here, try to fix it by creating certificates
-     [ -x /etc/freeradius/certs/bootstrap ] && /etc/freeradius/certs/bootstrap
-     
-     dpkg --configure -a
-     apt-get -y -f install
-  fi
-
-  # finally try to cleanup this mess
+  # aai team prevents a clean lenny upgrade
+  cp -av /etc/freeradius /etc/freeradius.$backup_ext
+  pkgrm freeradius-aai freeradius-ldap freeradius
   pkgadd freeradius-aai
 }
 
@@ -1173,6 +1137,13 @@ upgrade_postfix () {
   fi
 }
 
+# upgrade bind separately so DNS is not down for too long
+# or breaks postinst scripts of other cn packages that depend on
+# working resolver
+upgrade_bind() {
+  pkgadd bind9-cn
+}
+
 get_variable () {
   local name=$1 file=$2 val