我们在本地Apt仓库(reprepro)中有一些手工构build的(带有fpm和jenkins).deb文件。 这些.debs文件包含一个.desktop文件,该文件将被xdg-desktop在post-inst脚本中拾取。
如果我们手工安装deb文件,在一个新的系统上,一切都很好。
如果我们使用apt-get install安装新版本,我们会得到这个错误
xdg-desktop-menu: file '/usr/local/share/applications/customthingy.desktop' does not exist
如果我用apt-get install -d customthingy下载deb文件,然后运行
dpkg -i /var/cache/apt/archives/customthingy_2-r3_all.deb
我得到了和以前一样的xdg-desktop错误。 这样就排除了apt的问题。
如果我列出下载的deb的内容,
tom.oconnor@charcoal-black:~$ dpkg --contents /var/cache/apt/archives/customthingy_2-r3_all.deb |grep ".desktop" -rw-r--r-- root/root 201 2011-07-28 20:02 ./usr/local/share/applications/customthingy.desktop
你可以看到文件存在。
但是,如果我们在重新安装前清除,
tom.oconnor@charcoal-black:~$ sudo apt-get purge customthingy Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED customthingy* 0 upgraded, 0 newly installed, 1 to remove and 84 not upgraded. After this operation, 0B of additional disk space will be used. Do you want to continue [Y/n]? y (Reading database ... 219342 files and directories currently installed.) Removing customthingy ... Purging configuration files for customthingy ...
接着
tom.oconnor@charcoal-black:~$ sudo apt-get install customthingy Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed customthingy 0 upgraded, 1 newly installed, 0 to remove and 84 not upgraded. Need to get 0B/4,030B of archives. After this operation, 0B of additional disk space will be used. Selecting previously deselected package customthingy. (Reading database ... 219319 files and directories currently installed.) Unpacking customthingy (from .../customthingy_2-r3_all.deb) ... Setting up customthingy (2-r3) ...
编辑:Postinst脚本的内容
#!/bin/sh # Add an entry to the system menu XDG_DESKTOP_MENU="`which xdg-desktop-menu 2> /dev/null`" if [ ! -x "$XDG_DESKTOP_MENU" ]; then echo "WARNING: Could not find xdg-desktop-menu" >&2 else "$XDG_DESKTOP_MENU" install --mode system /usr/local/share/applications/customthingy.desktop "$XDG_DESKTOP_MENU" forceupdate --mode system fi
没有错误。 所以..问题是这些:
我猜你的postinst正在调用xdg-desktop-menu将桌面文件移动到/usr/share/applications并更新XDG桌面数据库。 这是通过例如google-chrome-stable ,但我不明白为什么(阅读)
如果您将桌面文件直接安装到/usr/share/applications (通过dpkg – 也就是通过dh_install将文件放在那里,例如.deb中的path只是/usr/share/applications )包的数量会自动“触发”更新:特别是gnome-menus和desktop-file-utils ,但也许还有其他的(取决于精确的目标操作系统版本等)
至less在我的情况下,这些足以实现手动运行xdg-desktop-menu所做的事情(程序会立即显示在我的用户菜单中)
至于为什么google-chrome-stable和其他(主要是第三方) .deb将桌面文件发送到除/usr/share/applications (在Chrome中为/opt ),然后将其移动用手。
它是调用“xdg-desktop-menu –uninstall”的罪魁祸首,即
"$XDG_DESKTOP_MENU" uninstall --mode system /usr/local/share/applications/customthingy.desktop
这会在postd调用xdg-desktop-menu尝试使用它之前删除.desktop文件。 非常好。
谈到google-chrome debs,他们还在他们的prerm脚本的顶部包括了这个节:
action="$1" if [ "$2" = "in-favour" ]; then # Treat conflict remove as an upgrade. action="upgrade" fi # Don't clean-up just for an upgrade.` if [ "$action" = "upgrade" ] ; then exit 0 fi
这是一个严肃的方法来解决这个问题,但似乎是在这里(和伟大的Goog太过诡计)。
保罗