fixup! Add automatic installer and upgrader.
This commit is contained in:
parent
fdffa76cab
commit
51d32de7c5
|
@ -51,8 +51,10 @@ void autoconf_load(const char* path)
|
|||
char* line = NULL;
|
||||
size_t line_size = 0;
|
||||
ssize_t line_length;
|
||||
off_t line_number = 0;
|
||||
while ( 0 < (line_length = getline(&line, &line_size, fp)) )
|
||||
{
|
||||
line_number++;
|
||||
if ( line[line_length - 1] == '\n' )
|
||||
line[--line_length] = '\0';
|
||||
line_length = 0;
|
||||
|
@ -78,7 +80,7 @@ void autoconf_load(const char* path)
|
|||
{
|
||||
char* full;
|
||||
if ( asprintf(&full, "%s\n%s", existing, value) < 0 )
|
||||
err(2, "%s: asprintf", path);
|
||||
err(2, "%s: malloc", path);
|
||||
setenv(name, full, 1);
|
||||
free(full);
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ void autoconf_load(const char* path)
|
|||
{
|
||||
char* full;
|
||||
if ( asprintf(&full, "%s %s", existing, value) < 0 )
|
||||
err(2, "%s: asprintf", path);
|
||||
err(2, "%s: malloc", path);
|
||||
setenv(name, full, 1);
|
||||
free(full);
|
||||
}
|
||||
|
@ -109,10 +111,8 @@ void autoconf_load(const char* path)
|
|||
setenv(name, value, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Graceful.
|
||||
errx(2, "%s: Bad line: %s", path, line);
|
||||
}
|
||||
errx(2, "%s:%ji: Invalid line: %s",
|
||||
path, (intmax_t) line_number, line);
|
||||
char* value = name + name_length;
|
||||
while ( *value && isblank((unsigned char) *value) )
|
||||
value++;
|
||||
|
@ -123,7 +123,6 @@ void autoconf_load(const char* path)
|
|||
value++;
|
||||
name[name_length] = '\0';
|
||||
}
|
||||
// TODO: Graceful error.
|
||||
if ( ferror(fp) )
|
||||
err(2, "%s", path);
|
||||
free(line);
|
||||
|
|
|
@ -175,7 +175,11 @@ void promptx(char* buffer,
|
|||
const char* accept_defaults = autoconf_get("accept_defaults");
|
||||
const char* automatic_answer = NULL;
|
||||
if ( autoconf_value )
|
||||
{
|
||||
automatic_answer = autoconf_value;
|
||||
if ( !automatic_answer[0] )
|
||||
automatic_answer = answer;
|
||||
}
|
||||
else if ( accept_defaults && !strcasecmp(accept_defaults, "yes") )
|
||||
automatic_answer = answer;
|
||||
if ( automatic_answer )
|
||||
|
|
|
@ -438,11 +438,9 @@ int main(void)
|
|||
" installer for %s.\n\n", uts.machine);
|
||||
|
||||
if ( autoconf_get("ready") &&
|
||||
autoconf_get("confirm_install") )
|
||||
(autoconf_get("disked") || autoconf_get("confirm_install")) )
|
||||
{
|
||||
int countdown = 10;
|
||||
// TODO: Is atoi defined on all inputs? Use a larger integer type!
|
||||
// Check for bad input!
|
||||
if ( autoconf_get("countdown") )
|
||||
countdown = atoi(autoconf_get("countdown"));
|
||||
sigset_t old_set;
|
||||
|
@ -654,19 +652,20 @@ int main(void)
|
|||
{
|
||||
prompt(input, sizeof(input), "videomode",
|
||||
"Select a default display resolution? (yes/no)", def);
|
||||
if ( strcasecmp(input, "no") && strcasecmp(input, "yes") )
|
||||
unsigned int xres, yres, bpp;
|
||||
bool set = sscanf(input, "%ux%ux%u", &xres, &yres, &bpp) == 3;
|
||||
if ( !strcasecmp(input, "no") )
|
||||
{
|
||||
input[0] = '\0';
|
||||
break;
|
||||
}
|
||||
const char* r = set ? input : NULL;
|
||||
if ( execute((const char*[]) { "chvideomode", r, NULL }, "f") != 0 )
|
||||
continue;
|
||||
bool was_no = strcasecmp(input, "no") == 0;
|
||||
input[0] = '\0';
|
||||
if ( was_no )
|
||||
break;
|
||||
if ( execute((const char*[]) { "chvideomode", NULL }, "f") != 0 )
|
||||
continue;
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) < 0 )
|
||||
break;
|
||||
if ( !(get_mode.mode.control & DISPMSG_CONTROL_VALID) )
|
||||
break;
|
||||
if ( get_mode.mode.control & DISPMSG_CONTROL_VGA )
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) < 0 ||
|
||||
!(get_mode.mode.control & DISPMSG_CONTROL_VALID) ||
|
||||
get_mode.mode.control & DISPMSG_CONTROL_VGA )
|
||||
break;
|
||||
snprintf(input, sizeof(input), "%ux%ux%u",
|
||||
get_mode.mode.view_xres,
|
||||
|
|
|
@ -376,12 +376,10 @@ int main(void)
|
|||
textf("Hello and welcome to the " BRAND_DISTRIBUTION_NAME " " VERSIONSTR ""
|
||||
" upgrader for %s.\n\n", uts.machine);
|
||||
|
||||
if ( autoconf_get("ready") &&
|
||||
autoconf_get("confirm_install") )
|
||||
if ( autoconf_get("ready") ||
|
||||
autoconf_get("confirm_upgrade") )
|
||||
{
|
||||
int countdown = 10;
|
||||
// TODO: Is atoi defined on all inputs? Use a larger integer type!
|
||||
// Check for bad input!
|
||||
if ( autoconf_get("countdown") )
|
||||
countdown = atoi(autoconf_get("countdown"));
|
||||
sigset_t old_set;
|
||||
|
@ -453,8 +451,7 @@ int main(void)
|
|||
};
|
||||
size_t num_readies = sizeof(readies) / sizeof(readies[0]);
|
||||
const char* ready = readies[arc4random_uniform(num_readies)];
|
||||
if ( autoconf_get("confirm_upgrade") &&
|
||||
!strcasecmp(autoconf_get("confirm_upgrade"), "yes") )
|
||||
if ( autoconf_get("confirm_upgrade") )
|
||||
text("Warning: This upgrader will automatically upgrade an operating "
|
||||
"system!\n");
|
||||
prompt(input, sizeof(input), "ready", "Ready?", ready);
|
||||
|
@ -540,11 +537,14 @@ int main(void)
|
|||
{
|
||||
prompt(input, sizeof(input), "videomode",
|
||||
"Select display resolution? (yes/no)", def);
|
||||
if ( strcasecmp(input, "no") && strcasecmp(input, "yes") )
|
||||
unsigned int xres, yres, bpp;
|
||||
bool set = sscanf(input, "%ux%ux%u", &xres, &yres, &bpp) == 3;
|
||||
if ( !set && strcasecmp(input, "no") && strcasecmp(input, "yes") )
|
||||
continue;
|
||||
if ( strcasecmp(input, "no") == 0 )
|
||||
break;
|
||||
if ( execute((const char*[]) { "chvideomode", NULL }, "f") != 0 )
|
||||
const char* r = set ? input : NULL;
|
||||
if ( execute((const char*[]) { "chvideomode", r, NULL }, "f") != 0 )
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ if [ -n "$autoinstall" ]; then
|
|||
fi
|
||||
|
||||
if [ -n "$autoupgrade" ]; then
|
||||
mkdir -p "-- $directory/etc"
|
||||
mkdir -p -- "$directory/etc"
|
||||
cp -- "$autoupgrade" "$directory/etc/autoupgrade.conf"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue