@@ -263,6 +263,89 @@ int infix_shell(kcontext_t *ctx)
263263 return rc ;
264264}
265265
266+ static const char * boot_targets [] = {
267+ "primary" ,
268+ "secondary" ,
269+ "net" ,
270+ NULL
271+ };
272+
273+ int infix_boot_targets (kcontext_t * ctx )
274+ {
275+ size_t i ;
276+
277+ (void )ctx ;
278+
279+ for (i = 0 ; boot_targets [i ]; i ++ )
280+ puts (boot_targets [i ]);
281+
282+ return 0 ;
283+ }
284+
285+ static const char * valid_boot_target (const kparg_t * parg )
286+ {
287+ const char * target ;
288+ size_t i ;
289+
290+ if (!parg )
291+ return NULL ;
292+
293+ target = kparg_value (parg );
294+ for (i = 0 ; boot_targets [i ]; i ++ ) {
295+ if (!strcmp (target , boot_targets [i ]))
296+ return target ;
297+ }
298+
299+ return NULL ;
300+ }
301+
302+ int infix_set_boot_order (kcontext_t * ctx )
303+ {
304+ char tmpfile [] = "/tmp/boot-order-XXXXXX" ;
305+ kpargv_t * pargv = kcontext_pargv (ctx );
306+ const char * targets [3 ];
307+ int fd , rc = 0 ;
308+ FILE * fp ;
309+
310+ targets [0 ] = valid_boot_target (kpargv_find (pargv , "first" ));
311+ targets [1 ] = valid_boot_target (kpargv_find (pargv , "second" ));
312+ targets [2 ] = valid_boot_target (kpargv_find (pargv , "third" ));
313+
314+ if (!targets [0 ]) {
315+ fprintf (stderr , ERRMSG "missing boot target\n" );
316+ return -1 ;
317+ }
318+
319+ fd = mkstemp (tmpfile );
320+ if (fd == -1 )
321+ goto fail ;
322+
323+ fp = fdopen (fd , "w" );
324+ if (!fp ) {
325+ close (fd );
326+ unlink (tmpfile );
327+ fail :
328+ fprintf (stderr , ERRMSG "failed creating temporary file\n" );
329+ return -1 ;
330+ }
331+
332+ fputs ("{\"infix-system:set-boot-order\":{\"boot-order\":[" , fp );
333+ for (size_t i = 0 ; i < NELEMS (targets ); i ++ ) {
334+ if (!targets [i ])
335+ continue ;
336+
337+ fprintf (fp , "%s\"%s\"" , i > 0 ? "," : "" , targets [i ]);
338+ }
339+ fputs ("]}}" , fp );
340+
341+ fclose (fp );
342+
343+ rc = systemf ("sysrepocfg -R %s -fjson 2>&1" , tmpfile );
344+ unlink (tmpfile );
345+
346+ return rc ;
347+ }
348+
266349int kplugin_infix_fini (kcontext_t * ctx )
267350{
268351 (void )ctx ;
@@ -274,6 +357,7 @@ int kplugin_infix_init(kcontext_t *ctx)
274357{
275358 kplugin_t * plugin = kcontext_plugin (ctx );
276359
360+ kplugin_add_syms (plugin , ksym_new ("boot_targets" , infix_boot_targets ));
277361 kplugin_add_syms (plugin , ksym_new ("copy" , infix_copy ));
278362 kplugin_add_syms (plugin , ksym_new ("datastore" , infix_datastore ));
279363 kplugin_add_syms (plugin , ksym_new ("erase" , infix_erase ));
@@ -282,6 +366,7 @@ int kplugin_infix_init(kcontext_t *ctx)
282366 kplugin_add_syms (plugin , ksym_new ("firewall_zones" , infix_firewall_zones ));
283367 kplugin_add_syms (plugin , ksym_new ("firewall_policies" , infix_firewall_policies ));
284368 kplugin_add_syms (plugin , ksym_new ("firewall_services" , infix_firewall_services ));
369+ kplugin_add_syms (plugin , ksym_new ("set_boot_order" , infix_set_boot_order ));
285370 kplugin_add_syms (plugin , ksym_new ("shell" , infix_shell ));
286371
287372 return 0 ;
0 commit comments