config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
    # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

preserve_perms() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ -e $OLD ]; then
    cp -a $OLD ${NEW}.incoming
    cat $NEW > ${NEW}.incoming
    mv ${NEW}.incoming $NEW
  fi
  config $NEW
}

preserve_perms etc/profile.d/karma.sh.new
preserve_perms etc/profile.d/karma.csh.new

( cd /usr/local ; ln -sf /opt/karma karma )
( cd opt/karma/doc ; rm -rf COPYING )
( cd opt/karma/doc ; ln -sf COPYING-2.0 COPYING )
( cd opt/karma/doc ; rm -rf COPYING.LIB )
( cd opt/karma/doc ; ln -sf COPYING.LIB-2.0 COPYING.LIB )
( cd opt/karma/lib ; rm -rf libkarma.so )
( cd opt/karma/lib ; ln -sf libkarma.so.1.7.25 libkarma.so )
( cd opt/karma/lib ; rm -rf libkarmaX11.so )
( cd opt/karma/lib ; ln -sf libkarmaX11.so.1.7.25 libkarmaX11.so )
( cd opt/karma/lib ; rm -rf libkarmaXt.so )
( cd opt/karma/lib ; ln -sf libkarmaXt.so.1.7.25 libkarmaXt.so )
( cd opt/karma/lib ; rm -rf libkarmagraphics.so )
( cd opt/karma/lib ; ln -sf libkarmagraphics.so.1.7.25 libkarmagraphics.so )
( cd opt/karma/lib ; rm -rf libkarmawidgets.so )
( cd opt/karma/lib ; ln -sf libkarmawidgets.so.1.7.25 libkarmawidgets.so )
( cd opt/karma/www ; rm -rf README.lib )
( cd opt/karma/www ; ln -sf ../doc/README.lib README.lib )
( cd opt/karma/www ; rm -rf modules.html )
( cd opt/karma/www ; ln -sf ../doc/modules/Overview modules.html )
( cd opt/karma/www/programmer-manual ; rm -rf :datafilters.html )
( cd opt/karma/www/programmer-manual ; ln -sf ./node12.html :datafilters.html )
( cd opt/karma/www/programmer-manual ; rm -rf datafilters.html )
( cd opt/karma/www/programmer-manual ; ln -sf ./node12.html datafilters.html )
( cd opt/karma/www ; rm -rf update-policy )
( cd opt/karma/www ; ln -sf ../doc/update-policy update-policy )
( cd opt/karma/www/user-manual ; rm -rf axislabels.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html axislabels.html )
( cd opt/karma/www/user-manual ; rm -rf centroidingalgorithm.html )
( cd opt/karma/www/user-manual ; ln -sf ./node10.html centroidingalgorithm.html )
( cd opt/karma/www/user-manual ; rm -rf colourcontrol.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html colourcontrol.html )
( cd opt/karma/www/user-manual ; rm -rf commonfeatures.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html commonfeatures.html )
( cd opt/karma/www/user-manual ; rm -rf datafilters.html )
( cd opt/karma/www/user-manual ; ln -sf ./node2.html datafilters.html )
( cd opt/karma/www/user-manual ; rm -rf dataformats.html )
( cd opt/karma/www/user-manual ; ln -sf ./node2.html dataformats.html )
( cd opt/karma/www/user-manual ; rm -rf freezingevents.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html freezingevents.html )
( cd opt/karma/www/user-manual ; rm -rf hardcopies.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html hardcopies.html )
( cd opt/karma/www/user-manual ; rm -rf imagestatistics.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html imagestatistics.html )
( cd opt/karma/www/user-manual ; rm -rf koords.html )
( cd opt/karma/www/user-manual ; ln -sf ./node10.html koords.html )
( cd opt/karma/www/user-manual ; rm -rf kpvslice.html )
( cd opt/karma/www/user-manual ; ln -sf ./node7.html kpvslice.html )
( cd opt/karma/www/user-manual ; rm -rf kshell.html )
( cd opt/karma/www/user-manual ; ln -sf ./node9.html kshell.html )
( cd opt/karma/www/user-manual ; rm -rf kslice3d.html )
( cd opt/karma/www/user-manual ; ln -sf ./node8.html kslice3d.html )
( cd opt/karma/www/user-manual ; rm -rf kvis.html )
( cd opt/karma/www/user-manual ; ln -sf ./node4.html kvis.html )
( cd opt/karma/www/user-manual ; rm -rf loadingdata.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html loadingdata.html )
( cd opt/karma/www/user-manual ; rm -rf magnifier.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html magnifier.html )
( cd opt/karma/www/user-manual ; rm -rf movies.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html movies.html )
( cd opt/karma/www/user-manual ; rm -rf panner.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html panner.html )
( cd opt/karma/www/user-manual ; rm -rf partialdata.html )
( cd opt/karma/www/user-manual ; ln -sf ./node2.html partialdata.html )
( cd opt/karma/www/user-manual ; rm -rf profiles.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html profiles.html )
( cd opt/karma/www/user-manual ; rm -rf pubrenzograms.html )
( cd opt/karma/www/user-manual ; ln -sf ./node4.html pubrenzograms.html )
( cd opt/karma/www/user-manual ; rm -rf resizingdisplays.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html resizingdisplays.html )
( cd opt/karma/www/user-manual ; rm -rf superimposingimages.html )
( cd opt/karma/www/user-manual ; ln -sf ./node12.html superimposingimages.html )
( cd opt/karma/www/user-manual ; rm -rf viewingheaders.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html viewingheaders.html )
( cd opt/karma/www/user-manual ; rm -rf xray.html )
( cd opt/karma/www/user-manual ; ln -sf ./node6.html xray.html )
( cd opt/karma/www/user-manual ; rm -rf zooming.html )
( cd opt/karma/www/user-manual ; ln -sf ./node3.html zooming.html )
( cd usr/doc/karma-1.7.25 ; rm -rf COPYING )
( cd usr/doc/karma-1.7.25 ; ln -sf /opt/karma/doc/COPYING COPYING )
( cd usr/doc/karma-1.7.25 ; rm -rf README )
( cd usr/doc/karma-1.7.25 ; ln -sf /opt/karma/doc/README README )
