#!/bin/bash

# First parameter: Root path that will be removed
# MY_ROOT=/export/home/is/root

if [ $# -ne 1 -o -z "$1" ]
then
  echo "One parameter required"
  echo "Usage:"
  echo "1. parameter: Path to the local root directory"
  echo "All packages in local database will be removed!"
  exit 2
fi

MY_ROOT=$1

cd `dirname $0`
DIRECTORY=`pwd`

GETUID_SO=/tmp/getuid.so.$$
linenum=59
tail +$linenum `basename $0` > $GETUID_SO

PKGLIST=`pkginfo -R $MY_ROOT | cut -f 2 -d ' ' | grep -v core`
COREPKG=`pkginfo -R $MY_ROOT | cut -f 2 -d ' ' | grep core`
COREPKG01=`pkginfo -R $MY_ROOT | cut -f 2 -d ' ' | grep core01`

echo "#############################################"
echo "#     Deinstallation of Office packages     #"
echo "#############################################"
echo
echo "Path to the root directory :  " $MY_ROOT
echo
echo "Packages to deinstall:"
for i in $PKGLIST $COREPKG; do
  echo $i
done

INSTALL_DIR=$MY_ROOT`pkginfo -R $MY_ROOT -r $COREPKG01`

# Restore original bootstraprc and sofficerc
mv -f $INSTALL_DIR/program/bootstraprc.orig $INSTALL_DIR/program/bootstraprc
mv -f $INSTALL_DIR/program/soffice.orig $INSTALL_DIR/program/soffice

for i in $PKGLIST $COREPKG; do
  LD_PRELOAD=$GETUID_SO /usr/sbin/pkgrm -n -R $MY_ROOT $i
done

# Removing old root directory, very dangerous!
# rm -rf $MY_ROOT

# removing library in temp directory
rm -f $GETUID_SO

echo
echo "Deinstallation done..."

exit 0
ELF                    4        4    (                   
  
           
 
                                                                                                                             	   
   
                                                                                                                                                                               
                   $          +  
      
   2       	   8          9              >          H  <        N 
         d        "              "        X          p                "              "              "        `                    	     
     P          x                "             "     *             0  h      _PROCEDURE_LINKAGE_TABLE_ _DYNAMIC _edata _etext _init fstat fstatat64 chmod _GLOBAL_OFFSET_TABLE_ __1cG__CrunVdo_exit_code_in_range6Fpv1_v_ __1cH__CimplKcplus_fini6F_v_ lchown setuid atexit _ex_register _get_exit_frame_monitor fchown _end _fini setgid __1cH__CimplKcplus_init6F_v_ _ex_deregister dlsym getuid libdl.so.1 SISCD_2.3 libCrun.so.1 SUNW_1.1 libc.so.1 SYSVABI_1.3 SUNWprivate_1.1 libpthread.so.1 libm.so.1 $ORIGIN       7       zt      B        L       
='      Y        b       7̳      l   Nq      x     4     	 8      l        p     L       H       D       h       @       <       0       
                          㿘@   5  A-   'D<'H#\ #`      @\@@ A	?\   ᴂ@ ` \   D
   HH#`  H $H$  `  @   5  @-   'D'H#\       @\?@@ @ې?\   Ḃ@ ` H`@ 
D@ @Ӓt     H`@'H\%   D   H 㿘@   -  @'D+   'Ha'L 'P #\#`    @\@@ @?\   @'` \   DaHL   PL#`  L $` L#$`  㿠@     㿠@      l?       㿠@      @?        x`??????                @     @  @     @         @     @        㿠@      ?           @      L???쀤                @     @          chown lchown fchown getuid setuid setgid fstat chmod fstatat64  fstat   chmod   fstatat64                                                      00     <0      o        7     o        Lo        o        b        
  	                        
             o  Go  Do   o                    8              	   o   o   lo   o         o      
                                                                                              	getuid.c  cg: Sun Compiler Common 11 2005/10/13 cg: Sun Compiler Common 11 2005/10/13 @(#)fcntl.h	1.15	01/07/29 SMI @(#)feature_tests.h	1.18	99/07/26 SMI @(#)isa_defs.h	1.20	99/05/04 SMI @(#)types.h	1.75	04/01/06 SMI @(#)machtypes.h	1.13	99/05/04 SMI @(#)int_types.h	1.6	97/08/20 SMI @(#)select.h	1.17	01/08/15 SMI @(#)time.h	2.72	05/01/24 SMI @(#)time.h	1.39	99/08/10 SMI @(#)time_iso.h	1.1	99/08/09 SMI @(#)time_impl.h	1.7	01/09/06 SMI @(#)fcntl.h	1.48	01/12/17 SMI @(#)stat.h	1.4	03/06/01 SMI @(#)stat_impl.h	1.3	03/06/01 SMI @(#)unistd.h	1.60	01/07/29 SMI @(#)unistd.h	1.39	01/07/29 SMI @(#)dlfcn.h	1.40	05/08/08 SMI @(#)auxv.h	1.27	00/02/07 SMI @(#)systeminfo.h	1.18	99/07/18 SMI @(#)strings.h	1.3	96/03/12 SMI @(#)string.h	1.24	99/08/10 SMI @(#)string_iso.h	1.2	99/11/09 SMI acomp: Sun C 5.8 2005/10/13 iropt: Sun Compiler Common 11 2005/10/13  .SUNW_syminfo .hash .dynsym .dynstr .SUNW_version .SUNW_reloc .rela.plt .text .init .fini .exception_ranges .rodata .rodata1 .got .dynamic .ex_shared .cpp_finidata .data .bss .symtab .strtab .compcom .debug_info .debug_line .debug_abbrev .debug_pubnames .debug_typenames .debug_varnames .comment .shstrtab                                               o   B         l                                                                               "                        %o     D  D   p                3                             ?      B  8  8                  I        P  P                    O                               U        	  	                     [        
`  
`                    m        
d  
d   ?                  u        
  
                     ~       
  
                    D       
  
   L                                                    0  0   8                         h  h                            t  t                                                                    !                                 I                 )               3               