Permalink
Browse files

Added "setenv" for bools, to export values to the environment.

  • Loading branch information...
megastep committed Mar 31, 2006
1 parent 7bb7ceb commit 69c4d0fded91a39f4ca4df8e61020c899f46d4e9
Showing with 49 additions and 20 deletions.
  1. +5 −0 README.xml
  2. +18 −12 bools.c
  3. +6 −2 bools.h
  4. +20 −6 install.c
View
@@ -369,6 +369,11 @@ Additionally, one of the following attributes must be used, unless "if" below is
The value must be a non-zero number to map to be TRUE. If the variable is not
set in the environment, the boolean will likewise be set to FALSE.
setenv The name of an environment variable that will be set with the value of the boolean
when running user scripts throughout the installer. The value of that variable will
be 0 or 1. This can be used for advanced scripting querying the internal state of
the installer.
It also recognizes two optional attributes :
later If set to "yes", the script will be executed at the time that the condition
View
30 bools.c
@@ -1,4 +1,4 @@
/* $Id: bools.c,v 1.1 2006-03-29 23:38:28 megastep Exp $ */
/* $Id: bools.c,v 1.2 2006-03-31 01:29:02 megastep Exp $ */
/*
Manage global installer booleans.
@@ -32,15 +32,18 @@ struct _setup_expression
struct _setup_expression *list, *next;
};
setup_bool *setup_booleans = NULL;
static install_info *cur_info = NULL;
static setup_bool *booleans = NULL, *setup_false = NULL, *setup_true = NULL;
static setup_bool *setup_false = NULL, *setup_true = NULL;
/* Fill up with standard booleans */
void setup_init_bools(install_info *info)
{
char buf[80];
cur_info = info;
setup_booleans = NULL;
/* Basic bools */
setup_true = setup_add_bool("true", 1);
@@ -81,8 +84,8 @@ setup_bool *setup_new_bool(const char *name)
if ( ret ) {
memset(ret, 0, sizeof(*ret));
ret->name = strdup(name);
ret->next = booleans;
booleans = ret;
ret->next = setup_booleans;
setup_booleans = ret;
}
return ret;
}
@@ -92,6 +95,7 @@ void setup_free_bool(setup_bool *b)
if (b) {
free(b->name);
free(b->script);
free(b->envvar);
free(b);
}
}
@@ -110,21 +114,23 @@ setup_bool *setup_find_bool(const char *name)
{
setup_bool *ret;
for ( ret = booleans; ret; ret = ret->next ) {
for ( ret = setup_booleans; ret; ret = ret->next ) {
if ( !strcmp(ret->name, name) ) {
return ret;
}
}
return NULL;
}
int setup_get_bool(const setup_bool *b)
int setup_get_bool(setup_bool *b)
{
if ( b ) {
if ( b->once ) {
return b->inited ? b->value : 0;
} else if (b->script) { /* Run the script to determine the value */
return (run_script(cur_info, b->script, 0, 0) == 0);
b->value = (run_script(cur_info, b->script, 0, 0) == 0);
b->inited = 1; /* Keep track of the last value */
return b->value;
}
}
return 0;
@@ -348,11 +354,11 @@ int match_condition(const char *expr)
void setup_exit_bools(void)
{
setup_bool *b;
while ( booleans ) {
b = booleans->next;
setup_free_bool(booleans);
booleans = b;
while ( setup_booleans ) {
b = setup_booleans->next;
setup_free_bool(setup_booleans);
setup_booleans = b;
}
cur_info = NULL;
booleans = NULL;
setup_booleans = NULL;
}
View
@@ -1,4 +1,4 @@
/* $Id: bools.h,v 1.1 2006-03-29 23:38:28 megastep Exp $ */
/* $Id: bools.h,v 1.2 2006-03-31 01:29:02 megastep Exp $ */
/*
Manage global installer booleans.
@@ -13,6 +13,7 @@
typedef struct _setup_bool {
char *name; /* Symbolic name */
char *script; /* A script to be run to determine the value, or NULL */
char *envvar; /* An environment variable to set with the value, if any */
unsigned value : 1; /* Boolean value */
unsigned once : 1; /* Whether the script has to be run every time the bool is evaluated, or just upon init */
unsigned inited : 1; /* Value was filled in */
@@ -24,6 +25,9 @@ typedef struct _setup_bool {
struct _setup_expression;
typedef struct _setup_expression setup_expression;
/* Exported list of booleans */
extern setup_bool *setup_booleans;
/**** API functions *******/
@@ -39,7 +43,7 @@ setup_bool *setup_add_bool(const char *name, unsigned value);
/* Manipulate booleans */
setup_bool *setup_find_bool(const char *name);
int setup_get_bool(const setup_bool *b);
int setup_get_bool(setup_bool *b);
void setup_set_bool(setup_bool *b, unsigned value);
View
@@ -1,4 +1,4 @@
/* $Id: install.c,v 1.171 2006-03-30 01:53:52 megastep Exp $ */
/* $Id: install.c,v 1.172 2006-03-31 01:29:02 megastep Exp $ */
/* Modifications by Borland/Inprise Corp.:
04/10/2000: Added code to expand ~ in a default path immediately after
@@ -616,20 +616,22 @@ const char *GetProductREADME(install_info *info, int *keepdirs)
int GetProductBooleans(install_info *info)
{
xmlNodePtr node;
char *name, *script, *later, *envvar, *cond;
char *name, *script, *later, *envvar, *envto, *cond;
int count = 0;
setup_bool *b = NULL;
for(node = XML_CHILDREN(XML_ROOT(info->config)); node; node = node->next) {
if(! strcmp((char *)node->name, "bool") ) {
name = (char *)xmlGetProp(node, BAD_CAST "name");
script = (char *)xmlGetProp(node, BAD_CAST "script");
later = (char *)xmlGetProp(node, BAD_CAST "later");
envvar = (char *)xmlGetProp(node, BAD_CAST "env");
envto = (char *)xmlGetProp(node, BAD_CAST "setenv");
cond = (char *)xmlGetProp(node, BAD_CAST "if");
if ( match_condition(cond) ) {
if ( script ) {
setup_bool *b = setup_new_bool(name);
b = setup_new_bool(name);
if ( b ) {
count ++;
b->script = strdup(script);
@@ -645,7 +647,7 @@ int GetProductBooleans(install_info *info)
log_fatal(_("Failed to allocate new bool"));
}
} else if ( envvar ) {
setup_bool *b = setup_new_bool(name);
b = setup_new_bool(name);
if ( b ) {
char *env = getenv(envvar);
@@ -659,18 +661,21 @@ int GetProductBooleans(install_info *info)
log_debug("New environment bool: %s = %s (from %s)", name, b->value ? "TRUE" : "FALSE", envvar);
}
} else if ( cond ) { /* We matched the condition - if all else fails, create the bool */
setup_add_bool(name, 1);
b = setup_add_bool(name, 1);
} else {
log_warning(_("Must have at least 'script' or 'env' attribute for <bool>"));
}
} else {
setup_add_bool(name, 0);
b = setup_add_bool(name, 0);
log_debug("New bool '%s' set to FALSE because of condition '%s'", name, cond);
}
if ( b && envto )
b->envvar = strdup(envto);
xmlFree(name);
xmlFree(script);
xmlFree(later);
xmlFree(envvar);
xmlFree(envto);
xmlFree(cond);
}
}
@@ -2939,6 +2944,8 @@ int run_script(install_info *info, const char *script, int arg, int include_tags
fp = fdopen(fd, "w");
if ( fp ) {
setup_bool *b;
fprintf(fp, /* Create script file, setting environment variables */
"#!/bin/sh\n"
"SETUP_PRODUCTNAME=\"%s\"\n"
@@ -2961,6 +2968,13 @@ int run_script(install_info *info, const char *script, int arg, int include_tags
"SETUP_OPTIONTAGS=\"%s\"\n"
"export SETUP_OPTIONTAGS\n",
get_optiontags_string(info));
/* Set boolean environment variables */
for ( b = setup_booleans; b; b = b->next ) {
if (b->envvar && b->inited) { /* We are NOT running scripts at this point */
fprintf(fp,"%s=%d; export %s\n", b->envvar, b->value, b->envvar);
}
}
/* Append script itself */
fprintf(fp, "%s%s\n",
working_dir, script);

0 comments on commit 69c4d0f

Please sign in to comment.