diff --git a/README.md b/README.md index ec333f3..18628cf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # argos-indicator-nvidia-prime Gnome Shell Indicator for NVidia Prime, using Argos API + + +####Installation +Install [Argos](https://extensions.gnome.org/extension/1176/argos/) Gnome-Shell extension. + +Create directory `~/.local/share/icons` if it does not exist: +``` +! [ -d "~/.local/share/icons" ] && mkdir --parents ~/.local/share/icons || true +``` + +Then: +``` +git clone https://github.com/cyberalex4life/argos-indicator-nvidia-prime.git +cd argos-indicator-nvidia-prime +cp -v icons/* ~/.local/share/icons/ +cp -v nvidia-prime.r.2s.sh ~/.config/argos/ +sudo cp org.freedesktop.policykit.pkexec.prime-select.policy /usr/share/polkit-1/actions/ +sudo cp pkroot /usr/local/bin/ +``` +**Note!** +Furthure info to be added soon... diff --git a/icons/nvidia-active-symbolic.svg b/icons/nvidia-active-symbolic.svg new file mode 100644 index 0000000..f868df9 --- /dev/null +++ b/icons/nvidia-active-symbolic.svg @@ -0,0 +1,102 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/icons/nvidia-inactive-symbolic.svg b/icons/nvidia-inactive-symbolic.svg new file mode 100644 index 0000000..19c9b1d --- /dev/null +++ b/icons/nvidia-inactive-symbolic.svg @@ -0,0 +1,108 @@ + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/icons/prime-indicator-intel-symbolic.svg b/icons/prime-indicator-intel-symbolic.svg new file mode 100644 index 0000000..25a3952 --- /dev/null +++ b/icons/prime-indicator-intel-symbolic.svg @@ -0,0 +1,81 @@ + + + + + + image/svg+xml + + + + + + + + + + + ® + + diff --git a/icons/prime-indicator-intel.svg b/icons/prime-indicator-intel.svg new file mode 100644 index 0000000..c5e7286 --- /dev/null +++ b/icons/prime-indicator-intel.svg @@ -0,0 +1,81 @@ + + + + + + image/svg+xml + + + + + + + + + + + ® + + diff --git a/icons/prime-indicator-nvidia-symbolic.svg b/icons/prime-indicator-nvidia-symbolic.svg new file mode 100644 index 0000000..06c31df --- /dev/null +++ b/icons/prime-indicator-nvidia-symbolic.svg @@ -0,0 +1,63 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/icons/prime-indicator-nvidia.svg b/icons/prime-indicator-nvidia.svg new file mode 100644 index 0000000..04f87e8 --- /dev/null +++ b/icons/prime-indicator-nvidia.svg @@ -0,0 +1,63 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/nvidia-prime.r.2s.sh b/nvidia-prime.r.2s.sh new file mode 100755 index 0000000..06b1a7c --- /dev/null +++ b/nvidia-prime.r.2s.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +run_as_root="pkroot -d" # gksu; pkroot; gnomesu -c; +this_script_path="$HOME/.config/argos/""$(basename "$0")" + +activate_intel="\"$run_as_root \\\"prime-select intel\\\"; $this_script_path\"" +activate_nvidia="\"$run_as_root \\\"prime-select nvidia\\\"; $this_script_path\"" + +activate_intel_and_logout="\"$run_as_root \\\"prime-select intel\\\" && sleep 1 && gnome-session-quit --logout --no-prompt; $this_script_path\"" +activate_nvidia_and_logout="\"$run_as_root \\\"prime-select nvidia\\\" && sleep 1 && gnome-session-quit --logout --no-prompt; $this_script_path\"" + +logout_cmd="\"gnome-session-quit --logout --no-prompt\"" + +nvidia_settings="\"nvidia-settings -p 'PRIME Profiles'; $this_script_path\"" +nvidia_active_icon="nvidia-active-symbolic" +nvidia_inactive_icon="nvidia-inactive-symbolic" +logout_icon="system-log-out" + + +QUERY=$(prime-select query) +if [ "$QUERY" == 'nvidia' ]; then + nvidia_state_icon=$nvidia_active_icon + TEMP=$(nvidia-smi -q -d TEMPERATURE | grep 'GPU Current Temp' | awk '{print $5}') + panel_string="$TEMP\xe2\x84\x83 | " +else + nvidia_state_icon=$nvidia_inactive_icon + panel_string=" | " +fi + +echo -e "$panel_string""iconName=$nvidia_state_icon" +echo "---" +echo "NVIDIA PRIME Profiles| iconName=$nvidia_state_icon bash=$nvidia_settings terminal=false" +echo "---" +echo "Switch to INTEL | iconName='prime-indicator-intel' bash=$activate_intel terminal=false" +echo "Switch to NVIDIA | iconName='prime-indicator-nvidia' bash=$activate_nvidia terminal=false" +echo "---" +echo "Switch to INTEL :: Log Out | iconName='prime-indicator-intel' bash=$activate_intel_and_logout terminal=false" +echo "Switch to NVIDIA :: Log Out | iconName='prime-indicator-nvidia' bash=$activate_nvidia_and_logout terminal=false" +echo "---" +echo "Log Out | iconName=$logout_icon bash=$logout_cmd terminal=false" diff --git a/org.freedesktop.policykit.pkexec.prime-select.policy b/org.freedesktop.policykit.pkexec.prime-select.policy new file mode 100644 index 0000000..b870f9e --- /dev/null +++ b/org.freedesktop.policykit.pkexec.prime-select.policy @@ -0,0 +1,27 @@ + + + + + + Alexandru-Catalin Petrini + https://github.com/cyberalex4life/ + + + + + Execute 'prime-select' without password. Put this in '/usr/share/polkit-1/actions' + + Authentication to run 'prime-select' as root. + + yes + yes + yes + + + /usr/bin/prime-select + + TRUE + + + diff --git a/pkroot b/pkroot new file mode 100755 index 0000000..15437bf --- /dev/null +++ b/pkroot @@ -0,0 +1,48 @@ +#! /bin/bash + +# pkroot +# +# wrapper for 'pkexec runwithpkexec' +# +# Copyright (C) 2018 Alexandru-Catalin Petrini (alexandru.c.petrini@gmail.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. + +# This program is distributed in the hope that it will be useful,# # # +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +# 'pkexec' must be passed the exact path location of 'runwithpkexec' +# as mentioned in 'org.freedesktop.policykit.pkexec.runwithpkexec.policy' file +# and 'runwithpkexec' must actually be placed in this location for pkroot +# to work properly. +runwithpkexec_path="/opt/scripts/runwithpkexec" +print_help() { + printf " \n %-5s\n\n" "Help: " + printf " %10s %-40s %-10s\n" "" "pkroot -h --help" "Show help" + printf " %10s %-40s %-10s\n" "" "pkroot [command]" "Run command requesting passwording" + printf " %10s %-40s %-10s\n" "" "pkroot \"[command1];[command2];..\"" "Run multiple commands (as one) requesting passwording" + printf " %10s %-40s %-10s\n" "" "pkroot '[command1];[command2];..'" "Run multiple commands (as one) requesting passwording" + printf " %10s %-40s %-10s\n" "" "pkroot -d [command]" "Run command directly, where command is passed directly to pkexec." + printf " %10s %-40s %-10s\n" "" "" "Usefull to bypass \"Refusing to render service to dead parents.\"," + printf " %10s %-40s %-10s\n" "" "" "when trying to run a process in the background, which pkexec does not allow." + printf " %10s %-40s %-10s\n" "" "" "Process needs it's own policy file which decides if pkexec runs process as root," + printf " %10s %-40s %-10s\n" "" "" "asking for password or without password" +} +arg1="$1" +args="$@" +if [ "$arg1" == "-h" -o "$arg1" == "--help" ]; then + print_help + exit 0 +elif [ "$arg1" == "-d" -o "$arg1" == "--directly" ]; then + args=${args//$arg1/} + pkexec $args + exit 0 +fi +pkexec $runwithpkexec_path "$@" diff --git a/screenshots/argos-nvidia-prime1.jpg b/screenshots/argos-nvidia-prime1.jpg new file mode 100644 index 0000000..ed1db41 Binary files /dev/null and b/screenshots/argos-nvidia-prime1.jpg differ diff --git a/screenshots/argos-nvidia-prime2.jpg b/screenshots/argos-nvidia-prime2.jpg new file mode 100644 index 0000000..91430db Binary files /dev/null and b/screenshots/argos-nvidia-prime2.jpg differ