Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am deploying some custom software as root (a necessity for this situation).

I set the owner/group to user1:user1 and set all the files to 644 beforehand in shell, then copy and deploy with ant.

However, when files get copied over from the deployment directory, the ownership changes back to root and all the files install with 666 permissions.

This seems to occur whether the file is overwritten or newly created. I believe there is a way to set an option in cp, mv commands to preserve permissions, but that would be a lot of commands to change. How can I fix this?

Is there some setting I can change temporarily for root so the install always preserves the file permissions?

share|improve this question
    
Are you using a script with lots of cp and mv commands? If yes it should be easy to change all of them with sed to use the options you need (see my answer below). –  Claudio Jul 10 '12 at 16:12
    
Yes I have a number of cp/mv commands, but they are occuring in my ant deploy.xml, so not shell script. –  yellavon Jul 10 '12 at 19:54
add comment

2 Answers

cp -p will preserve your permissions. If you want the copy to be the closest possible you can simply use the "archive" option: cp -a. From cp --help you can double check it:

-a, --archive                same as -dR --preserve=all

-p                           same as --preserve=mode,ownership,timestamps
  --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                             mode,ownership,timestamps), if possible
                             additional attributes: context, links, xattr,
                             all
share|improve this answer
    
This is not available for ant, instead you have to use exec and cp. –  Bobby Dec 9 '13 at 8:54
add comment

No. But you should be using install instead, which lets you explicitly specify all that.

share|improve this answer
1  
Can you expand on that? Google didn't turn up any good explanations or examples. –  yellavon Jul 11 '12 at 13:56
add comment

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.