Changed backup extenstion. Updated logging format.
authorValentin Vidic <vvidic@carnet.hr>
Tue, 18 Dec 2007 11:40:01 +0000 (12:40 +0100)
committerValentin Vidic <vvidic@carnet.hr>
Tue, 18 Dec 2007 11:40:01 +0000 (12:40 +0100)
usr/share/carnet-upgrade/functions.sh

index 3c179a1..cd2bc56 100644 (file)
@@ -198,7 +198,7 @@ run_post_upgrade() {
 ###
 
 run_actions() {
-  local line lineno lineno2 f n name action
+  local line lineno lineno2 f n name action testmsg
   [ "$DEBUG" ] && set -vx
   name="$1"
   f="$2"
@@ -224,12 +224,14 @@ run_actions() {
     done
     test=$(echo "$line" | sed 's/              */      /g'| awk -F'    ' '{print $1}')
     action=$(echo "$line" | sed 's/            */      /g'| awk -F'    ' '{print $2}')
+    testmsg=""
+    [ "$test" != "true" ] && testmsg="if '$test'"
     if eval $test; then
-      log "$(printf 'action %02d' $lineno) starting: '${action}' if '$test'"
+      log "$(printf 'action %02d' $lineno) starting: '${action}' $testmsg "
       eval $action
-      log "$(printf 'action %02d' $lineno) finished: '${action}'"
+      log "$(printf 'action %02d' $lineno) finished: '${action}' $testmsg"
     else
-      log "$(printf 'action %02d' $lineno) skipping: '${action}' if '$test'"
+      log "$(printf 'action %02d' $lineno) skipping: '${action}' $testmsg"
     fi
     [ "$lineno2" -gt "$lineno" ] && lineno=$lineno2
   done
@@ -302,8 +304,8 @@ upgrade () {
 
 # funkcija utrpa ispravan sources.list
 create_sources_list () {
-    [ -f /etc/apt/sources.list -a ! -f /etc/apt/sources.list.cn-upgrade ] && mv /etc/apt/sources.list /etc/apt/sources.list.cn-upgrade
-    cp /usr/share/carnet-upgrade/sources.list /etc/apt
+    [ -f /etc/apt/sources.list -a ! -f /etc/apt/sources.list.cn3-upgrade ] && mv /etc/apt/sources.list /etc/apt/sources.list.cn3-upgrade
+    cp /usr/share/carnet-upgrade/files/sources.list /etc/apt
     notice "Novi sadrzaj datoteke /etc/apt/sources.list:
 
 `cat /etc/apt/sources.list`"
@@ -332,54 +334,83 @@ add_group_proc () {
 
 # backup_slapd_db
 backup_slapd_db () {
-  if [ ! -f /var/backups/slapcat.cn-upgrade ]; then
+  local ldap_backup=/var/backup/slapcat.cn3-upgrade
+
+  if [ ! -f $ldap_backup ]; then
     [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius stop || true
 
     if [ -x /etc/init.d/slapd -a -d /var/lib/ldap ]; then
       /etc/init.d/slapd stop || true
-      if slapcat -l /var/backups/slapcat.cn-upgrade; then
-        log "/var/backups/slapcat.cn-upgrade created"
-        notice "Napravljen backup slapd baze u /var/backups/slapcat.cn-upgrade."
+      if slapcat -l $ldap_backup; then
+        log "$ldap_backup created"
+        notice "Napravljen backup slapd baze u $ldap_backup."
       fi
       /etc/init.d/slapd start || true
     fi
 
     [ -x /etc/init.d/freeradius ] && /etc/init.d/freeradius start || true
   else
-    log "slapd backup already at /var/backups/slapcat.cn-upgrade, skipping"
-    notice "Backup slapd baze u /var/backups/slapcat.cn-upgrade vec postoji!"
+    log "slapd backup already at $ldap_backup, skipping"
+    notice "Backup slapd baze u $ldap_backup vec postoji!"
   fi
 }
 
 # backup etc direktorija
 backup_etc_dir () {
-  if [ ! -f /var/backups/etc.tar.gz ]; then
-    if tar cfz /var/backups/etc.tar.gz /etc 2> /dev/null; then
-      log "/var/backups/etc.tar.gz created"
-      notice "Napravljen backup /etc direktorija u /var/backups/etc.tar.gz."
+  local etc_backup=/var/backups/etc.cn3-upgrade.tar.gz
+
+  if [ ! -f $etc_backup ]; then
+    if tar cfz $etc_backup /etc 2> /dev/null; then
+      log "$etc_backup created"
+      notice "Napravljen backup /etc direktorija u $etc_backup."
     fi
   else
-    log "/etc backup already present in /var/backups/etc.tar.gz, skipping."
-    notice "Backup /etc direktorija u /var/backups/etc.tar.gz vec postoji!"
+    log "/etc backup already present in $etc_backup, skipping."
+    notice "Backup /etc direktorija u $etc_backup vec postoji!"
   fi
 }
 
 # fixaj /etc/default/raid2
 fix_etc_default_raid2 () {
   if [ -f /etc/default/raid2 ]; then
-    sed "s/^AUTOSTART.*/AUTOSTART=true/g" /etc/default/raid2 > /etc/default/raid2.cn-upgrade.$$
-    chown --reference=/etc/default/raid2 /etc/default/raid2.cn-upgrade.$$
-    chmod --reference=/etc/default/raid2 /etc/default/raid2.cn-upgrade.$$
+    sed "s/^AUTOSTART.*/AUTOSTART=true/g" /etc/default/raid2 > /etc/default/raid2.cn3-upgrade.$$
+    chown --reference=/etc/default/raid2 /etc/default/raid2.cn3-upgrade.$$
+    chmod --reference=/etc/default/raid2 /etc/default/raid2.cn3-upgrade.$$
 
-    if ! cmp -s /etc/default/raid2.cn-upgrade.$$ /etc/default/raid2; then
+    if ! cmp -s /etc/default/raid2.cn3-upgrade.$$ /etc/default/raid2; then
       log "Fixed /etc/default/raid2 AUTOSTART option."
-      mv /etc/default/raid2.cn-upgrade.$$ /etc/default/raid2
+      mv /etc/default/raid2.cn3-upgrade.$$ /etc/default/raid2
     else
-      rm /etc/default/raid2.cn-upgrade.$$
+      rm /etc/default/raid2.cn3-upgrade.$$
     fi
   fi
 }
 
+# restore distribution config file
+restore_config () {
+  local file
+
+  for file in "$@"; do
+    # backup changes
+    if [ -f "$file" -a ! -f "$file.cn3-upgrade" ]; then
+      mv "$file" "$file.cn3-upgrade"
+    fi
+
+    # install original
+    cp "/usr/share/carnet/upgrade/files/$file" "$file"
+  done
+}
+
+# upgrade apache -> apache2
+install_apache2 () {
+  # bugfix za apache2-cn postinst
+  mkdir -p /etc/apache2
+  touch /etc/apache2/httpd.conf
+
+  pkgadd php4-odbc php4-xslt mktemp
+  pkgadd apache2 squirrelmail apache2-cn squirrelmail-cn
+}
+
 # instaliraj zadnji freeradius; uvjeti u queue fileovima
 install_freeradius () {
   pkgadd --force-yes freeradius-cn freeradius=1.0.5-0 freeradius-ldap=1.0.5-0
@@ -485,16 +516,16 @@ fix_smtp_auth() {
   fi
   if [ -f $conf -a -f $tmpl ] && \
     ! cmp -s $conf $tmpl; then
-    mv $conf $conf.cn-upgrade
+    mv $conf $conf.cn3-upgrade
     mv_in_sasl=1
   fi
   if [ -f $confdir/Sendmail.conf ]; then
-    mv $confdir/Sendmail.conf $confdir/Sendmail.conf.cn-upgrade
+    mv $confdir/Sendmail.conf $confdir/Sendmail.conf.cn3-upgrade
     mv_in_sasl=1
   fi
   if [ -f $confdir/sasl.m4 ] && \
     ! cmp -s $confdir/sasl.m4 $tmpldir/sasl.m4; then
-    mv -f $confdir/sasl.m4 $confdir/sasl.m4.cn-upgrade
+    mv -f $confdir/sasl.m4 $confdir/sasl.m4.cn3-upgrade
     mv_in_sasl=1
   fi
   [ "$mv_in_sasl" ] && \