Checking on whether or not the system has a battery is not reliable - a UPS connected to the system may show up as a battery (which showed up when I checked).
So one way is to use dmidecode to get the chassis type of the system:
dmidecode --string chassis-type
But this command requires sudo. To avoid using sudo, you can print the contents of /sys/class/dmi/id/chassis_type, which will return the decimal value of the chassis type.
cat /sys/class/dmi/id/chassis_type
But when I checked, both of the commands gave output where my desktop was considered as "Rack Mount Chassis" (decimal value 23) and my laptop as "Notebook" (decimal value 10). So it might vary according to the system that we are handling.
That's when I used the hostnamectl command and got better values from the Chassis and Icon name:
hostnamectl status | grep Chassis | cut -f2 -d ":" | tr -d ' '
Since my desktop machine didn't have any Chassis option, I used the Icon name value:
hostnamectl status | grep "Icon name" | cut -f2 -d ":" | tr -d ' '
So on my laptop the result was "computer-laptop", on desktop it's just "computer" and on my server, it is "computer-vm". You can use these values to install the tlp on the system.
latop-detect -v. The output wasWe're a laptop (non device ACPI battries found). – user68186 May 31 '24 at 15:52laptop-detectand see which command is the one that gives this result. I presume it isif ( grep -q Battery $sysfs_power_supply/$power_supply/type 2>/dev/null ) && ( ! grep -q Device $sysfs_power_supply/$power_supply/scope 2>/dev/null ). – FedKad May 31 '24 at 16:07grep -q Device /sys/class/power_supply/BAT0/scopefails with no such file or directory and that results in the output. – user68186 May 31 '24 at 20:55dmidecodeis more accurate: runninghostnamectlanddmidecodeon an Intel NUC, the first reports "desktop" while the second reports "Mini PC"; I mean they're both fair takes, butdmidecodejust nails it. – kos Jun 01 '24 at 12:32hostnamectl chassisreturnsUnknown operation chassis.Instead,hostnamectl status | grep Chassiscan be used, givingChassis: desktop(just noticed Matt said something similar, not deleting because of the use or grep to sort it out). adding| cut -d ":" -f 2may be helpful – Chris H Jun 03 '24 at 09:54