FrameworkComputer / linux-docs

Linux Markdown Guides
108 stars 20 forks source link

Instructions don't select the OEM kernel properly -- because `ls` is aliased on my system! #17

Closed greyhare closed 8 months ago

greyhare commented 8 months ago

Just a note for (crazy) people like me who have the ls command set to an alias in bash.

The symptom is that it's still using the 6.2 kernels from the -generic kernel package. And you'll notice that latest_oem_kernel is blank.

The solution is to, in each of the big "paste this blob into bash" blocks of code in the instructions, change ls to command ls, which tells it to ignore the alias. It's in several places; don't miss any.

Another solution is to undefine the alias, if that's the only thing between you and the raw ls command.

Anyway, I'm not sure how to patch this into the docs, or if it's even worth it, but at least this should get picked up by Google so others don't lose a weekend like I did.

JohnAZoidberg commented 8 months ago

What did you alias ls to? Any reasonable ls replacement should act the same when provided with no args, for example exa.

We could change it from ls to find:

zoid@fw13:~$ ls /boot/vmlinuz-*
/boot/vmlinuz-6.0.2-76060002-generic  /boot/vmlinuz-6.0.6-76060006-generic
zoid@fw13:~$ find /boot/vmlinuz-*
/boot/vmlinuz-6.0.2-76060002-generic
/boot/vmlinuz-6.0.6-76060006-generic
zoid@fw13:~$ echo $(find /boot/vmlinuz-* | awk -F"-" '{split($0, a, "-"); version=a[3]; if (version>max) {max=version; kernel=a[2] "-" a[3] "-" a[4]}} END{print kernel}')
6.0.6-76060006-generic
greyhare commented 8 months ago

Derp, sorry, it's not an alias, it's a function:

$ type ls
ls is a function
ls () 
{ 
    command ls -lqF "$@" | ${PAGER}
}

The thing is that a user should be able to mess things up in their ~/.bashrc like this, because we do. I confess I'm lazy and don't like typing out the flags and pager command.

We could change it from ls to find:

In that last command, it's still ls. That said I think you could use find's -name predicate to do a more precise filtering for only OEM kernels, too. (e.g. find /boot -name 'vmlinuz-.*-oem')

I'm not certain why you do both -F"-" and split($0, a, "-"); it would seem you could drop the split and replace a[3] with $4, etc.

I'm in the middle of actually getting the Ryzen mobo into my laptop, and can try this after I'm done.

zachfeldman commented 8 months ago

Certainly a matter of opinion, but I think it's totally justified for a shell script to assume that ls will work as advertised. This is @ctsdownloads 's domain, but maybe he'd consider a pull request to modify the script in case someone didn't? Otherwise like you said, this issue should help with others' googling @greyhare !

JohnAZoidberg commented 8 months ago

In that last command, it's still ls. That said I think you could use find's -name predicate to do a more precise filtering for only OEM kernels, too. (e.g. find /boot -name 'vmlinuz-.*-oem')

Whoops, copy paste error. It actually does work with find /boot/vmlinuz-*, not because of find but because of shell expansion. So echo /boot/vmlinuz-* will work just fine in this case.

greyhare commented 8 months ago

echo won't work because it would put everything on one line and awk wouldn't work.

Looking over some things, the industry standard (and best security) way around this seems to be to just use the full path to the binary, i.e. /bin/ls. This avoids functions and aliases as well as "bad guy" programs inserted in the $PATH.

ctsdownloads commented 8 months ago

Hi @greyhare, I appreciate your perspective.

Just a note for (crazy) people like me who have the ls command set to an alias in bash.

The script block assumes this is a default install. On something customized where you have an alias for a common use command like ls, then using the advanced method will be the best course.

The solution is to, in each of the big "paste this blob into bash" blocks of code in the instructions, change ls to command ls, which tells it to ignore the alias. It's in several places; don't miss any.

Another solution is to undefine the alias, if that's the only thing between you and the raw ls command.

The block of code is used on a fresh installation, as a newbie friendly to make things "just work" - when following the guide, you'd setup any customization after running through the steps - not before.

If the customization (alias) was setup and imported into the new install before the script is run, you'll want to use the advanced method.

You are of course, welcome and encouraged to create a fork of this vetted script to run in a manner that better meets your needs. We'll happily take a look at it. But the existing script is battle tested (I use it at least 4 times daily for the sake of speed), so redoing it will not be something we're focused on at this time.

If you need additional support for this, please open a support ticket and I would be happy to help.

greyhare commented 8 months ago

It may have been written assuming a fresh install, but I was directed to it as a series of steps I must complete before upgrading my one-year-old Framework 13's motherboard from Intel 12th Gen to AMD Ryzen.

Just working with what I've got.