Why is my bash script merging folders?

I hope this thread is in the right forum...

This is for a .deb package that will be installed on Cydia.

Pre'note': I am installing a custom 'hosts' file and AdSheet.app directory. My problem is during a reinstall/upgrade. Cydia will run the entire installation process again, which means it executes the preinst file and postrm file (I don't know why it runs both during a reinstall). For some reason (?) the AdSheet.app directory will merge the 'original' folder and my 'custom' folder together and be placed back in /Applications.

During reinstalls/upgrades, I created a method for moving the original files from the Ads_Suck folder to the Just_In_Case folder so as to preserve those files.

I'm thinking, though, that if I make a script in the preinst file to check 'if' the Applications/AdSheet.app is = 0, 'then' STOP the rest of the installation.

Again, thanx in advance for any help...

PREINST:

#!/bin/bash

mkdir /private/var/mobile/Ads_Suck

mkdir /private/var/mobile/Just_In_Case

cp -R /private/var/mobile/Ads_Suck/hosts /private/var/mobile/Just_In_Case

cp -R /etc/hosts /private/var/mobile/Ads_Suck

rm -r /etc/hosts

cp -R /private/var/mobile/Ads_Suck/AdSheet.app /private/var/mobile/Just_In_Case

RESULTS_SIZE=`stat -c %s /Applications/AdSheet.app`
if [ "$RESULTS_SIZE" -eq 0 ]
then

    echo "AdSheet.app is 0kB in size. I'm not replacing it..." 
    exit 1;

else

    cp -R /Applications/AdSheet.app /private/var/mobile/Ads_Suck
    rm -r /Applications/AdSheet.app

fi

echo "Original files are in var/mobile/Ads_Suck"

echo "Original files are in var/mobile/Ads_Suck"

echo "Original files are in var/mobile/Ads_Suck"

echo "Original files are in var/mobile/Ads_Suck"

declare -a cydia
cydia=($CYDIA)

if [[ $1 == install || $1 == upgrade ]]; then
    if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"
    fi
fi

exit

POSTRM:

#!/bin/bash

rm -r /etc/hosts

rm -r /Application/AdSheet.app

cp -R /private/var/mobile/Ads_Suck/hosts /etc

cp -R /private/var/mobile/Ads_Suck/AdSheet.app /Applications

echo "Restoring the original files"

echo "Restoring the original files"

echo "Restoring the original files"

DIR="/private/var/mobile/Just_In_Case/AdSheet.app"

if [ $# -ne 1 ]
then
    echo "found AdSheet.app"
    exit 0
fi

if [ -d "$DIR" ]
then
   rm -r /Applications/AdSheet.app
   cp -R "$DIR" /Applications 
   rm -r "$DIR"
fi

DIR="/private/var/mobile/Just_In_Case/hosts"

if [ $# -ne 1 ]
then
    echo "found 'hosts' file"
    exit 0
fi

if [ -f "$DIR" ]
then
   rm -r /etc/hosts
   cp -R "$DIR" /etc
   rm -r "$DIR"
fi

rm -r /private/var/mobile/Ads_Suck

rm -r /private/var/mobile/Just_In_Case

declare -a cydia
cydia=($CYDIA) 

if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"    
fi

exit

BUMP...

Anyone????