Using apt-file
I am able to find the packages providing certain executables like this for example:
sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/wget
Well actually:
sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/wget | grep "/wget$"
(Because otherwise it would just return all packages containing executables starting with wget
.)
Now I was running:
EXEC_NAME="x86_64-w64-mingw32-g++"
sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/${EXEC_NAME} | grep "${EXEC_NAME}$"
And surprisingly it doesn't return anything. Why? Because no package provides a file with that name.
If I run:
EXEC_NAME="x86_64-w64-mingw32-g++"
sudo apt-file search {/bin,/sbin,/usr/bin/,/usr/sbin}/${EXEC_NAME}
I get the following result:
g++-mingw-w64-x86-64-posix: /usr/bin/x86_64-w64-mingw32-g++-posix
g++-mingw-w64-x86-64-win32: /usr/bin/x86_64-w64-mingw32-g++-win32
implying there is no package providing x86_64-w64-mingw32-g++
.
But after a while I found that g++-mingw-w64-x86-64-posix
doesn't just provide the executable g++-mingw-w64-x86-64-posix
, but also an alias or symlink called g++-mingw-w64-x86-64
.
In this case it was easy to figure out because the package happened to contain another binary with a very similar name. Now my issue is that I need to automate this in a way that works for any alias/symlink, even for ones that have a completely different name.
How can I do this?
Edit:
The alias is created in the file g++-mingw-w64-x86-64-posix.postinst
of the g++-mingw-w64-x86-64-posix
package, in case that helps:
update-alternatives --install /usr/bin/x86_64-w64-mingw32-g++ x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix 30 \
--slave /usr/bin/x86_64-w64-mingw32-c++ x86_64-w64-mingw32-c++ /usr/bin/x86_64-w64-mingw32-c++-posix
Edit2:
Is there maybe a way to search the file content of all packages' .postinst
files? Maybe by downloading all .postinst
files into a cache? Maybe that could be done by downloading the file header of each package first to see at which bytes in the archives the .postinst files are located and then use HTTP range requests to download them?
Edit3:
This doesn't change anything, but I found instead of grep and cut, you can just use the -x
and the -l
flag. This makes the command a bit shorter:
sudo apt-file search -l -x "^/(bin|sbin|usr/bin|usr/sbin)/${EXEC_NAME}$" | head -1
If you download
dwww
with the commandyou can use dwww-quickfind, one of its sub-packages, in order to, well, quickly find it. The following is from the dwww man-page:
Just to test out the interface, from the terminal, ran it for 10 - 15 commands, some GNU, others not, without issue. For example, when I ran
and the result was
It obviously follows symlinks, so I would guess that it tracks aliases as well. Either way, It is worth a shot. Even if it doesn't, just getting
dwww
is worth the trouble. Typedwww <any-pkg>
and you will understand.It is like the
man
command on steroids.The problem with symlinks is they aren't necessarily installed by packages.
You can use
readlink -f [/path/file]
to (try to) get the path to the real file. If/path/file
is a symlink,readlink
will return the file that the symlink points to. If there is a chain of symlinks,readlink
will follow them until it gets to a break in the chain or the real file.Then you can use
apt-file
to search for the packages.