Extend environment file parsing to also parse environment.local

This latter file can be created by the administrator next to the environment
file in order to override parameters set in environment file.
The reason for this is the environment file is always overwritten
during installation, while environment.local is never touched by
the installers. So making the changes in there ensures they persist
acros gnucash updates.
This commit is contained in:
Geert Janssens 2017-08-26 20:42:53 +02:00
parent 2662f4bca3
commit bbea5061a3
2 changed files with 75 additions and 52 deletions

View File

@ -5,10 +5,20 @@
@-NOTE - gnucash-on-windows.git:gnucash.iss don't conflict. -@
# environment
#
# This configuration file can be used to change/add environment variables
# This configuration file defines a number of environment variables to set/alter
# during GnuCash startup.
#
# It uses a very simple syntax for this:
# The contents of this file is overwritten with each gnucash update.
# If you want to add your own variables to the environment or wish
# to override what gets set in this file please create a new file
# named "environment.local" next to this one with the same structure:
#
# [Variables]
# VAR_X=value_x
# ....
#
#
# Both files use a very simple syntax:
# <variable_name>=<variable_value>
#
# You can refer to existing environment variables in the new value by
@ -61,8 +71,8 @@ LD_LIBRARY_PATH={GNC_LIBRARY_PATH};{LD_LIBRARY_PATH}
# The same, but for GnuCash on OS X
DYLD_LIBRARY_PATH={GNC_LIBRARY_PATH};{DYLD_LIBRARY_PATH}
# If you wish GnuCash to use a different language, uncomment the two parameters
# below and set LANG to your preferred locale
# If you wish GnuCash to use a different language, copy the two parameters
# below to environment.local, remove '# ' in front and set LANG to your preferred locale
# LANG=nl_BE
# LANGUAGE={LANG}
@ -71,7 +81,7 @@ DYLD_LIBRARY_PATH={GNC_LIBRARY_PATH};{DYLD_LIBRARY_PATH}
# Linux - follows the freedesktop xdg data home specification
# Windows - uses the user's AppData(Roaming)\GnuCash
# OS X/Quarz - uses the value of NSApplicationSupportDirectory/GnuCash
# If these are not what you want, you can override it here
# If these are not what you want, you can override it in enviromnent.local
# GNC_DATA_HOME=
# Similarly you can override the default location for AqBanking's settings.

View File

@ -96,60 +96,17 @@ static gchar *environment_expand(gchar *param)
return expanded;
}
void
gnc_environment_setup (void)
static void
gnc_environment_parse_one (const gchar *env_path)
{
gchar *config_path;
gchar *env_file;
GKeyFile *keyfile = g_key_file_new();
GError *error = NULL;
gchar **env_vars;
gsize param_count;
gint i;
gboolean got_keyfile;
gchar *env_parm;
/* Export default parameters to the environment */
env_parm = gnc_path_get_prefix();
if (!g_setenv("GNC_HOME", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_HOME.");
g_free (env_parm);
env_parm = gnc_path_get_bindir();
if (!g_setenv("GNC_BIN", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_BIN.");
g_free (env_parm);
env_parm = gnc_path_get_pkglibdir();
if (!g_setenv("GNC_LIB", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_LIB.");
g_free (env_parm);
env_parm = gnc_path_get_pkgdatadir();
if (!g_setenv("GNC_DATA", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_DATA.");
g_free (env_parm);
env_parm = gnc_path_get_pkgsysconfdir();
if (!g_setenv("GNC_CONF", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_CONF.");
g_free (env_parm);
env_parm = gnc_path_get_libdir();
if (!g_setenv("SYS_LIB", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable SYS_LIB.");
g_free (env_parm);
config_path = gnc_path_get_pkgsysconfdir();
#ifdef G_OS_WIN32
{
/* unhide files without extension */
gchar *pathext = g_build_path(";", ".", g_getenv("PATHEXT"),
(gchar*) NULL);
g_setenv("PATHEXT", pathext, TRUE);
g_free(pathext);
}
#endif
env_file = g_build_filename (config_path, "environment", NULL);
got_keyfile = g_key_file_load_from_file (keyfile, env_file, G_KEY_FILE_NONE, &error);
g_free (config_path);
g_free (env_file);
got_keyfile = g_key_file_load_from_file (keyfile, env_path, G_KEY_FILE_NONE, &error);
if ( !got_keyfile )
{
g_key_file_free(keyfile);
@ -195,7 +152,7 @@ gnc_environment_setup (void)
if (!g_setenv (env_vars[i], new_val, TRUE))
g_warning ("Couldn't properly override environment variable \"%s\". "
"This may lead to unexpected results", env_vars[i]);
"This may lead to unexpected results", env_vars[i]);
g_free(new_val);
}
}
@ -203,3 +160,59 @@ gnc_environment_setup (void)
g_strfreev(env_vars);
g_key_file_free(keyfile);
}
void
gnc_environment_setup (void)
{
gchar *config_path;
gchar *env_path;
gchar *env_parm;
/* Export default parameters to the environment */
env_parm = gnc_path_get_prefix();
if (!g_setenv("GNC_HOME", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_HOME.");
g_free (env_parm);
env_parm = gnc_path_get_bindir();
if (!g_setenv("GNC_BIN", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_BIN.");
g_free (env_parm);
env_parm = gnc_path_get_pkglibdir();
if (!g_setenv("GNC_LIB", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_LIB.");
g_free (env_parm);
env_parm = gnc_path_get_pkgdatadir();
if (!g_setenv("GNC_DATA", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_DATA.");
g_free (env_parm);
env_parm = gnc_path_get_pkgsysconfdir();
if (!g_setenv("GNC_CONF", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable GNC_CONF.");
g_free (env_parm);
env_parm = gnc_path_get_libdir();
if (!g_setenv("SYS_LIB", env_parm, FALSE))
g_warning ("Couldn't set/override environment variable SYS_LIB.");
g_free (env_parm);
config_path = gnc_path_get_pkgsysconfdir();
#ifdef G_OS_WIN32
{
/* unhide files without extension */
gchar *pathext = g_build_path(";", ".", g_getenv("PATHEXT"),
(gchar*) NULL);
g_setenv("PATHEXT", pathext, TRUE);
g_free(pathext);
}
#endif
/* Parse the environment file that got installed with gnucash */
env_path = g_build_filename (config_path, "environment", NULL);
gnc_environment_parse_one(env_path);
g_free (env_path);
/* Parse local overrides for this file */
env_path = g_build_filename (config_path, "environment.local", NULL);
gnc_environment_parse_one(env_path);
g_free (env_path);
g_free (config_path);
}