[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [solved] Xfce: Toggle CPUfreq scaling by the panel - Was: Re: Xfce: 2 + 1 questions



Hi Lorenzo :)

- PyGTK gksu (I don't know this, since I'm not a Py coder)
- PolicyKit (I never set it up myself)
- set SUID bit for /usr/bin/cpufreq-set (I did this a long time a go:
  spinymouse-sudo@64studio:~$ sudo -i
  root@64studio:~# chmod u+s /usr/bin/cpufreq-selector
  This was before PolicyKit was available and it resulted in a security
  discussion at 64 Studio users mailing list in 2009.)

My shell script simply enables to use any frontend for su, the default
is set to use gksu.

- Ralf

PS: I'll download your app and test it ASAP, anyway, my shell script
already is used for my Xfce panel, it's working (for Xfce user sessions
and it should work with any other WM/DE). If wanted, it also is able to
'remember' the chosen scaling for startup.
Btw. I was a Commodore 64 assembler audio and MIDI coder. I'm not a
shell script writer. Documentations about programming shell scripts for
Linux are odd, since first hits by Google just inform about some
options, hence my shell script might be ugly code, but it seems to be
not buggy. Today I would program some parts in a different way, but I
keep the script as I programmed it yesterday. Works like a charm here.
  

On Thu, 2011-11-24 at 09:01 +0100, Lorenzo Sutton wrote:
> Hey Ralf,
> 
> On 23/11/11 23:03, Ralf Mardorf wrote:
> > On Sat, 2011-11-19 at 14:12 +0100, Ralf Mardorf wrote:
> >> On Sat, 2011-11-19 at 12:09 +0200, Andrei Popescu wrote:
> >>> On Vi, 18 nov 11, 21:44:39, Ralf Mardorf wrote:
> >>>>
> >>>> It's supported by the plugin, but it doesn't work.
> >>>
> >>> If the plugin has the frequency switching controls, but they don't do
> >>> anything please report a bug (if not already reported).
> >>
> >> To http://www.debian.org/Bugs/ and/or https://bugzilla.xfce.org/ ?
> >> [snip]
> >
> > Hi :)
> >
> > I didn't file a bugreport, since it looks like it should be able to set
> > the governor, but the menus should simply show available governors.
> >
> > Instead I wrote a script that e.g. can be used for a launcher. Each time
> > you click the launcher, the governor for the CPU frequency scaling will
> > be toggled from one to another.
> 
> I think we had the same idea, but I thought of a small pyGtk 
> notification area gui. Basically a kind of standalone clone of the gnome 
> plugin...
> 
> I set up un gitorious:
> 
> https://gitorious.org/gcputray
> 
> (or simply get the tar.gz of the current master:
> https://gitorious.org/gcputray/gcputray/archive-tarball/master )
> 
> Only problem is that you have to run it as root. Actually any suggestion 
> on how to wisely set it up for user would be welcome
> 
> Lorenzo.
> 
> >
> > E.g. right click the Xfce panel>  Panel>  Add New Items...>  Mark
> > "Launcher">  + Add>  Close>
> > Right click the launcher icon>  Move it, if wanted>  Right click again>
> > Properties>  Tab: General>  Click the icon for "Add a new empty
> > item" (or later "Edit the currently selected item")>
> >
> > Name:    CPUfreq-GOVtoggle
> > Comment: Toggle CPU frequency scaling governor
> > Command: cpufreq-govtoggle
> > Icon:    Application icons/xfce4-cpufrq-plugin or
> >           Application icons/gnome-cpu-frequency-applet
> >
> >> Create or Save
> >
> > You might use the freq monitoring plugin without an icon and move the
> > launcher, showing the icon only, in front of it.
> >
> > Have fun,
> >
> > Ralf
> >
> > This is the script, read the comments how to install it:
> >
> >
> > #!/bin/sh
> >
> >
> > # Install and uninstall
> >
> > # First copy the shell script to /usr/local/bin
> > # To initialize everything that's needed to use this script as user run
> > # su -lc "sh /usr/local/bin/cpufreq-govtoggle --init"
> >
> > # To undo changes as user run
> > # su -lc "sh /usr/local/bin/cpufreq-govtoggle --undo"
> >
> >
> > # Usage
> >
> > # E.g. by a panel launcher, as user run
> > # cpufreq-govtoggle
> >
> >
> > # 2011-Nov-23 ralf.mardorf@alice-dsl.net
> >
> >
> > SU_FRONTEND=gksu
> > EDITOR=gedit
> >
> > CPUFREQ_SET=/usr/bin/cpufreq-set
> > CPUFREQ_INFO=/usr/bin/cpufreq-info
> > CPUFREQ_UTILS=/etc/init.d/cpufrequtils
> > CPUFREQ_UTILS_BAK=/etc/cpufreq-govtoggle/cpufrequtils~
> >
> > GOVERNOR_O=ondemand
> > GOVERNOR_P=performance
> >
> > INIT_TEXT="The cpufreq-govtoggle shell script contains two variables.
> > \nLine 31
> > \nGOVERNOR_O=ondemand
> > \nLine 32
> > \nGOVERNOR_P=performance
> > \nInstead of \"ondemand\" and \"performance\" you can edit it to any
> > \nother value, the script should toggle.
> > \n
> > \nThe script also set a link to a script that contains a variable for
> > \nthe governor during startup.
> > \nIf you set the governor to the variable GOVERNOR_O, at startup the
> > \nscript cpufrequtilo is used, if you set it to
> > \nGOVERNOR_P, the script cpufrequtilp is used.
> > \nBy default line 43 for both scripts is
> > \nGOVERNOR=\"ondemand\"
> > \nYou can keep both scripts at \"ondemand\" or edit them to any value.
> > \n
> > \n
> > \nPush any key to start the editor."
> >
> > keyboard_entry()
> > {
> >   stty raw -echo
> >   dd count=1 bs=1 2>/dev/null
> >   stty -raw echo
> > }
> >
> > if [ -z $1 ] ; then
> >
> >   ## CPU frequency scaling governor toggle ##
> >
> >   CHAR=`$CPUFREQ_INFO -p | awk '{print $3}'`
> >   if [ $CHAR = $GOVERNOR_P ] ; then
> >    $SU_FRONTEND -u root "$CPUFREQ_SET -g $GOVERNOR_O"
> >    if [ -e /etc/cpufreq-govtoggle/cpufrequtilo ] ; then
> >     $SU_FRONTEND rm $CPUFREQ_UTILS
> >     $SU_FRONTEND ln /etc/cpufreq-govtoggle/cpufrequtilo $CPUFREQ_UTILS
> >    fi
> >   else
> >    $SU_FRONTEND -u root "$CPUFREQ_SET -g $GOVERNOR_P"
> >    if [ -e /etc/cpufreq-govtoggle/cpufrequtilp ] ; then
> >     $SU_FRONTEND rm $CPUFREQ_UTILS
> >     $SU_FRONTEND ln /etc/cpufreq-govtoggle/cpufrequtilp $CPUFREQ_UTILS
> >    fi
> >   fi
> >   exit 0
> > elif [ -z $2 ] ; then
> >
> >   ## Init ##
> >
> >   if [ $1 = "--init" ] ; then
> >    if [ -e /etc/cpufreq-govtoggle/cpufrequtilo ] ; then
> >     echo "$0: /etc/cpufreq-govtoggle/cpufrequtilo already existing"
> >     exit 1
> >    else
> >     clear
> >     echo "If a file is missing install the package providing it\n"
> >     F=0
> >     if [ -e $CPUFREQ_SET ] ; then : ; else
> >      echo "$0: cannot access $CPUFREQ_SET: No such file"
> >      F=1
> >     fi
> >     if [ -e $CPUFREQ_INFO ] ; then : ; else
> >      echo "$0: cannot access $CPUFREQ_INFO: No such file"
> >      F=1
> >     fi
> >     if [ -e $CPUFREQ_UTILS ] ; then : ; else
> >      echo "$0: cannot access $CPUFREQ_UTILS: No such file"
> >      F=1
> >     fi
> >     if [ $F = 1 ] ; then
> >      exit 1
> >     fi
> >     echo "No file is missing"
> >     echo -n "Push any key to continue"
> >     CHAR=`keyboard_entry`
> >     mkdir /etc/cpufreq-govtoggle
> >     cp -p $CPUFREQ_UTILS $CPUFREQ_UTILS_BAK
> >     mv $CPUFREQ_UTILS /etc/cpufreq-govtoggle/cpufrequtilo
> >     ln /etc/cpufreq-govtoggle/cpufrequtilo $CPUFREQ_UTILS
> >     cp -p /etc/cpufreq-govtoggle/cpufrequtilo\
> >           /etc/cpufreq-govtoggle/cpufrequtilp
> >     clear ; echo $INIT_TEXT
> >     echo -n "Step 1 of 3, edit, save&  close or just close cpufrequtilo"
> >     CHAR=`keyboard_entry`
> >     $EDITOR /etc/cpufreq-govtoggle/cpufrequtilo
> >     clear ; echo $INIT_TEXT
> >     echo -n "Step 2 of 3, edit, save&  close or just close cpufrequtilp"
> >     CHAR=`keyboard_entry`
> >     $EDITOR /etc/cpufreq-govtoggle/cpufrequtilp
> >     clear ; echo $INIT_TEXT
> >     echo -n "Edit, save&  close or just close cpufreq-govtoggle"
> >     CHAR=`keyboard_entry`
> >     $EDITOR /usr/local/bin/cpufreq-govtoggle
> >     chmod 755 /usr/local/bin/cpufreq-govtoggle
> >     clear ; echo "Done"
> >     exit 0
> >    fi
> >
> >   ## Undo ##
> >
> >   elif [ $1 = "--undo" ] ; then
> >    if [ -e $CPUFREQ_UTILS_BAK ] ; then : ; else
> >     echo "$0: cannot access $CPUFREQ_UTILS_BAK: No such file"
> >     exit 1
> >    fi
> >    rm $CPUFREQ_UTILS
> >    cp -p $CPUFREQ_UTILS_BAK $CPUFREQ_UTILS
> >    chmod 644 /usr/local/bin/cpufreq-govtoggle
> >    rm -r /etc/cpufreq-govtoggle
> >    exit 0
> >   fi
> > fi
> >   echo "$0: unrecognized option"
> > exit 1


Reply to: