SHARE
TWEET

Untitled

a guest Feb 8th, 2012 1,321 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # By: Bresiyel 1-28-2012
  3. # Adds programs to polkit for gui view
  4. progAdd=$1
  5. progLoc=$(echo `whereis "$progAdd" | awk '{print $2}'`)
  6.  
  7. verify(){
  8. if [ "$progAdd" == "" ];
  9. then
  10.    echo "Program usage: poladd program"
  11.    exit 1
  12. fi
  13. if [ "$progLoc" == "" ];
  14. then
  15.    echo "Did not find $progAdd"
  16.    exit 1
  17. elif [ `echo $progLoc | grep bin` == "" ];
  18. then
  19.    echo "Found location $progLoc, however this may not be valid..."
  20.    echo "Exiting..."
  21.    exit 1
  22. fi
  23. exists
  24. return
  25. }
  26. exists(){
  27. alreadyHere=$(cat /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy | grep "$progAdd")
  28. if [ "$alreadyHere" != "" ];
  29. then
  30.    echo "This program is already configured."
  31.    exit 1
  32. fi
  33. return
  34. }
  35. addProgram(){
  36. if [ -e /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy ];
  37. then
  38.    sudo cp -f /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy ~/org.freedesktop.policykit.pkexec.policy.backup
  39.    cat /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy | sed 's_</policyconfig>__' | sudo tee /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy
  40.    echo "  <action id=\"org.freedesktop.policykit.pkexec."$progAdd"\">
  41.    <description>Run "$progAdd"</description>
  42.    <message>Authentication is required to run "$progAdd"</message>
  43.    <defaults>
  44.      <allow_any>auth_admin</allow_any>
  45.      <allow_inactive>auth_admin</allow_inactive>
  46.      <allow_active>auth_admin</allow_active>
  47.    </defaults>
  48.    <annotate key=\"org.freedesktop.policykit.exec.path\">"$progLoc"</annotate>
  49.    <annotate key=\"org.freedesktop.policykit.exec.allow_gui\">true</annotate>
  50.  </action>
  51.  
  52. </policyconfig>" | sudo tee -a /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy
  53. fi
  54. return
  55. }
  56.  
  57. verify
  58. addProgram
  59. exit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top