What does /usr/sbin/install really do?
Asked Answered
B

1

6

I'm trying to install discount on my VPS which is based on Solaris and compiling works great after setting some environment variables but the install fails.

So I thought I'd do the install manually, but what does install really do? Is it simply a mv followed by a chmod? Is it magic? That error seems to show that it attempts to do a lot of searching for files all over?

Can I just copy the binary, library and header files as usual?

Googling "install" doesn't give me much relevant information so I appreciate any clarification I can get!

Brakeman answered 10/2, 2011 at 16:19 Comment(0)
M
8

According to man install:

install [OPTION]... [-T] SOURCE DEST`  
install [OPTION]... SOURCE... DIRECTORY  
install [OPTION]... -t DIRECTORY SOURCE...  
install [OPTION]... -d DIRECTORY...  

In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to the existing DIRECTORY, while setting permission modes and owner/group. In the 4th form, create all components of the given DIRECTORY(ies).

As for the difference to using cp, according to install vs. cp; and mmap, install unlinks the existing file, creating a new one linked to the same spot.

This has the advantage that, if the file you're trying to overwrite is a currently running program, it can continue running, as the file being written is in fact in a new location, and the existing program code is still in the old one.

A cp simply tries to overwrite the existing file, which will fail if the file is locked due to being in use.

Further information

Marjie answered 10/2, 2011 at 16:25 Comment(3)
Yes, well that's how to use it. But what does it really do? Like, behind the scenes. If it only copies a file, why wouldn't the Makefile just use cp?Sadesadella
I just added a link to install vs. cp; and mmap, which may answer your questions about that.Poppo
So install is basically a work-around for the fact that BSD doesn't support GNU's cp --remove-destination.Sew

© 2022 - 2024 — McMap. All rights reserved.