Skip to content

Commit

Permalink
Makes the hardware info file root owned
Browse files Browse the repository at this point in the history
  • Loading branch information
ribalba committed Nov 8, 2023
1 parent 553e305 commit 131e210
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ PWD=$(pwd)
echo "ALL ALL=(ALL) NOPASSWD:/usr/bin/env python3 $PWD/lib/hardware_info_root.py" | sudo tee /etc/sudoers.d/green_coding_hardware_info

print_message "Setting the hardare hardware_info to be owned by root"
sudo cp -f $PWD/lib/hardware_info_root_original.py $PWD/lib/hardware_info_root.py
sudo chown root:root $PWD/lib/hardware_info_root.py
sudo chmod 755 $PWD/lib/hardware_info_root.py

Expand Down
26 changes: 26 additions & 0 deletions lib/hardware_info_root_original.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'''There are some values we need to get as root. So there are two scripts one is `hardware_info.py` which is included
in the main program and the `get_values` method is called. Unfortunately there is no way to get root in a safe way. So
we have split out the values we can get without being root and then we call this script from the main program with
sudo. This is why the output is json and not a nice representation as it needs to be machine readable.
'''

import json
import platform
from hardware_info import rdr, get_values

root_info_list = [
[rdr, 'CPU scheduling', '/sys/kernel/debug/sched'],
]

def get_root_list():
if platform.system() == 'Darwin':
return []

return root_info_list


if __name__ == '__main__':
if platform.system() == 'Darwin':
print('{}')
else:
print(json.dumps(get_values(get_root_list())))

0 comments on commit 131e210

Please sign in to comment.