#!/bin/sh
# Portions Copyright (c) 2003 Apple Computer, Inc.  All rights reserved.
if [ -d /afs -a ! -h /afs ]; then
   rmdir /afs
fi
majorvers=`uname -r | sed 's/\..*//'`
if [ $majorvers -ge 7 ]; then
  # /Network is now readonly, so put AFS in /afs; make sure /afs is a directory
  if [ -e /afs ]; then
    if [ -h /afs -o ! -d /afs ]; then
      rm -f /afs
      mkdir /afs
    fi
  else
    mkdir /afs
  fi
else
  mkdir -p /Network/afs
  if [ ! -h /afs ]; then
    ln -s /Network/afs /afs
  fi
fi

cd /var/db/openafs/etc

if [ ! -f cacheinfo ]; then
   cp cacheinfo.sample cacheinfo
fi

# testing case -- upgrading from pre 1.2.7, but .last file exists.
# merge the .save and .last....
if [ ! -f CellServDB -a -f CellServDB.save -a -f CellServDB.master.last ]; then
   cp CellServDB.save CellServDB
fi

# upgrading between 2 post-1.2.7 releases (or the testing case)
if [ -f CellServDB.master.last ]; then
  if cmp -s CellServDB.master.last CellServDB.master ; then
    echo No CellServDB updates
    done=1
  fi
fi

# the local changes were included in the update
if [ -z "$done" -a  -f CellServDB ]; then
  if cmp -s CellServDB CellServDB.master ; then
    echo CellServDB is up to date.
    cp CellServDB.master CellServDB.master.last
    done=1
  fi
fi

if [ -z "$done" ]; then
  # there are local changes to be merged
  if [ -f CellServDB -a -f CellServDB.master.last ]; then
    echo Merging CellServDB entries....
    perl $1/Contents/Resources/csrvdbmerge.pl
    echo done
  else
    # this is a new install, or an upgrade from pre-1.2.7
    echo "Installing new CellServDB"
    cp CellServDB.master CellServDB.master.last
    cp CellServDB.master CellServDB
  fi
fi

if [ $majorvers -ge 7 ]; then
  # make config/settings.plist if it doesn't exist
  if [ ! -e config/settings.plist -a -e config/settings.plist.orig ]; then
    cp config/settings.plist.orig config/settings.plist
  fi
elif [ -e config/afssettings ]; then
  # turn off execution of afssettings
  chmod a-x config/afssettings
fi
