简体   繁体   English

以 root 身份获取 Firefox 版本

[英]Get Firefox version as root

I have an installation script that I'd like to run on macOS/Linux.我有一个要在 macOS/Linux 上运行的安装脚本。

Mid-installation, I need to detect the currently installed Firefox version to decide whether or not to use a deprecated feature (ie AutoConfig ) versus a modern feature (ie policies.json ).在安装过程中,我需要检测当前安装的 Firefox 版本来决定是否使用不推荐使用的功能(即AutoConfig )与现代功能(即policies.json )。

  • For Windows, I have logic to parse the Firefox version from the registry.对于 Windows,我有从注册表解析 Firefox 版本的逻辑。 This works fine.这工作正常。
  • On macOS/Linux I want to parse the output of firefox --version however when firefox sees the script running as root it complains:在 macOS/Linux 上,我想解析firefox --version的输出,但是当firefox看到脚本以root身份运行时,它会抱怨:

Running Firefox as root in a regular user's session is not supported.不支持在普通用户的会话中以 root 身份运行 Firefox。 ( $HOME is /Users/foo which is owned by foo .) $HOME/Users/foo拥有的/Users/foo foo 。)

I can use sudo -u $USER firefox --version but this seems like it will have scalability issues with systems that don't have sudo enabled.我可以使用sudo -u $USER firefox --version但这似乎与未启用sudo系统存在可扩展性问题。 Is there another way to get the version without launching the process as a regular user?有没有另一种方法可以在不以普通用户身份启动进程的情况下获取版本? Is there an undocumented override flag?是否有未记录的覆盖标志? I've tried --headless to no avail.我试过--headless无济于事。

It appears the following is a viable workaround for running firefox --version as root.以下似乎是以 root 身份运行firefox --version的可行解决方法。

HOME=/tmp XAUTHORITY=/tmp firefox --version

As far as I know, /tmp should always be owned by root , but if there are exceptions, please propose a better path so that this solution can be improved.据我所知, /tmp应该始终由root拥有,但如果有例外,请提出更好的路径,以便可以改进此解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM