Question regarding local scripts

Polytropon freebsd at edvax.de
Mon Feb 23 08:58:36 UTC 2015


On Mon, 23 Feb 2015 09:42:30 +0100 (CET), Raimund Sacherer wrote:
> Hello, 
> 
> I am rather new to FreeBSD, putting a couple of new servers in
> production. I read a lot in the manuals, the man hier and googled
> around, but I can't find best practices for storing local
> scripts / apps. 

What do you mean by "local" in relation to apps? Software you
install with the port collection (or via pkg) will be installed
into /usr/local, and this will be recorded (!) by the system's
package system.



> In Debian this part was easy, Debian never touches /usr/local,
> so I had this complete namespace for internal use. 

FreeBSD is different: /usr/local is for locally installed programs,
as the name suggests, and those are managed by the system. In the
"top level" directories only the OS is installed. So when you would
remove /usr/local entirely, the OS would not be affected.



> How to do this in FreeBSD the sane way? 

There are different ways to do this on FreeBSD, but they aren't
standardized. Allow me to mention _one_ example.

The use of the Solarisism /opt is possible. Inside /opt, you
can basically do what you want. /opt/bin is a central "hub"
for scripts and binaries, as well as for symlinks which are
required by programs that reside in, let's say, /opt/foo/program.
You can also have /opt/src for sources, /opt/lib for libraries
and /opt/libexec for daemons; for example, my printer filters
reside there.

Keep in mind the OS does not record anything you do in /opt.
You need to do things manually (like updating stuff), and
even adding paths (like /opt/bin to $PATH).

For things that you wish to be able to use by _one_ user only,
you can put scripts in his ~/bin, and add that to $PATH.

Also consider using version control for your scripts; just
the mandatory sidenote. :-)

But there's probably an easier way: Read the porter's handbook
and create ports for your program or (collections of) scripts
which you can't manage via ports/pkg. It's not that hard, and
there are many advantages over /opt.



> I thought of creating /scripts, but this seems odd, I thought
> of /opt/scripts or /opt/scripts/[s]bin hierarchy, or
> /opt/local/[s]bin hierarchy, but I am not sure how you are
> doing this sort of thing. 

Don't make things more complicated than they need to be. :-)



> I think what I like best would be to recreate a sort of
> /usr/local hierarchy under /opt/local.

You can root the hierarchy directly to /opt, because /opt
does not exist to the system (in a sense of "man hier").

If you place /opt on an individual partition, it's also very
easy to forbid executing (in case of security concerns) by
a simple mount option, or entirely removing access to the
local additions by unmounting it.




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list