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

Added CPU temperature and Device name for X86 #267

Merged
merged 1 commit into from Oct 24, 2022

Conversation

FauFra
Copy link
Contributor

@FauFra FauFra commented Oct 19, 2022

  • What does this PR aim to accomplish?:

Updated cpu and sys_model variables with more precise files when the script is executed on a X86 machine.


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

  • I have read the above and my PR is ready for review. Check this box to confirm

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

The tests failing for stickler at L290

-f doesn't work with globs. Use a for loop

padd.sh Outdated
@@ -267,7 +269,9 @@ GetSystemInformation() {
fi

# Device model
if [ -f /sys/firmware/devicetree/base/model ]; then
if [ -f /sys/devices/virtual/dmi/id/product_name ]; then
Copy link
Member

Choose a reason for hiding this comment

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

On my system product_family would be the better choice.

chrko@ThinkPad-X230:~$ cat /sys/devices/virtual/dmi/id/product_name 
2325CN3
cat /sys/devices/virtual/dmi/id/product_family 
ThinkPad X230


Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the same file used by applications like neofetch to show the host name. I tried with an MSI and a Mac Mini and product_name and the results are these:

cat /sys/devices/virtual/dmi/id/product_family 
PS
cat /sys/devices/virtual/dmi/id/product_name 
PS63 Modern 8SC

cat /sys/devices/virtual/dmi/id/product_family
Macmini
cat /sys/devices/virtual/dmi/id/product_name
Macmini6,2

While on an Asus laptop the situation is as your:

cat /sys/devices/virtual/dmi/id/product_family
VivoBook
cat /sys/devices/virtual/dmi/id/product_name
X510UQR

So, I thought that a possible solution could be if product_family is a substring of product_name then only the latter is shown, otherwise both the strings are displayed.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if it works also in your system

Copy link
Member

Choose a reason for hiding this comment

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

It works.

chrko@ThinkPad-X230:~$ ./test.sh 
ThinkPad X230 2325CN3

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

Please address the Stickler complains.

padd.sh Outdated
@@ -267,7 +269,9 @@ GetSystemInformation() {
fi

# Device model
if [ -f /sys/firmware/devicetree/base/model ]; then
if [ -f /sys/devices/virtual/dmi/id/product_name ]; then
Copy link
Member

Choose a reason for hiding this comment

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

It works.

chrko@ThinkPad-X230:~$ ./test.sh 
ThinkPad X230 2325CN3

padd.sh Outdated
sys_model="${product_family} ${product_name}"
fi

# sys_model=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_name)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# sys_model=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_name)

@DL6ER
Copy link
Member

DL6ER commented Oct 21, 2022

I can furthermore provide on a small NUC:

d@nuc1:~$ cat /sys/firmware/devicetree/base/model
cat: /sys/firmware/devicetree/base/model: No such file or directory
d@nuc1:~$ cat /sys/devices/virtual/dmi/id/product_name
To Be Filled By O.E.M.
d@nuc1:~$ cat /sys/devices/virtual/dmi/id/product_family
To Be Filled By O.E.M.

On my HP microserver:

d@ubuntu-server:~$ cat /sys/firmware/devicetree/base/model
cat: /sys/firmware/devicetree/base/model: No such file or directory
d@ubuntu-server:~$ cat /sys/devices/virtual/dmi/id/product_name
ProLiant MicroServer
d@ubuntu-server:~$ cat /sys/devices/virtual/dmi/id/product_family

On a new server:

d@ubuntu-server2:~$ cat /sys/firmware/devicetree/base/model
cat: /sys/firmware/devicetree/base/model: No such file or directory
d@ubuntu-server2:~$ cat /sys/devices/virtual/dmi/id/product_name
KRPA-U16 Series
d@ubuntu-server2:~$ cat /sys/devices/virtual/dmi/id/product_family
Server

@FauFra
Copy link
Contributor Author

FauFra commented Oct 21, 2022

Thank you very much, this is helpful! But what happens if you execute a program like neofetch on your NUC server? What is shown near host label?

@yubiuser
Copy link
Member

yubiuser commented Oct 21, 2022

That's interesting. Currently the latest code (v7.1.0) master looks like

            if [[ -d /system/app/ && -d /system/priv-app ]]; then
                model="$(getprop ro.product.brand) $(getprop ro.product.model)"

            elif [[ -f /sys/devices/virtual/dmi/id/board_vendor ||
                    -f /sys/devices/virtual/dmi/id/board_name ]]; then
                model=$(< /sys/devices/virtual/dmi/id/board_vendor)
                model+=" $(< /sys/devices/virtual/dmi/id/board_name)"

            elif [[ -f /sys/devices/virtual/dmi/id/product_name ||
                    -f /sys/devices/virtual/dmi/id/product_version ]]; then
                model=$(< /sys/devices/virtual/dmi/id/product_name)
                model+=" $(< /sys/devices/virtual/dmi/id/product_version)"

            elif [[ -f /sys/firmware/devicetree/base/model ]]; then
                model=$(< /sys/firmware/devicetree/base/model)

            elif [[ -f /tmp/sysinfo/model ]]; then
                model=$(< /tmp/sysinfo/model)
            fi

Producing LENOVO 2325CN3


Using the locally installed version (also v7.1.0) 2325CN3 ThinkPad X230

And the code looks like

            if [[ -d /system/app/ && -d /system/priv-app ]]; then
                model="$(getprop ro.product.brand) $(getprop ro.product.model)"

            elif [[ -f /sys/devices/virtual/dmi/id/product_name ||
                    -f /sys/devices/virtual/dmi/id/product_version ]]; then
                model=$(< /sys/devices/virtual/dmi/id/product_name)
                model+=" $(< /sys/devices/virtual/dmi/id/product_version)"

            elif [[ -f /sys/firmware/devicetree/base/model ]]; then
                model=$(< /sys/firmware/devicetree/base/model)

            elif [[ -f /tmp/sysinfo/model ]]; then
                model=$(< /tmp/sysinfo/model)
            fi

They added it here: dylanaraps/neofetch#1943

The old was more useful I think. We could simply change the order of if cases

@FauFra
Copy link
Contributor Author

FauFra commented Oct 21, 2022

I noticed the same thing. If you download the last release code, it is different from the one in the repo.

However the same logic can be implemented without any problem, but that cleaning string way is not supported in sh. Is there any reason why sh is used instead of bash?

@yubiuser
Copy link
Member

Is there any reason why sh is used instead of bash?

To increase POSIX compliance to make it more portable.


${name/foo/bar} -- you can use $(printf '%s\n' "$name" | sed 's/foo/bar/'), after changing shell patterns to regular expressions. This originated in ksh93 and is also present in mksh, and zsh, but variation in behaviour and glob pattern syntax between the three.

https://mywiki.wooledge.org/Bashism

@FauFra
Copy link
Contributor Author

FauFra commented Oct 21, 2022

Okay, thanks. I will try to implement the same logic and string cleaning then.

@yubiuser
Copy link
Member

Works good for me. Maybe @DL6ER could test on his devices.

padd.sh Outdated
fi

# Cleaning device model from useless OEM information
sys_model=$(echo "$sys_model" | sed -e 's:To be filled by O.E.M.::g')
Copy link
Member

Choose a reason for hiding this comment

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

Stickler test (actually Shellcheck) is complaining here. It is asking to use this variable substituion ${variable//search/replace}, but I'm almost sure this is not POSIX.

You can try to use shell "pattern filtering":

Suggested change
sys_model=$(echo "$sys_model" | sed -e 's:To be filled by O.E.M.::g')
sys_model="${sys_model#"To be filled by O.E.M."}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This is a more elegant way to clean the string.

Copy link
Member

Choose a reason for hiding this comment

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

This only works if the searched string is on the beginning of $sys_model. If you need to remove from the end, use ${sys_model%"To be filled by O.E.M."}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so for each string there must be two filters, one for the beginning and one for the end since there might be the possibility that the value of sys_model is To be filled by O.E.M. To be filled by O.E.M., as shown by @DL6ER

padd.sh Outdated
@@ -279,7 +279,6 @@ GetSystemInformation() {
if [ -z "$sys_model" ]; then
sys_model="${product_family} ${product_name}"
fi
Copy link
Member

Choose a reason for hiding this comment

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

There is one more test failing (if you click on "Details" on the failing test you will be able to see it).

There are trailing spaces here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks. Now it should be fixed.

@yubiuser
Copy link
Member

Tests pass now. Can you please squash down your commits into a single one?

Signed-off-by: FauFra <frasca.fausto@gmail.com>
@FauFra
Copy link
Contributor Author

FauFra commented Oct 23, 2022

Is it okay now?

@yubiuser yubiuser merged commit 6c2429a into pi-hole:development Oct 24, 2022
@yubiuser yubiuser mentioned this pull request Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants