Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
2021-01-18 18:04:56 -05:00
|
|
|
* Copyright (c) 2016, 2018, 2020, 2021 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* sysmerge.c
|
|
|
|
* Upgrade current operating system from a sysroot.
|
|
|
|
*/
|
2016-02-18 16:16:02 -05:00
|
|
|
|
2018-07-14 16:34:48 -04:00
|
|
|
#include <sys/stat.h>
|
2016-02-18 16:16:02 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2021-01-15 15:12:56 -05:00
|
|
|
#include <ctype.h>
|
2016-02-18 16:16:02 -05:00
|
|
|
#include <err.h>
|
2016-04-08 17:09:38 -04:00
|
|
|
#include <errno.h>
|
2021-01-18 18:04:56 -05:00
|
|
|
#include <fcntl.h>
|
2016-02-18 16:16:02 -05:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-01-15 15:12:56 -05:00
|
|
|
#include <termios.h>
|
2016-02-18 16:16:02 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "conf.h"
|
|
|
|
#include "execute.h"
|
2016-08-22 18:28:49 -04:00
|
|
|
#include "hooks.h"
|
2016-02-18 16:16:02 -05:00
|
|
|
#include "fileops.h"
|
|
|
|
#include "manifest.h"
|
|
|
|
#include "release.h"
|
|
|
|
|
2021-01-15 15:12:56 -05:00
|
|
|
static char* atcgetblob(int fd, const char* name, size_t* size_ptr)
|
|
|
|
{
|
|
|
|
ssize_t size = tcgetblob(fd, name, NULL, 0);
|
|
|
|
if ( size < 0 )
|
|
|
|
return NULL;
|
|
|
|
char* result = (char*) malloc((size_t) size + 1);
|
|
|
|
if ( !result )
|
|
|
|
return NULL;
|
|
|
|
ssize_t second_size = tcgetblob(fd, name, result, (size_t) size);
|
|
|
|
if ( second_size != size )
|
|
|
|
return free(result), (char*) NULL;
|
|
|
|
result[(size_t) size] = '\0';
|
|
|
|
if ( size_ptr )
|
|
|
|
*size_ptr = (size_t) size;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_partition_name(const char* path)
|
|
|
|
{
|
|
|
|
const char* name = path;
|
|
|
|
for ( size_t i = 0; path[i]; i++ )
|
|
|
|
if ( path[i] == '/' )
|
|
|
|
name = path + i + 1;
|
|
|
|
if ( !isalpha((unsigned char) *name) )
|
|
|
|
return false;
|
|
|
|
name++;
|
|
|
|
while ( isalpha((unsigned char) *name) )
|
|
|
|
name++;
|
|
|
|
if ( !isdigit((unsigned char) *name) )
|
|
|
|
return false;
|
|
|
|
name++;
|
|
|
|
while ( isdigit((unsigned char) *name) )
|
|
|
|
name++;
|
|
|
|
if ( *name != 'p' )
|
|
|
|
return false;
|
|
|
|
name++;
|
|
|
|
if ( !isdigit((unsigned char) *name) )
|
|
|
|
return false;
|
|
|
|
name++;
|
|
|
|
while ( isdigit((unsigned char) *name) )
|
|
|
|
name++;
|
|
|
|
return *name == '\0';
|
|
|
|
}
|
|
|
|
|
2016-02-18 16:16:02 -05:00
|
|
|
static void compact_arguments(int* argc, char*** argv)
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < *argc; i++ )
|
|
|
|
{
|
|
|
|
while ( i < *argc && !(*argv)[i] )
|
|
|
|
{
|
|
|
|
for ( int n = i; n < *argc; n++ )
|
|
|
|
(*argv)[n] = (*argv)[n+1];
|
|
|
|
(*argc)--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool has_pending_upgrade(void)
|
|
|
|
{
|
|
|
|
return access_or_die("/boot/sortix.bin.sysmerge.orig", F_OK) == 0 ||
|
|
|
|
access_or_die("/boot/sortix.initrd.sysmerge.orig", F_OK) == 0 ||
|
|
|
|
access_or_die("/sysmerge", F_OK) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
setvbuf(stdout, NULL, _IOLBF, 0); // Pipes.
|
|
|
|
|
|
|
|
bool booting = false;
|
2016-08-22 18:28:49 -04:00
|
|
|
bool cancel = false;
|
2021-01-18 18:04:56 -05:00
|
|
|
bool full = false;
|
2016-08-22 18:28:49 -04:00
|
|
|
bool hook_finalize = false;
|
|
|
|
bool hook_prepare = false;
|
2016-02-18 16:16:02 -05:00
|
|
|
bool wait = false;
|
|
|
|
|
|
|
|
for ( int i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
const char* arg = argv[i];
|
|
|
|
if ( arg[0] != '-' || !arg[1] )
|
|
|
|
continue;
|
|
|
|
argv[i] = NULL;
|
|
|
|
if ( !strcmp(arg, "--") )
|
|
|
|
break;
|
|
|
|
if ( arg[1] != '-' )
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
while ( (c = *++arg) ) switch ( c )
|
|
|
|
{
|
2020-12-27 16:34:20 -05:00
|
|
|
case 'c': cancel = true; break;
|
2021-01-18 18:04:56 -05:00
|
|
|
case 'f': full = true; break;
|
2016-02-18 16:16:02 -05:00
|
|
|
case 'w': wait = true; break;
|
|
|
|
default:
|
2021-01-15 15:12:56 -05:00
|
|
|
errx(1, "unknown option -- '%c'", c);
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( !strcmp(arg, "--booting") )
|
|
|
|
booting = true;
|
2016-08-22 18:28:49 -04:00
|
|
|
else if ( !strcmp(arg, "--cancel") )
|
|
|
|
cancel = true;
|
2021-01-18 18:04:56 -05:00
|
|
|
else if ( !strcmp(arg, "--full") )
|
|
|
|
full = true;
|
2016-08-22 18:28:49 -04:00
|
|
|
else if ( !strcmp(arg, "--hook-finalize") )
|
|
|
|
hook_finalize = true;
|
|
|
|
else if ( !strcmp(arg, "--hook-prepare") )
|
|
|
|
hook_prepare = true;
|
2016-02-18 16:16:02 -05:00
|
|
|
else if ( !strcmp(arg, "--wait") )
|
|
|
|
wait = true;
|
|
|
|
else
|
2021-01-15 15:12:56 -05:00
|
|
|
errx(1, "unknown option: %s", arg);
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
compact_arguments(&argc, &argv);
|
|
|
|
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( 1 < booting + cancel + hook_finalize + hook_prepare + wait )
|
|
|
|
errx(2, "Mutually incompatible options were passed");
|
|
|
|
|
|
|
|
bool hook_only = hook_prepare || hook_finalize;
|
|
|
|
bool no_source = cancel;
|
|
|
|
bool no_cancel = booting || hook_only;
|
|
|
|
|
2016-02-18 16:16:02 -05:00
|
|
|
const char* source;
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( no_source )
|
2016-02-18 16:16:02 -05:00
|
|
|
{
|
2016-08-22 18:28:49 -04:00
|
|
|
source = "";
|
2016-02-18 16:16:02 -05:00
|
|
|
if ( 1 < argc )
|
2016-08-22 12:07:01 -04:00
|
|
|
errx(2, "Unexpected extra operand `%s'", argv[1]);
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
else if ( booting )
|
|
|
|
{
|
|
|
|
source = "/sysmerge";
|
|
|
|
if ( 1 < argc )
|
2016-08-22 12:07:01 -04:00
|
|
|
errx(2, "Unexpected extra operand `%s'", argv[1]);
|
2021-01-18 18:04:56 -05:00
|
|
|
full = access_or_die("/sysmerge/tix/sysmerge.full", F_OK) == 0;
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( argc < 2 )
|
2016-08-22 12:07:01 -04:00
|
|
|
errx(2, "No source operand was given");
|
2016-02-18 16:16:02 -05:00
|
|
|
source = argv[1];
|
|
|
|
if ( 2 < argc )
|
2016-08-22 12:07:01 -04:00
|
|
|
errx(2, "Unexpected extra operand `%s'", argv[2]);
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
|
2016-08-22 18:28:49 -04:00
|
|
|
bool did_cancel = false;
|
|
|
|
if ( !no_cancel && has_pending_upgrade() )
|
2016-02-18 16:16:02 -05:00
|
|
|
{
|
|
|
|
rename("/boot/sortix.bin.sysmerge.orig", "/boot/sortix.bin");
|
|
|
|
rename("/boot/sortix.initrd.sysmerge.orig", "/boot/sortix.initrd");
|
|
|
|
execute((const char*[]) { "rm", "-rf", "/sysmerge", NULL }, "");
|
2016-08-22 18:28:49 -04:00
|
|
|
execute((const char*[]) { "update-initrd", NULL }, "e");
|
2016-02-18 16:16:02 -05:00
|
|
|
printf("Cancelled pending system upgrade.\n");
|
2016-08-22 18:28:49 -04:00
|
|
|
did_cancel = true;
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( cancel )
|
2016-08-22 18:28:49 -04:00
|
|
|
{
|
|
|
|
if ( !did_cancel )
|
|
|
|
printf("No system upgrade was pending.\n");
|
2016-02-18 16:16:02 -05:00
|
|
|
return 0;
|
2016-08-22 18:28:49 -04:00
|
|
|
}
|
2016-02-18 16:16:02 -05:00
|
|
|
|
|
|
|
const char* old_release_path = "/etc/sortix-release";
|
|
|
|
struct release old_release;
|
|
|
|
if ( !os_release_load(&old_release, old_release_path, old_release_path) )
|
2016-04-08 17:09:38 -04:00
|
|
|
{
|
|
|
|
if ( errno == ENOENT )
|
|
|
|
warn("%s", old_release_path);
|
2016-02-18 16:16:02 -05:00
|
|
|
exit(2);
|
2016-04-08 17:09:38 -04:00
|
|
|
}
|
2016-02-18 16:16:02 -05:00
|
|
|
|
|
|
|
char* new_release_path;
|
|
|
|
if ( asprintf(&new_release_path, "%s/etc/sortix-release", source) < 0 )
|
|
|
|
err(2, "asprintf");
|
|
|
|
struct release new_release;
|
|
|
|
if ( !os_release_load(&new_release, new_release_path, new_release_path) )
|
2016-04-08 17:09:38 -04:00
|
|
|
{
|
|
|
|
if ( errno == ENOENT )
|
|
|
|
warn("%s", new_release_path);
|
2016-02-18 16:16:02 -05:00
|
|
|
exit(2);
|
2016-04-08 17:09:38 -04:00
|
|
|
}
|
2016-02-18 16:16:02 -05:00
|
|
|
free(new_release_path);
|
|
|
|
|
2017-04-12 15:05:03 -04:00
|
|
|
const char* old_machine_path = "/etc/machine";
|
|
|
|
char* old_machine = read_string_file(old_machine_path);
|
|
|
|
if ( !old_machine )
|
|
|
|
err(2, "%s", old_machine_path);
|
|
|
|
char* new_machine_path;
|
|
|
|
if ( asprintf(&new_machine_path, "%s/etc/machine", source) < 0 )
|
|
|
|
err(2, "asprintf");
|
|
|
|
char* new_machine = read_string_file(new_machine_path);
|
|
|
|
if ( !new_machine )
|
|
|
|
err(2, "%s", new_machine_path);
|
|
|
|
if ( strcmp(old_machine, new_machine) != 0 )
|
|
|
|
errx(2, "%s (%s) does not match %s (%s)", new_machine_path,
|
|
|
|
new_machine, old_machine_path, old_machine);
|
|
|
|
free(old_machine);
|
|
|
|
free(new_machine_path);
|
|
|
|
free(new_machine);
|
|
|
|
|
2016-02-18 16:16:02 -05:00
|
|
|
// TODO: Check for version (skipping, downgrading).
|
|
|
|
|
|
|
|
struct conf conf;
|
|
|
|
load_upgrade_conf(&conf, "/etc/upgrade.conf");
|
|
|
|
|
2017-04-10 10:37:30 -04:00
|
|
|
bool can_run_new_abi =
|
|
|
|
abi_compatible(new_release.abi_major, new_release.abi_minor,
|
|
|
|
old_release.abi_major, old_release.abi_minor);
|
2016-08-22 18:28:49 -04:00
|
|
|
|
|
|
|
bool header;
|
|
|
|
bool copy_files;
|
|
|
|
bool run_prepare;
|
|
|
|
bool run_finalize;
|
|
|
|
bool my_prepare;
|
|
|
|
bool my_finalize;
|
|
|
|
if ( booting )
|
2016-02-18 16:16:02 -05:00
|
|
|
{
|
2016-08-22 18:28:49 -04:00
|
|
|
header = true;
|
|
|
|
copy_files = true;
|
|
|
|
run_prepare = true;
|
|
|
|
my_prepare = true;
|
|
|
|
run_finalize = true;
|
|
|
|
my_finalize = true;
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
2016-08-22 18:28:49 -04:00
|
|
|
else if ( hook_prepare )
|
2016-02-18 16:16:02 -05:00
|
|
|
{
|
2016-08-22 18:28:49 -04:00
|
|
|
header = false;
|
|
|
|
copy_files = false;
|
|
|
|
run_prepare = true;
|
|
|
|
my_prepare = true;
|
|
|
|
run_finalize = false;
|
|
|
|
my_finalize = false;
|
|
|
|
}
|
|
|
|
else if ( hook_finalize )
|
|
|
|
{
|
|
|
|
header = false;
|
|
|
|
copy_files = false;
|
|
|
|
run_prepare = false;
|
|
|
|
my_prepare = false;
|
|
|
|
run_finalize = true;
|
|
|
|
my_finalize = true;
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( !wait && !can_run_new_abi )
|
|
|
|
{
|
|
|
|
printf("%lu.%lu -> %lu.%lu ABI transition, "
|
|
|
|
"delaying upgrade to next boot.\n",
|
|
|
|
old_release.abi_major, old_release.abi_major,
|
|
|
|
new_release.abi_major, new_release.abi_major);
|
|
|
|
wait = true;
|
|
|
|
}
|
|
|
|
header = true;
|
|
|
|
copy_files = true;
|
|
|
|
run_prepare = !wait;
|
|
|
|
my_prepare = false;
|
|
|
|
run_finalize = !wait;
|
|
|
|
my_finalize = false;
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( header )
|
|
|
|
{
|
|
|
|
if ( wait )
|
|
|
|
printf("Scheduling upgrade to %s on next boot using %s:\n",
|
|
|
|
new_release.pretty_name, source);
|
|
|
|
else
|
|
|
|
printf("Upgrading to %s using %s:\n",
|
|
|
|
new_release.pretty_name, source);
|
|
|
|
}
|
|
|
|
|
2020-12-27 16:32:04 -05:00
|
|
|
// Upgrade hooks that runs before the old system is replaced.
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( run_prepare )
|
|
|
|
{
|
|
|
|
if ( my_prepare )
|
2020-12-27 16:32:04 -05:00
|
|
|
upgrade_prepare(&old_release, &new_release, source, "");
|
2016-08-22 18:28:49 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char* new_sysmerge = join_paths(source, "sbin/sysmerge");
|
|
|
|
if ( !new_sysmerge )
|
2021-01-15 15:12:56 -05:00
|
|
|
err(2, "malloc");
|
2016-08-22 18:28:49 -04:00
|
|
|
execute((const char*[]) { new_sysmerge, "--hook-prepare", source,
|
|
|
|
NULL }, "e");
|
|
|
|
free(new_sysmerge);
|
|
|
|
}
|
|
|
|
if ( hook_prepare )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( copy_files )
|
|
|
|
{
|
|
|
|
const char* target = "";
|
|
|
|
if ( wait )
|
|
|
|
{
|
|
|
|
target = "/sysmerge";
|
|
|
|
if ( mkdir(target, 0755) < 0 )
|
|
|
|
err(2, "%s", target);
|
|
|
|
execute((const char*[]) { "tix-collection", "/sysmerge", "create",
|
|
|
|
NULL }, "e");
|
|
|
|
}
|
2021-01-18 18:04:56 -05:00
|
|
|
install_manifests_detect(source, target, true, true, full);
|
2016-08-22 18:28:49 -04:00
|
|
|
}
|
2016-02-18 16:16:02 -05:00
|
|
|
|
|
|
|
if ( wait )
|
|
|
|
{
|
|
|
|
printf(" - Scheduling upgrade on next boot...\n");
|
2021-01-18 18:04:56 -05:00
|
|
|
if ( full )
|
|
|
|
{
|
|
|
|
int fd = open("/sysmerge/tix/sysmerge.full", O_WRONLY | O_CREAT);
|
|
|
|
if ( fd < 0 )
|
|
|
|
err(1, "/sysmerge/tix/sysmerge.full");
|
|
|
|
close(fd);
|
|
|
|
}
|
2016-02-18 16:16:02 -05:00
|
|
|
execute((const char*[]) { "cp", "/boot/sortix.bin",
|
2021-01-15 15:12:56 -05:00
|
|
|
"/boot/sortix.bin.sysmerge.orig",
|
|
|
|
NULL }, "e");
|
2016-02-18 16:16:02 -05:00
|
|
|
execute((const char*[]) { "cp", "/boot/sortix.initrd",
|
2021-01-15 15:12:56 -05:00
|
|
|
"/boot/sortix.initrd.sysmerge.orig",
|
|
|
|
NULL }, "e");
|
2016-02-18 16:16:02 -05:00
|
|
|
execute((const char*[]) { "cp", "/sysmerge/boot/sortix.bin",
|
2016-08-22 18:28:49 -04:00
|
|
|
"/boot/sortix.bin", NULL }, "e");
|
|
|
|
execute((const char*[]) { "/sysmerge/sbin/update-initrd", NULL }, "e");
|
2016-02-18 16:16:02 -05:00
|
|
|
|
|
|
|
printf("The system will be upgraded to %s on the next boot.\n",
|
|
|
|
new_release.pretty_name);
|
|
|
|
printf("Run %s --cancel to cancel the upgrade.\n", argv[0]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-27 16:32:04 -05:00
|
|
|
// Upgrade hooks that run after the new system is installed.
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( run_finalize )
|
|
|
|
{
|
|
|
|
if ( my_finalize )
|
2020-12-27 16:32:04 -05:00
|
|
|
upgrade_finalize(&old_release, &new_release, source, "");
|
2016-08-22 18:28:49 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char* new_sysmerge = join_paths(source, "sbin/sysmerge");
|
|
|
|
if ( !new_sysmerge )
|
|
|
|
err(2, "asprintf");
|
|
|
|
execute((const char*[]) { new_sysmerge, "--hook-finalize", source,
|
|
|
|
NULL }, "e");
|
|
|
|
free(new_sysmerge);
|
|
|
|
}
|
|
|
|
if ( hook_finalize )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-21 16:09:03 -05:00
|
|
|
if ( booting )
|
|
|
|
{
|
|
|
|
unlink("/boot/sortix.bin.sysmerge.orig");
|
|
|
|
unlink("/boot/sortix.initrd.sysmerge.orig");
|
|
|
|
execute((const char*[]) { "rm", "-rf", "/sysmerge", NULL }, "");
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:28:49 -04:00
|
|
|
if ( access_or_die("/etc/fstab", F_OK) == 0 )
|
2016-02-18 16:16:02 -05:00
|
|
|
{
|
|
|
|
printf(" - Creating initrd...\n");
|
2016-08-22 18:28:49 -04:00
|
|
|
execute((const char*[]) { "update-initrd", NULL }, "e");
|
2016-02-18 16:16:02 -05:00
|
|
|
|
|
|
|
if ( conf.grub )
|
|
|
|
{
|
2021-01-15 15:12:56 -05:00
|
|
|
int boot_fd = open("/boot", O_RDONLY);
|
|
|
|
if ( boot_fd < 0 )
|
|
|
|
err(2, "/boot");
|
|
|
|
char* boot_device = atcgetblob(boot_fd, "device-path", NULL);
|
|
|
|
if ( !boot_device )
|
|
|
|
err(2, "Failed to find device of filesystem: /boot");
|
|
|
|
close(boot_fd);
|
|
|
|
// TODO: A better design for finding the parent block device of a
|
|
|
|
// partition without scanning every block device.
|
|
|
|
if ( is_partition_name(boot_device) )
|
|
|
|
*strrchr(boot_device, 'p') = '\0';
|
|
|
|
printf(" - Installing bootloader...\n");
|
|
|
|
execute((const char*[]) { "grub-install", boot_device,
|
|
|
|
NULL },"eqQ");
|
|
|
|
free(boot_device);
|
2016-02-18 16:16:02 -05:00
|
|
|
printf(" - Configuring bootloader...\n");
|
2016-08-22 18:28:49 -04:00
|
|
|
execute((const char*[]) { "update-grub", NULL }, "eqQ");
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
else if ( access_or_die("/etc/grub.d/10_sortix", F_OK) == 0 )
|
|
|
|
{
|
|
|
|
printf(" - Creating bootloader fragment...\n");
|
2016-08-22 18:28:49 -04:00
|
|
|
execute((const char*[]) { "/etc/grub.d/10_sortix", NULL }, "eq");
|
2016-02-18 16:16:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Successfully upgraded to %s.\n", new_release.pretty_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|