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 wrote a little shellscript that helps installing a web application. The script itself just downloads a zip archive, extracts it and changes the permissions of the extracted files to the one needed to run the webapp.
The problem now is that some users reported that after running my script, all the permissions of every file in their home directory or even on their whole computer changed to 000 (except the actual unzipped files which do have the correct permissions).
The only lines in my script actually doing IO are these:

URL="http://foo.com/"
FILENAME="some.zip"
curl --silent "$URL$FILENAME" -o $FILENAME > /dev/null
echo "Unzipping...\c"
if unzip -oqq $FILENAME > /dev/null
then
    chmod -R 777 app/tmp app/webroot app/Config/database* app/configuration*
    chown -R www:www *
    rm $FILENAME
    echo "\t\t\tOK"
    exit 0
else
    echo "\t\t\tERROR"
    exit 1
fi

I seriously can't explain this to myself. How can this even be possible?
It is entirely possible that the users accidentally ran the script in their home directory, but that still wouldn't explain why the permissions where set to 000, not www/777.

share|improve this question
    
You can't change the permissions of "the whole computer" without root privileges. I don't see any obvious error here. –  slhck Jun 29 '12 at 7:41
    
@slhck Actually the script asks for root permissions because it may not be able to change the permissions of the files or download the zip because it may not have permission over the working directory (for example in /var/www). –  half_bit Jun 29 '12 at 7:50
    
sooo many things wrong.... When you do chown -R www.www *, are you SURE you're in the right subdir? you're changing EVERYTHING in the CURRENT directory (and everything below it) to being owned by www. Bad. What is your intent of the \c in the first echo line? It should be followed by something... Maybe you meant something else? If your script asks for root permissions, you're doing it wrong. Anything unzipped by you, is owned by you. Zip doesn't do owners or permissions. –  lornix Jun 29 '12 at 10:51
    
@lornix I know that chown -r www.www * isn't best practice, but that still doesn't explain the results some users have, and besides changing it would a bit tricky because I can't be sure what files exactly to own (they can change with every new "release" of the archive). And if I download a zip it is owned by the current user, yes, but I can't download it in the first place if the current user doesn't have write access to the current directory.The \c is an escape sequence that makes sure to not do a line break after the echo, it works and is what I wanted. –  half_bit Jun 29 '12 at 12:16
    
Fair enough... How about unzipping contents into a known subdir? That would prevent a tarbomb (archives without a top directory) from doing bad things, then move the contents after you've "processed" it. Never heard of \c doing that, usually it's echo -n "xxx"... but ok. (using -o (overwrite!) in the current subdir is dangerous too, again the known subdir idea would help prevent issues) –  lornix Jun 29 '12 at 12:23
show 1 more comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.