Can I store unix permissions in a zip file (built with apache ant)?

I am creating a linux installer for a Java application and in the end I have install.jar and setup.sh which I installed in a zip file using ant.

The idea is that the user unpacks the zip file and then runs setup.sh, but the problem is that they always need chmod setup.sh to grant execution rights.

I want to remove this step, and I'm not sure if the problem is:

  • This is Im building in Windows
  • This is Im building with ant zip task
  • Or that zips cannot issue permissions and will always unpack without x permission.
+7
source share
6 answers

You cannot store Linux / Unix file permissions in a ZIP file.

Modify (after comments) using the "external attributes" field inside the ZIP header, these attributes can be stored inside the ZIP file. GNU unzip can apparently read this extra field and restore file permissions. I am not sure when it was added to the ZIP format, as earlier versions - from the MS-DOS world - did not support this.

The TAR format - the "native" Unix / Linux format - is designed to include file attributes, and Ant can create TAR files that retain the attributes on 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>
+12
source

You do not need to switch to tar files. I do not know why people who do not know Ant offer tips on this topic.

Use the zipfileset filemode file option. Documented at http://ant.apache.org/manual/Types/zipfileset.html

+18
source

zip / unzip on modern Linux distributions will retain file permissions. But you need to make sure that zip on windows reads this.

+1
source

If you use a tar file instead of a zip file, it should save permissions for you. File owners and groups may not match, but permission bits will be.

0
source

I think you can do it 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 find setUnixMode()

0
source
 <shellscript shell="sh" dir="abc" failonerror="true"> zip -ry abc.zip * </shellscript> 

ant script above calls the shell script to create a zip archive in which permissions are very well preserved. It works with ant 1.7 and above. However, I have not tried to check if this ant script works on windows. This works very well on a Mac.

0
source

All Articles