.desktop 文件中的 pkexec 命令

np_*_*3ka 13 command-line .desktop pkexec

我为 Androxyde 的 Flashtool(索尼 Xperia 设备的实用程序,我必须使用其文件夹中的可执行文件打开)制作了一个 .desktop 文件,该文件需要 root 权限才能使用 fastboot 实用程序。我曾经让它与 一起工作gksu,但我使用的是 Ubuntu 15.04,而 gksu 现在已经过时了。

我试图修改exec

Exec=gksu /home/natasha/FlashTool/FlashTool
Run Code Online (Sandbox Code Playgroud)
Exec=pkexec /home/natasha/FlashTool/FlashTool
Run Code Online (Sandbox Code Playgroud) 然后,我读到 pkexec 不允许运行 X11 应用程序,因此我以这种方式覆盖:

在此处输入图片说明

链接到 Imgur.com 上的完整图像

现在的问题是:它询问我密码但 Flashtool 的 GUI 没有启动。但是,如果我在终端中执行该命令,程序将毫无问题地启动。我能做什么?

在此处输入图片说明

链接到 Imgur.com 上的完整图像

A.B*_*.B. 10

在中创建一个新文件 /usr/share/polkit-1/actions/

sudo nano /usr/share/polkit-1/actions/FlashTool.policy
Run Code Online (Sandbox Code Playgroud)

并添加以下行:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

<policyconfig>

  <action id="org.freedesktop.policykit.pkexec.run-FlashTool">
    <description>Run FlashTool</description>
    <message>Authentication is required to run FlashTool</message>
    <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/home/natasha/FlashTool/FlashTool</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
  </action>

</policyconfig>
Run Code Online (Sandbox Code Playgroud)

然后新建一个文件 /home/natasha/FlashTool/

nano /home/natasha/FlashTool/flashtool-pkexec
Run Code Online (Sandbox Code Playgroud)

并添加以下行:

#!/bin/sh
pkexec "/home/natasha/FlashTool/FlashTool" "$@"
Run Code Online (Sandbox Code Playgroud)

Exec在您的desktop文件中使用以下行:

Exec=/home/natasha/FlashTool/flashtool-pkexec
Run Code Online (Sandbox Code Playgroud)

经测试我的系统上的Ubuntu 15.04 GNOME与以下文件:


$ cat /usr/share/applications/gedit.root.desktop 
[Desktop Entry]
Name=Gedit as root
GenericName=Text Editor
X-GNOME-FullName=
Comment=
Exec=gedit-pkexec
Icon=gedit
Terminal=false
Type=Application
Categories=GNOME;System;Filesystem;Settings;
StartupNotify=true
X-Ubuntu-Gettext-Domain=gedit

$ cat /usr/share/polkit-1/actions/gedit.policy 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

<policyconfig>

  <action id="org.freedesktop.policykit.pkexec.run-FlashTool">
    <description>Run FlashTool</description>
    <message>Authentication is required to run FlashTool</message>
    <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/gedit</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
  </action>

</policyconfig>

$ cat /usr/bin/gedit-pkexec 
#!/bin/sh
pkexec "gedit" "$@"
Run Code Online (Sandbox Code Playgroud)