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

Usage without admin password #3

Open
auipga opened this issue May 31, 2021 · 2 comments
Open

Usage without admin password #3

auipga opened this issue May 31, 2021 · 2 comments

Comments

@auipga
Copy link
Contributor

auipga commented May 31, 2021

Assuming that your user is in the wheel group, maybe* this could work:

sudo visudo -f /etc/sudoers.d/smbios-thermal-ctl

then paste

%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl -i
%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl -g

%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl --set-thermal-mode=balanced
%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl --set-thermal-mode=cool-bottom
%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl --set-thermal-mode=quiet
%wheel ALL= NOPASSWD: /usr/bin/smbios-thermal-ctl --set-thermal-mode=performance

Adjustments for 'pkexec' may also be needed.

*I can't try because of Error: Tried to construct an object without a GType on gnome-shell 40.1

@auipga
Copy link
Contributor Author

auipga commented May 31, 2021

After getting the extension to work (by reading paradoxxxzero/gnome-shell-system-monitor-applet@ffeb78f) and a few stackexchanges I found out, that sudo isn't the right way.

The next thing to try is policies, which might require a separate script (a wrapper to previous listed commands) and a setup

@auipga
Copy link
Contributor Author

auipga commented Jun 3, 2021

wrapper script to allow only actions, we want to support (maybe this is not necessary)

/usr/local/bin/thermalmode

#!/usr/bin/env bash

if [ -z "$1" ] ; then
  echo "Usage:"
  echo "  thermalmode get"
  echo "  thermalmode list"
  echo "  thermalmode <mode>"
  exit 0
fi


if [ "$1" = "get" ] ; then
  output=$(smbios-thermal-ctl -g)

  #  ...
  # Current Thermal Modes:
  #          Quiet
  #  ...

  # @todo: do some awk: the line after "Current Thermal Modes:", trim spaces, kebab-case
  mode=$(echo "$output" | sed -n 7p)

  echo "$mode"
  exit 0
fi


#output=$(smbios-thermal-ctl -i)

#  ...
#  Supported Thermal Modes:
#         Balanced
#         Cool Bottom
#         Quiet
#         Performance
#  ...

# @todo: do required awk
# @todo: convert to kebab-case
#supported_thermal_modes= $output -> awk -> kebab-case -> array
supported_thermal_modes=(balanced cool-bottom quiet performance)


if [ "$1" = "list" ] ; then
  echo "Supported thermal modes:"
  for mode in "${supported_thermal_modes[@]}"; do
    echo " ${mode}"
  done
  exit 0
fi


# set_thermal_mode
mode="$1"
for i in "${supported_thermal_modes[@]}"
do
    if [ "$i" = "$mode" ] ; then
      smbios-thermal-ctl --set-thermal-mode $mode #1>> /dev/null
      echo "set-thermal-mode ${mode}"
      exit 0
    fi
done

echo "unsupported parameter."
exit 1

I think this wrapper is needed because the sudoers file in the initial post is not really save. (Parameters could be combined to potentially do sth. else than we want)

Now allow to execute:

chmod +x /usr/local/bin/thermalmode
sudo visudo -f /etc/sudoers.d/thermalmode
## paste (without '#')
# %wheel ALL= NOPASSWD: /usr/local/bin/thermalmode

After that I replaced

["pkexec"].concat(["smbios-thermal-ctl", "--set-thermal-mode", mode]),

with

["thermalmode"].concat([mode]),

in extension.js. Result: It works.

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

No branches or pull requests

1 participant