Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a shell file that is pulled from github and built into a zip using TeamCity.

It is typically edited and put into github from a Windows machine.

I need this shell script to be executable upon unzipping. How do I do this? Currently I have to do chmod +x blah.sh

share|improve this question

4 Answers 4

up vote 2 down vote accepted

The quickest and easiest solution would probably be to use a shell script that addresses your permissions after running the unzip.

share|improve this answer
    
Yeah - I guess I was hoping for a way to avoid this. But the unzip is already being run via shell script, so I will just do this! Thanks. –  elgabito May 4 '12 at 13:16
#! /bin/bash
#First argument ($1) would be the name of the file to be unzipped
#Second argument ($2) would be where to unzip the files to (absolute path)
unzip $1 -d $2
find $2 -name *.sh -print0 | xargs -0 chmod +x

This would work as long as the files you were wanting to make as executable were always going to be *.sh. Otherwise could always add a third argument ($3) and substitute it for the *.sh but then you would always have to input the name of the file to be made executable for every archive.

share|improve this answer
    
That would make all the files from the zip u+x though, would it not? Including adding traverse permissions to all directories and execute to non-executable files? –  Falcon Momot May 3 '12 at 19:52
    
Very true. The script would go in /usr/bin. Still a kludge but best way I could think of to address the issue. –  Rob May 4 '12 at 0:51

You should create the archive with a Unix zip to preserve the Unix attributes.

share|improve this answer
    
Yes, but I'm not zipping it, TeamCity is. –  elgabito May 3 '12 at 18:01

What shell are you using? I know in bash you can define your own commands (via alias), for example once i made a custom command i called cdsee and it took a single parameter (a directory) and cd'd to it, then ls -lah immediately. made it very easy to do my work, as i immediately saw the contents of said folder.

It should, likewise, be possible, and even easy, to make a command that would run the unzip command, and then immediately chmod +x.

Unfortunately, how to pull arguments is escaping me at the moment. But the simplest answer would be to use a linux machine for the originating zip-job, or making your custom command/alias execute the chmod automatically.

share|improve this answer
    
Having an alias with its own semantic arguments is kind of a kludge. It would very nearly be better to write a small script and place it in /usr/bin or something. –  Falcon Momot May 3 '12 at 19:51
1  
it works, and is simple to implement. what's the problem with that? also, i don't entirely know what you're talking about with a small script in usr/bin. an alias is just the solution i know of that would work. –  acolyte May 3 '12 at 20:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.