#!/bin/bash

##
# decompress: run from the postinstall script to decompress the 7z archives

##
# track the 7za status and return it at the end of the script
result=0

##
# extract the (de) compressor
Z=7za
rm -rf setX.txt    # remove old copy of setX.txt
rm -rf $Z          # remove old copy of 7za
unzip  $Z.zip      # unzip a new copy of 7za

##
# decompress the folders (and remove the compressed archives)
for folder in MacOS AcroCEF Plugins Helpers Frameworks Plug-ins Resources Services Support; do
	if [ $result == 0 ]; then 
		echo decompressing $folder/
		./$Z  x -y $folder.7z	# extracts $folder/ from $folder.7z
		result=$?				# remember if we failed!
		rm -rf     $folder.7z	# remove the compressed archive
        if [ "$folder" = "MacOS" ]; then
            echo "Will touch the app icon"
            path_app="$(dirname "$PWD")"    #
            touch "$path_app" # touch Reader app-  upon extracting MacOs contents , we refresh its icon
        fi
	fi
done

##
# set the permissions (as prescribed by Apple)
find . -name "*" -type d -depth                    -exec chmod 0775 {} ";"
find . -name "*" -type f -depth                    -exec chmod 0664 {} ";"

# 2684939 and 2690875.  Set the X bit by reading setX.txt
{
	while read filename; do
		if [ -e "$filename" ]; then 
  			chmod 775 "$filename"
		fi
	done
} < "setX.txt"

##
# 2717261
chown root MacOS
chown root Resources


##
# cleanup:  remove the compressor (postinstall removes -this- script)
rm -rf setX.txt    # remove old copy of setX.txt
rm -rf $Z          # remove old copy of 7za
rm -rf $Z.zip

exit $result

# That's all Folks!
##
