Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Reliable way to invoke apt-get #192

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

guekho64
Copy link
Contributor

@guekho64 guekho64 commented Mar 23, 2021

Why?

This PR attempts to cover an edge case which might occur here if an user attempts to use aptitude (or any other custom package manager) in apt-fast.conf, by overriding "${_APTMGR}", while being in an environment which prioritizes /usr/local/bin over /usr/bin in "${PATH}", with a symlink from e.g. /usr/local/bin/aptitude -> /usr/bin/apt.fast.

Trying to invoke apt-fast with this setup would cause apt-fast to call himself.

Is this necessary?

Although such environment would seem extremely unusual at first, taking a closer look to your "${PATH}" might reveal that, in fact, you could be using a similar configuration without even knowing (Like i discovered); also, if we take into account that apt-fast.conf actually allows "${_APTMGR}" to be overridden, than means that we'd just need to also create a symlink like the one above described to trigger this edge case.

So? What's the idea?

The idea behind this PR it's quite simple: We just need to make sure that we're calling /usr/bin/apt-get whenever we call for apt-get.

This can be achieved in many ways
  • We could simply go ahead and replace each apt-get occurence within apt-fast with /usr/bin/apt-get
  • Or we could store /usr/bin/apt-get into a variable, and replace each apt-get occurence with "${var}" [Currently in use]
  • Or we could use whereis command, from utils-linux package to do something like this
    whereis_APT=($(whereis -b 'apt-get')) # apt-get: /usr/bin/apt-get
    real_APT="${whereis_APT[1]}"
    echo "${real_APT}" # /usr/bin/apt-get

Are there any drawbacks?

Strictly talking, there could be a few:

Option 1

This option would end up adding a lot of hardcoded lines into apt-fast

Option 2

This option requires an additional variable to store apt-get fullpath, and just one hardcoded line.

Option 3

This option requires (at least) an additional variable to store apt-get fullpath, and adding another dependency: utils-linux package.

After a little research, seems systemd package depends on utils-linux, so that means utils-linux comes preinstalled, at least in Ubuntu (Debian's systemd doesn't seem to share that dependency)

Final notes

As always, If I made some mistake, or if you have any suggestion, it's always welcome.

@Lasall
Copy link
Collaborator

Lasall commented Mar 25, 2021

Can you rebase it against the current master please, so the actual changes are easily viewable?

@Lasall
Copy link
Collaborator

Lasall commented Mar 25, 2021

I didn't know about the whereis command. It looks nice an avoids hardcoding paths. It can be assumed installed on Debian systems using apt-fast as it is a dependency for mount (which is a dependency for systemd).

So I placed an exec file in /usr/local/bin/apt-get and the whereas output is:
apt-get: /usr/bin/apt-get /usr/local/bin/apt-get

How is the order of the output?

Copy link
Collaborator

@Lasall Lasall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase :)

@guekho64 guekho64 marked this pull request as draft March 25, 2021 21:54
@guekho64
Copy link
Contributor Author

So I placed an exec file in /usr/local/bin/apt-get and the whereas output is:
apt-get: /usr/bin/apt-get /usr/local/bin/apt-get

How is the order of the output?

It seems whereis has its own list of paths where it searches by default, and following that strict order

-l Output the list of effective lookup paths that whereis is using.
When none of -B, -M, or -S is specified, the option will output
the hard-coded paths that the command was able to find on the
system.

Manual page whereis(1) line 52

For instance, invoking whereis -l on my system returns this output:

Large text ahead

bin: /usr/bin
bin: /usr/sbin
bin: /bin
bin: /sbin
bin: /lib/x86_64-linux-gnu
bin: /usr/lib/x86_64-linux-gnu
bin: /usr/lib
bin: /etc
bin: /lib
bin: /lib64
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games
bin: /usr/include
bin: /usr/local
bin: /usr/libexec
bin: /usr/share
man: /usr/share/man/de
man: /usr/share/man/es
man: /usr/share/man/fr
man: /usr/share/man/ja
man: /usr/share/man/man8
man: /usr/share/man/pl
man: /usr/share/man/ru
man: /usr/share/man/man1
man: /usr/share/man/man7
man: /usr/share/man/it
man: /usr/share/man/sl
man: /usr/share/man/man5
man: /usr/share/man/nl
man: /usr/share/man/sv
man: /usr/share/man/man3
man: /usr/share/man/cs
man: /usr/share/man/da
man: /usr/share/man/fi
man: /usr/share/man/hu
man: /usr/share/man/id
man: /usr/share/man/ko
man: /usr/share/man/tr
man: /usr/share/man/zh_CN
man: /usr/share/man/zh_TW
man: /usr/share/man/pt_BR
man: /usr/share/man/pt
man: /usr/share/man/fr.ISO8859-1
man: /usr/share/man/fr.UTF-8
man: /usr/share/man/sr
man: /usr/share/man/man4
man: /usr/share/man/hr
man: /usr/share/info
src: /usr/src/linux-headers-5.4.0-65-generic
src: /usr/src/linux-headers-5.4.0-65
src: /usr/src/r8168-8.048.00
src: /usr/src/linux-hwe-5.8-headers-5.8.0-45
src: /usr/src/linux-headers-5.8.0-45-lowlatency
src: /usr/src/nvidia-450.102.04
src: /usr/src/linux-headers-5.8.0-45-generic
src: /usr/src/linux-hwe-5.8-headers-5.8.0-48
src: /usr/src/linux-headers-5.8.0-48-generic
src: /usr/src/linux-headers-5.8.0-48-lowlatency

Additionally, I also tried to confuse whereis by creating two fake apt-get's, placing one into /usr/local/bin, and the other one inside /usr/sbin.

Invoking whereis 'apt-get' one more time outputs this:

apt-get: /usr/bin/apt-get /usr/sbin/apt-get /usr/local/bin/apt-get /usr/share/man/man8/apt-get.8.gz

Based on my output from whereis -l, I'd say that binaries are simply sorted by directory, depending on the output of whereis -l

@guekho64
Copy link
Contributor Author

BTW, I marked this PR as a draft temporarily, since I've been a bit stressed out lately, and I accidentaly messed up something when trying to rebase. 🤦‍♂️ (facepalm)

I'll fix it in the next few days; in the meantime, we can continue analyzing the idea behind my PR.

Repository owner deleted a comment Oct 28, 2022
Repository owner deleted a comment Dec 8, 2022
Repository owner locked as spam and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants