1

Suppose I have tar.bz2 archive, with some directory that has binary file and some assistive files for it.
When user unpack it, he must start binary from within the result directory such a way: ./binary123, but I want this current path to be added to $PATH variable automatically (while unpacking) so the user can do just binary123.

Is there some way to achieve this?

In fact, I need some post-script functionality for archive unpacking..

1 Answer 1

2

No – the '.tar' archive is just a file archive and nothing else. tar is not a package installer; it will not put files in e.g. /usr/bin unless you ask it to literally extract the whole archive there.

In general, it is nowadays considered a security issue if a tool can be tricked into placing files outside the specified destination directory, and paths such as ../../../usr/bin are not allowed by default. (There's an option to allow them in GNU tar, though.)

Also, on many systems, $PATH does not contain any user-writable locations by default – it would have to be modified first (or the installation done as root). There is no generic way to add stuff to $PATH – you'd need to take into account many different shells and login environments, and the user would still need to log out for the changes to apply.

Finally, the ability to add executables to $PATH (or to run post-extraction scripts) just invites abuse. While such an ability would be fully expected from a package manager app (e.g. if you run "npm i -g" or "cabal install"), it would be completely unexpected from a plain old file archiver.

(Most likely, if it had been supported by tar, nobody would be using tar to extract files – they'd be using some alternative "safetar" and you'd just be back to your original problem.)

You should create an actual deb/rpm package. Those are literally meant to be installed into $PATH.

1
  • 1
    In addition to what @user1686 has said here it is nowadays considered a security issue if a tool can be tricked into placing files outside the specified destination directory .. no user1686, this has ALWAYS been the case in Xnix environments.. I remember getting smacked with this lesson by my admin back in the HPUX and IBMAIX days. :) Great response though. JUST DON'T DO IT NK-cell.. even if you can somehow trick the OS into allowing you. This isn't windows and there is a reason that not even . is in the path. Commented Jul 2, 2021 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .