#!/bin/sh

#
# Show arguments and wait for cancellation.
#
#echo "source package path: $1"
#echo "package destination: $2"
#echo "mount point of dest: $3"
#echo "installer framework: $4"

#
# If the ServerSetup directory does not exist then create it.
# If it exists set the ownership and permissions.
#
if [ -e "$3/System/Library/ServerSetup" ]; then
    if [ ! -e "$3/System/Library/ServerSetup/Configured" ]; then
        mkdir "$3/System/Library/ServerSetup/Configured"
    fi
    if [ ! -e "$3/System/Library/ServerSetup/UnConfigured" ]; then
        mkdir "$3/System/Library/ServerSetup/UnConfigured"
    fi
    "$3/usr/sbin/chown" 0:0 "$3/System/Library/ServerSetup/Configured"
    "$3/usr/sbin/chown" 0:0 "$3/System/Library/ServerSetup/UnConfigured"
    chmod 755 "$3/System/Library/ServerSetup/Configured"
    chmod 755 "$3/System/Library/ServerSetup/UnConfigured"
fi

###
# If this is an upgrade from 10.1 (with the old package names),
# run the post-upgrade script instead.
#
###
if [ -d "$3/Library/Receipts/Mac_OS_X_Server_Admin.pkg" ]; then
    "$1/Contents/Resources/postupgrade"
    rm -rf "$3/Library/Receipts/Mac_OS_X_Server_Admin.pkg"
    rm -rf "$3/Library/Receipts/MacintoshManagerAdmin.pkg"
    exit 0
fi

###
# If Server Settings exists then we want to move it to the new /Applications/Server/Manage 10.2 Server folder.
#   This is so that they can contiue to administrate older server while being on the new system
# 
###
if [ -e "$3/Applications/Utilities/Server Settings.app" ]; then
    echo -n "Preserving old Server Settings.app..."
    if [ ! -e "$3/Applications/Server/Manage 10.2 Server" ]; then
        mkdir -p "$3/Applications/Server/Manage 10.2 Server"
    fi
    mv "$3/Applications/Utilities/Server Settings.app" "$3/Applications/Server/Manage 10.2 Server"
    echo "done."
fi

###
# Delete the old version of the Assistant app
# iff we are a Server!
#
###
if [ -e "$2/Library/Receipts/ServerEssentials.pkg" ] ; then
    echo -n "Deleting archaic version of Assistant..."
    rm -rf "$2/System/Library/CoreServices/Setup Assistant.app"
    rm "$2/Applications/Utilities/Setup Assistant.app"
    echo "done."
fi
    
# 
# Run the common post- operations.
#  
"$1/Contents/Resources/postcommon" "$1" "$2" "$3" "$4"
