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