#! /usr/dt/bin/dtksh

# ----------------------------------------------------------
# wait due to sys.session's multiple procs inititalization
# ----------------------------------------------------------

if [ "$1" = "-wait" ]; then
   sleep 20
fi

export TRUE=1
export FALSE=0

# -----------------------------------------------
#  Return Codes
# -----------------------------------------------

export KEEP_FILES=10
export DELETE_FILES=11

# ------------------------------------------------------
#  Conditions checked 
#              1. X11rte.ext.obj is installed 
#              2. The /usr/lpp/xdt3 directory exists 
# 
#  Returns
#              TRUE - If both conditions are true
#             FALSE - If either condition is false
#
# ------------------------------------------------------

xdt3_installed ()
{
   ls -d /usr/lpp/xdt3 > /dev/null 2>&1
   rc1=$?

   # If the /usr/lpp/xdt3 directory exists, then return FALSE
   if [ $rc1 != 0 ]; then
      return $FALSE 
   fi

   return $TRUE
}
# ------------------------------------------------------
#  Routine that performs the actual file cleanup (both
#  SWVPD and filesystem).
# ------------------------------------------------------

blast_xdt_files ()
{
  export PROVIDED_INV_FILE=/usr/dt/install/oldrules/dtrmrules.data
  export CREATED_INV_FILE=/tmp/xdt3.inv.$$
 
  # -------------------------------------------------------------
  #  Call sysck -Ou -u to remove the inventory VPD entries and links
  #  for the provided inventory file.
  # -------------------------------------------------------------

  /usr/bin/sysck -Ou -u -f $PROVIDED_INV_FILE 

  # --------------------------------------------------------------
  # Build an inventory file of all /usr/lpp/xdt3 directory entries 
  # that exist in the USR inventory VPD, so we can blast them.
  # --------------------------------------------------------------

  ODMDIR=/usr/lib/objrepos /usr/bin/odmget inventory | /usr/bin/fgrep loc0 | \
  /usr/bin/awk -F\" '{ print $2":" }' | /usr/bin/grep "^/usr/lpp/xdt3"  \
  > $CREATED_INV_FILE

  rc=$?

  # -------------------------------------------------------------
  #  Call sysck -Ou -u to remove the inventory VPD entries and links
  #  for the created inventory file.
  # -------------------------------------------------------------

  if [ $rc = 0 ]; then
     /usr/bin/sysck -Ou -u -f $CREATED_INV_FILE 
  fi
  /usr/bin/rm -f $CREATED_INV_FILE

  # -----------------------------------------------
  # Remove the entire /usr/lpp/xdt3 directory
  # -----------------------------------------------

  /usr/bin/rm -rf /usr/lpp/xdt3

  # ------------------------------------------------------------
  # Remove the files specified in the provided inventory file
  # ------------------------------------------------------------

  /usr/bin/grep -v symlinks $PROVIDED_INV_FILE | \
  /usr/bin/awk -F: '{print $1}' | \
  while read FILE; do
     /usr/bin/rm -f $FILE 
  done

  exit $DELETE_FILES
}

# -----------------------------------------------
#  Callbacks for "Keep Files" dialog
# -----------------------------------------------

cancelCallback ()
{
   XtSetSensitive $FORM TRUE
}

okCallback ()
{
   exit $KEEP_FILES
}

# -----------------------------------------------
#  Callbacks for "Delete Files" dialog
# -----------------------------------------------

delcancelCallback ()
{
   XtSetSensitive $FORM TRUE
}

delokCallback ()
{
   XtSetSensitive $FORM FALSE
   XtSetSensitive $RMINFO FALSE
   blast_xdt_files
}

# -----------------------------------------------
#  Callbacks for "Help" dialog
# -----------------------------------------------

helpCancelCallback ()
{
  XtUnmanageChild $FORM1
  XtDestroyWidget $POPUP
  XtSetSensitive $FORM TRUE
}

# -----------------------------------------------
#  Callbacks for "Desktop Cleanup" push buttons
#            Keep Files push button
#            Delete Files push button
#            Help push button
# -----------------------------------------------

keepCallback ()
{

  XtSetSensitive $FORM FALSE
  XmCreateInformationDialog INFO $TOP infoDiag  \
                messageString:"
Are you sure you want to keep these files?

If you later decide to delete these files, type the
/usr/dt/install/oldrules/dtrmrules command.
" \
                dialogTitle:"$MAIN_TITLE - Keep Confirmation" \
                okLabelString:"Keep Files" \
                cancelLabelString:"Cancel Keep" \
                resizePolicy:RESIZE_NONE

  XmMessageBoxGetChild CHILD $INFO DIALOG_HELP_BUTTON 
  XtUnmanageChild $CHILD

  XtManageChild $INFO

  XtAddCallback $INFO okCallback "okCallback"
  XtAddCallback $INFO cancelCallback "cancelCallback"
}

