enables pill download from arvo commit hash

This commit is contained in:
Joe Bryan 2019-02-11 14:58:23 -05:00
parent bf3dce1c01
commit b41f65304f
3 changed files with 85 additions and 31 deletions

View File

@ -546,8 +546,7 @@
/* u3_opts: command line configuration.
*/
typedef struct _u3_opts {
// XX find a way to re-enable -A (fastboot)
// c3_c* arv_c; // -A, initial sync from
c3_c* arv_c; // -A, initial sync from
c3_o abo; // -a, abort aggressively
c3_c* pil_c; // -B, bootstrap from
c3_o bat; // -b, batch create
@ -573,8 +572,7 @@
c3_o qui; // -q, quiet
c3_o rep; // -R, report build info
c3_o has; // -S, Skip battery hashes
// XX find a way to re-enable -s (auto-pill)
// c3_o git; // -s, pill url from arvo git hash
c3_o git; // -s, pill url from arvo git hash
c3_o etn; // -t, trust snapshot for pre-boot
c3_c* url_c; // -u, pill url
c3_o vno; // -V, replay without reboots

View File

@ -467,6 +467,62 @@ _king_get_atom(c3_c* url_c)
return u3i_bytes(buf_u.len, (const c3_y*)buf_u.base);
}
/* _get_cmd_output(): Run a shell command and capture its output.
Exits with an error if the command fails or produces no output.
The 'out_c' parameter should be an array of sufficient length to hold
the command's output, up to a max of len_c characters.
*/
static void
_get_cmd_output(c3_c *cmd_c, c3_c *out_c, c3_w len_c)
{
FILE *fp = popen(cmd_c, "r");
if ( NULL == fp ) {
fprintf(stderr, "'%s' failed\n", cmd_c);
exit(1);
}
if ( NULL == fgets(out_c, len_c, fp) ) {
fprintf(stderr, "'%s' produced no output\n", cmd_c);
exit(1);
}
pclose(fp);
}
/* _arvo_hash(): get a shortened hash of the last git commit
that modified the sys/ directory in arvo.
hax_c must be an array with length >= 11.
*/
static void
_arvo_hash(c3_c *out_c, c3_c *arv_c)
{
c3_c cmd_c[2048];
sprintf(cmd_c, "git -C %s log -1 HEAD --format=%%H -- sys/", arv_c);
_get_cmd_output(cmd_c, out_c, 11);
out_c[10] = 0; // end with null-byte
}
/* _git_pill_url(): produce a URL from which to download a pill
based on the location of an arvo git repository.
*/
static void
_git_pill_url(c3_c *out_c, c3_c *arv_c)
{
c3_c hax_c[11];
assert(NULL != arv_c);
if ( 0 != system("which git >> /dev/null") ) {
fprintf(stderr, "boot: could not find git executable\r\n");
exit(1);
}
_arvo_hash(hax_c, arv_c);
sprintf(out_c, "https://bootstrap.urbit.org/git-%s.pill", hax_c);
}
/* _boothack_pill(): parse CLI pill arguments into +pill specifier
*/
static u3_noun
@ -480,11 +536,21 @@ _boothack_pill(void)
pil = u3m_file(u3_Host.ops_u.pil_c);
}
else {
c3_assert( 0 != u3_Host.ops_u.url_c );
fprintf(stderr, "boot: downloading pill %s\r\n", u3_Host.ops_u.url_c);
pil = _king_get_atom(u3_Host.ops_u.url_c);
}
c3_c url_c[2048];
if ( (c3y == u3_Host.ops_u.git) &&
(0 != u3_Host.ops_u.arv_c) )
{
_git_pill_url(url_c, u3_Host.ops_u.arv_c);
}
else {
c3_assert( 0 != u3_Host.ops_u.url_c );
strcpy(url_c, u3_Host.ops_u.url_c);
}
fprintf(stderr, "boot: downloading pill %s\r\n", url_c);
pil = _king_get_atom(url_c);
}
return u3nt(c3y, pil, arv);
}

View File

@ -72,10 +72,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.dry = c3n;
u3_Host.ops_u.etn = c3n;
u3_Host.ops_u.gab = c3n;
// XX find a way to re-enable -s (auto-pill)
//
// u3_Host.ops_u.git = c3n;
u3_Host.ops_u.git = c3n;
// always disable hashboard
// XX temporary, remove once hashes are added
@ -92,10 +89,8 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.veb = c3n;
u3_Host.ops_u.kno_w = DefaultKernel;
// XX re-enable -s, -A
//
while ( -1 != (ch_i=getopt(argc, argv,
"G:J:B:K:H:w:u:e:E:f:F:k:m:p:LjabcCdgqtvxPDRS")) )
"G:J:B:K:A:H:w:u:e:E:f:F:k:m:p:LjabcCdgqstvxPDRS")) )
{
switch ( ch_i ) {
case 'J': {
@ -111,10 +106,8 @@ _main_getopt(c3_i argc, c3_c** argv)
break;
}
case 'A': {
// XX find a way to re-enable -A (fastboot)
// u3_Host.ops_u.arv_c = strdup(optarg);
// break;
return c3n;
u3_Host.ops_u.arv_c = strdup(optarg);
break;
}
case 'H': {
u3_Host.ops_u.dns_c = strdup(optarg);
@ -188,8 +181,7 @@ _main_getopt(c3_i argc, c3_c** argv)
case 'D': { u3_Host.ops_u.dry = c3y; break; }
case 'q': { u3_Host.ops_u.qui = c3y; break; }
case 'v': { u3_Host.ops_u.veb = c3y; break; }
// XX find a way to re-enable -s (auto-pill)
// case 's': { u3_Host.ops_u.git = c3y; break; }
case 's': { u3_Host.ops_u.git = c3y; break; }
case 'S': { u3_Host.ops_u.has = c3y; break; }
case 't': { u3_Host.ops_u.etn = c3y; break; }
case '?': default: {
@ -325,20 +317,18 @@ _main_getopt(c3_i argc, c3_c** argv)
return c3n;
}
else if ( u3_Host.ops_u.nuu == c3y
&& u3_Host.ops_u.url_c == 0 ) {
// XX find a way to re-enable -s (auto-pill)
// && u3_Host.ops_u.git == c3n ) {
&& u3_Host.ops_u.url_c == 0
&& u3_Host.ops_u.git == c3n ) {
u3_Host.ops_u.url_c =
"https://bootstrap.urbit.org/urbit-" URBIT_VERSION ".pill";
}
// XX find a way to re-enable -A (fastboot)
// else if ( u3_Host.ops_u.nuu == c3y
// && u3_Host.ops_u.url_c == 0
// && u3_Host.ops_u.arv_c == 0 ) {
else if ( u3_Host.ops_u.nuu == c3y
&& u3_Host.ops_u.url_c == 0
&& u3_Host.ops_u.arv_c == 0 ) {
// fprintf(stderr, "-s only makes sense with -A\n");
// return c3n;
// }
fprintf(stderr, "-s only makes sense with -A\n");
return c3n;
}
if ( u3_Host.ops_u.pil_c != 0 ) {
struct stat s;