#!/bin/sh
set -e
export LC_ALL=C

cd $2
DMGFILE=$4

# We need group readability for some Macs to be able to handle /Applications
# installation. Still unclear exactly why this is -- it is not dependent on
# OSX version...
find . -executable -exec chmod 750 {} \;
find . ! -executable -exec chmod 640 {} \;

find . -type f | sed -e 's/^\.\///' | sort | xargs -i echo "{}={}" > /tmp/filelist.txt
find . -type l | sed -e 's/^\.\///' | sort | xargs -i echo "{}={}" >> /tmp/filelist.txt

mkisofs -D -V "$6" -no-pad -R -apple -o /tmp/icecat-uncompressed.dmg -path-list /tmp/filelist.txt -graft-points -gid 20 -dir-mode 0750 -new-dir-mode 0750


dmg dmg /tmp/icecat-uncompressed.dmg $4
rm /tmp/icecat-uncompressed.dmg

find . -executable -exec chmod 755 {} \;
find . ! -executable -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