# -------------------------------------------------------------------------

deleteCallback ()
{
  XtSetSensitive $FORM FALSE
  XmCreateInformationDialog RMINFO $TOP infoDiag  \
                messageString:"Are you sure you want to delete these files?
         Deleting Files may take several minutes..." \
                dialogTitle:"$MAIN_TITLE - Delete Confirmation" \
                okLabelString:"Delete Files" \
                cancelLabelString:"Cancel Delete" \
                resizePolicy:RESIZE_NONE

  XmMessageBoxGetChild RMCHILD $RMINFO DIALOG_HELP_BUTTON 
  XtUnmanageChild $RMCHILD

  XtManageChild $RMINFO

  XtAddCallback $RMINFO okCallback "delokCallback"
  XtAddCallback $RMINFO cancelCallback "delcancelCallback"
}

# -------------------------------------------------------------------------

helpCallback ()
{
XtSetSensitive $FORM FALSE

# Creation of dialogWindow1

XtCreateApplicationShell POPUP popup TopLevelShell

XtCreateManagedWidget FORM1 form1 XmForm $POPUP \
        width:960 \
        height:595

XtSetValues $POPUP minWidth:960 \
        minHeight:595

XtCreateManagedWidget SEP1 sep1 XmSeparator $FORM1 \
        bottomAttachment:ATTACH_FORM \
        bottomOffset:120 \
        leftAttachment:ATTACH_FORM \
        rightAttachment:ATTACH_FORM

# Creation of scrolledListWindow1
XtCreateManagedWidget SWIN1 swin1 XmScrolledWindow $FORM1 \
        scrollingPolicy:AUTOMATIC \
        visualPolicy:VARIABLE \
        scrollBarDisplayPolicy:AS_NEEDED \
        leftAttachment:ATTACH_POSITION \
        leftPosition:13 \
        rightAttachment:ATTACH_POSITION \
        rightPosition:95 \
        topAttachment:ATTACH_POSITION \
        topPosition:2 \
        bottomAttachment:ATTACH_WIDGET \
        bottomWidget:$SEP1 \
        bottomOffset:10


XtCreateManagedWidget LABEL1 label1 XmLabel $SWIN1 \
        stringDirection:STRING_DIRECTION_L_TO_R \
	recomputeSize:FALSE \
        alignment:ALIGNMENT_BEGINNING \
        labelString:"
If this dialog appears it means that the AIXwindows Desktop for IBM AIX V3.2x 
(old desktop), was previously installed on this system. In the old desktop, 
each icon had an associated "rules" file. This file contained the name of the 
icon and the actions that the icon performed.

The AIXwindows Desktop Version 4.1(V4.1 Desktop) is a totally new desktop. 
It cannot use the old desktop rules files. The old desktop files can be 
converted to run on the V4.1 Desktop. This dialog is asking whether you want 
to keep the old desktop rules files so that you can convert them for use on 
the V4.1 Desktop. 

In the old desktop there were two types of rules files:

Default rules files and icons - 
These are the default icons that make up the desktop. For example, the trash 
can, home folder, and file cabinets are all examples of default rules files 
icons.

Custom rules files and icons - 
These were created by the system administrator or a user to customize the 
desktop. This may have been done for tools and applications that were written 
at your site. For example, your company may have written a time-card 
application and your system administrator created a new icon for it and wrote 
a rules file for the icon.

When you chose Migration when you installed AIX V4.1, the Custom rules files 
were automatically preserved so that you can convert them. This dialog is 
asking whether you want to keep or delete the old Default rules files and 
icons.  The new V4.1 Desktop already has its own default actions (trash can, 
file cabinet, etc.) and it does not need the old desktop rules files. In most 
cases it is not necessary to keep the default old desktop files and you should 
choose Delete Files to free up your storage space.  However, you may want to 
keep the old desktop files if you created custom rules files and you used the 
default icons instead of creating new custom icons.

Dialog Buttons:

Keep Files  The old desktop rules files and icons will not be erased. 
  They will remain on your disk. If at a later date you decide that 
  you want to remove the old rules and icons you can enter 
  the following command to bring back this dialog:
  /usr/dt/install/oldrules/dtrmrules

Erase Files  The old desktop rules files and icons will be erased from your 
  disk to free up space.

Further Information:
  Consult your desktop migration documentation for information on migration 
  from the old desktop to the new desktop and for rules conversion techniques.
"  

XtCreateManagedWidget PB4 pb4 XmPushButton $FORM1 \
        labelString:"Cancel" \
        topAttachment:ATTACH_WIDGET \
        topOffset:45 \
        topWidget:$SEP1 \
        leftAttachment:ATTACH_POSITION \
        leftPosition:40 \
        rightAttachment:ATTACH_POSITION \
        rightPosition:60

XtAddCallback $PB4 activateCallback "helpCancelCallback"
XtRealizeWidget $POPUP

}

