apt-get environment variables when spawning "debian rules" file
What are the environment variables made available to debian/rules
(often make
) when spawned by apt-get
during installation of a package under Ubuntu?
I am specifically after the environment variables that would pertain to Gnome's configuration directories. I'd like avoiding开发者_开发百科 "hardcoding" things like ~/.conf/apps/ ...
since I have been told these might change like they tend to...
I've been googling like crazy!
Are you looking for the XDG_CONFIG_HOME and related? In particular, note that XDG_CONFIG_HOME doesn't have to exist, and a value of ~/.config is assumed in that case.
Python example
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++ example
#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;
}
debian/rules
gets invoked at package build time (either the source or binary package) It does not get called during apt-get
.
In fact, the .deb file (==binary package), does not contain a copy of debian/rules anymore. That file is only in the source package.
Furthermore, packages should normally not try to do things for a particular user, or make use of the configuration of a user. Debian packages are intended for software that is installed system-wide.
Although it's theoretically possible to make a personal package that installs something in /home, such a package is of very limited value.
精彩评论