I\'m building a linux installer for a Java application, and I end up with an install.jar and a setup.sh that I put in a zip file using ant.
The idea is the user unzi
If you use a tar file instead of a zip file, it should preserve the permissions for you. The files' owners and groups might not match up, but the permission bits will.
I think you can do this with Apache Commons Compress.
First paragraph:
Access to internal and external attributes (which are used to store Unix permission by some zip implementations).
Take a look at the API and look for setUnixMode()
<shellscript shell="sh" dir="abc" failonerror="true">
zip -ry abc.zip *
</shellscript>
The ant script above invokes a shell script to create the zip archive in which the permissions are very well preserved. It works with Ant 1.7 and above. However I have not tried verified running this ant script on windows. This works very well on mac.
zip/unzip in modern linux distros will preserve file permissions. But you need to make sure that the zip in windows honours this.
To expand on Blaine’s answer, you can use <zipfileset> child elements to specify permissions:
<zip destfile="build/MyApplication.zip" encoding="UTF-8">
<zipfileset dir="${content-dir}" encoding="UTF-8"
includes="**/setup.sh" filemode="755"/>
<zipfileset dir="${content-dir}" encoding="UTF-8"
excludes="**/setup.sh"/>
</zip>
You cannot store Linux/Unix file permissions in a ZIP file.
Edit (after comments) by using the "external attributes" field inside the ZIP header these attributes can be store inside a ZIP file. GNU's unzip
is apparently able to read that additional field and restore file permissions. I'm not sure when this was added to the ZIP format as the early versions - coming from a MS-DOS world - did not have support for this.
The TAR format - being a "native" Unix/Linux format - has been designed to include file attributes and Ant can create TAR files that will preserve attributes across all Linux/Unix operating systems.
<tar compression="gzip" destfile="my-archive.tgz"> <tarfileset mode="544" dir="dir_with_shell_scripts"> <include name="*.sh"/> </tarfileset> </tar>