#--------------------------------------------------------------
#    M A I N
#--------------------------------------------------------------


xdt3_installed

XDT3_INSTALLED=$?

if [ $XDT3_INSTALLED = ${FALSE} ]; then
   exit ${DELETE_FILES}
fi


MAIN_TITLE="Desktop Cleanup"

XtInitialize TOP Attention "${MAIN_TITLE}" 

XtDisplay DISPLAY $TOP

XtCreateManagedWidget FORM form XmForm $TOP \
        width:869 \
        height:474 

XtSetValues $TOP minWidth:869 \
        minHeight:474 \
	x:220 \
	y:245

XtCreateManagedWidget SEP sep XmSeparator $FORM \
        bottomAttachment:ATTACH_FORM \
        bottomOffset:120 \
        leftAttachment:ATTACH_FORM \
        rightAttachment:ATTACH_FORM

# Creation of scrolledListWindow1
XtCreateManagedWidget SWIN swin XmScrolledWindow $FORM \
        scrollingPolicy:AUTOMATIC \
        visualPolicy:VARIABLE \
        scrollBarDisplayPolicy:AS_NEEDED \
        leftAttachment:ATTACH_POSITION \
        leftPosition:13 \
        rightAttachment:ATTACH_POSITION \
        rightPosition:95 \
        topAttachment:ATTACH_POSITION \
        topPosition:2 \
        bottomAttachment:ATTACH_WIDGET \
        bottomWidget:$SEP \
        bottomOffset:10 


XtCreateManagedWidget LABEL label XmLabel $SWIN \
	stringDirection:STRING_DIRECTION_L_TO_R \
	alignment:ALIGNMENT_BEGINNING \
        labelString:"
The v3.2 Aixwindows Desktop (X desktop) was previously installed on your
system.  Do you want to keep the old system rule files and icons for 
possible migration to the new v4.1 desktop or just remove them?  These 
files minimally take up several megabytes of disk space, and more 
depending on which locales are installed.  Note that not all of these
files and icons will be migrateable, and migration will require 
additional steps.

If you did not use the v3.2 desktop or you used it, but did not customize
it, you probably should delete these files, because these files are not 
needed to run the new desktop.  

How do you want to proceed?" 


XtCreateManagedWidget label1 label1 \
        XmLabel $FORM \
        labelType:PIXMAP \
        labelPixmap:"/usr/dt/install/oldrules/dtrmrules.ico" \
        leftAttachment:ATTACH_POSITION \
        leftPosition:3 \
        topAttachment:ATTACH_POSITION \
        topPosition:30

XtCreateManagedWidget PB1 pb1 XmPushButton $FORM \
        labelString:"Keep Files" \
        topAttachment:ATTACH_WIDGET \
        topOffset:45 \
        topWidget:$SEP \
        leftAttachment:ATTACH_POSITION \
        leftPosition:10  \
        rightAttachment:ATTACH_POSITION \
        rightPosition:30 

XtCreateManagedWidget PB3 pb3 XmPushButton $FORM \
        labelString:"Help" \
        topAttachment:ATTACH_WIDGET \
        topOffset:45 \
        topWidget:$SEP \
        leftAttachment:ATTACH_POSITION \
        leftPosition:70 \
        rightAttachment:ATTACH_POSITION \
        rightPosition:90 

XtCreateManagedWidget PB2 pb2 XmPushButton $FORM \
        labelString:"Delete Files" \
        topAttachment:ATTACH_WIDGET \
        topOffset:45 \
        topWidget:$SEP \
        leftAttachment:ATTACH_POSITION \
        leftPosition:40 \
        rightAttachment:ATTACH_POSITION \
        rightPosition:60



XtAddCallback $PB1 activateCallback "keepCallback"
XtAddCallback $PB2 activateCallback "deleteCallback"
XtAddCallback $PB3 activateCallback "helpCallback" 

XtRealizeWidget $TOP

XtMainLoop
