【问题标题】:apt-get environment variables when spawning "debian rules" file生成“debian 规则”文件时 apt-get 环境变量
【发布时间】:2010-02-05 15:52:44
【问题描述】:

在 Ubuntu 下安装软件包期间,apt-get 生成时,debian/rules(通常是 make)可以使用哪些环境变量?

我特别关注与 Gnome 的配置目录相关的环境变量。我想避免像~/.conf/apps/ ... 这样的“硬编码”内容,因为我被告知这些内容可能会像他们倾向于...

我一直在疯狂地搜索!

【问题讨论】:

  • 您在寻找 XDG_CONFIG_HOME 和相关的吗? freedesktop.org/wiki/Specifications/basedir-spec 虽然在安装包时触摸任何主目录似乎都不合适。特别要注意 XDG_CONFIG_HOME 不必存在,在这种情况下假定 ~/.config 的值。
  • @Roger Pate:这实际上是你的评论我想要的答案:-)

标签: linux ubuntu makefile debian apt-get


【解决方案1】:

您在寻找 XDG_CONFIG_HOME 和 related 吗?特别要注意 XDG_CONFIG_HOME 不必存在,在这种情况下假定 ~/.config 的值。

Python 示例

import os
from os import path

app_name = "my_app"
home_config = path.join(
  os.environ.get("XDG_CONFIG_HOME") or path.expanduser("~/.config"),
  app_name,
)

print "User-specific config:", home_config

C++ 示例

#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>

std::string get_home_config(std::string const& app_name) {
  // also look at boost's filesystem library
  using namespace std;
  string home_config;
  char const* xdg_config_home = getenv("XDG_CONFIG_HOME");
  if (xdg_config_home && xdg_config_home[0] != '\0') {
    home_config = xdg_config_home;
  }
  else {
    if (char const* home = getenv("HOME")) {
      home_config = home;
      home_config += "/.config";
    }
    else throw std::runtime_error("HOME not set");
  }
  home_config += "/";
  home_config += app_name;
  return home_config;
}

int main() try {
  std::cout << "User-specific config: " << get_home_config("my_app") << '\n';
  return 0;
}
catch (std::exception& e) {
  std::clog << e.what() << std::endl;
  return 1;
}

【讨论】:

    【解决方案2】:

    debian/rules 在包构建时被调用(源包或二进制包)它确实apt-get 期间被调用。

    事实上,.deb 文件(==二进制包)不再包含 debian/rules 的副本。该文件仅在源包中。

    此外,包通常不应尝试为特定用户做事,或利用用户的配置。 Debian 软件包适用于在系统范围内安装的软件。

    虽然理论上可以制作个人包,在/home 中安装一些东西,但这样的包的价值非常有限。

    【讨论】:

      猜你喜欢
      • 2013-01-28
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 2014-06-10
      相关资源
      最近更新 更多