mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-04-22 11:35:47 -04:00
Add timeout option for auto_install/persistence plugin (#1161)
This commit is contained in:
parent
0c66908935
commit
9cfd05811b
@ -45,6 +45,7 @@ int g_ventoy_wimboot_mode = 0;
|
|||||||
int g_ventoy_iso_uefi_drv = 0;
|
int g_ventoy_iso_uefi_drv = 0;
|
||||||
int g_ventoy_last_entry = -1;
|
int g_ventoy_last_entry = -1;
|
||||||
int g_ventoy_suppress_esc = 0;
|
int g_ventoy_suppress_esc = 0;
|
||||||
|
int g_ventoy_suppress_esc_default = 1;
|
||||||
int g_ventoy_menu_esc = 0;
|
int g_ventoy_menu_esc = 0;
|
||||||
int g_ventoy_fn_mutex = 0;
|
int g_ventoy_fn_mutex = 0;
|
||||||
int g_ventoy_terminal_output = 0;
|
int g_ventoy_terminal_output = 0;
|
||||||
@ -639,7 +640,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
|||||||
default_entry = get_entry_number (menu, "default");
|
default_entry = get_entry_number (menu, "default");
|
||||||
|
|
||||||
if (g_ventoy_suppress_esc)
|
if (g_ventoy_suppress_esc)
|
||||||
default_entry = 1;
|
default_entry = g_ventoy_suppress_esc_default;
|
||||||
else if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
|
else if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
|
||||||
default_entry = g_ventoy_last_entry;
|
default_entry = g_ventoy_last_entry;
|
||||||
}
|
}
|
||||||
@ -1036,6 +1037,11 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (autobooted == 0 && g_ventoy_menu_esc && auto_boot) {
|
||||||
|
g_ventoy_last_entry = boot_entry;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
e = grub_menu_get_entry (menu, boot_entry);
|
e = grub_menu_get_entry (menu, boot_entry);
|
||||||
if (! e)
|
if (! e)
|
||||||
continue; /* Menu is empty. */
|
continue; /* Menu is empty. */
|
||||||
|
@ -2969,6 +2969,7 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
int defidx = 1;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
char configfile[128];
|
char configfile[128];
|
||||||
install_template *node = NULL;
|
install_template *node = NULL;
|
||||||
@ -2992,11 +2993,15 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node->autosel >= 0 && node->autosel <= node->templatenum)
|
if (node->autosel >= 0 && node->autosel <= node->templatenum)
|
||||||
|
{
|
||||||
|
defidx = node->autosel;
|
||||||
|
if (node->timeout < 0)
|
||||||
{
|
{
|
||||||
node->cursel = node->autosel - 1;
|
node->cursel = node->autosel - 1;
|
||||||
debug("Auto install template auto select %d\n", node->autosel);
|
debug("Auto install template auto select %d\n", node->autosel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
@ -3004,24 +3009,31 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node->timeout > 0)
|
||||||
|
{
|
||||||
|
vtoy_ssprintf(buf, pos, "set timeout=%d\n", node->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
vtoy_ssprintf(buf, pos, "menuentry \"Boot without auto installation template\" {\n"
|
vtoy_ssprintf(buf, pos, "menuentry \"Boot without auto installation template\" {\n"
|
||||||
" echo %s\n}\n", "123");
|
" echo %s\n}\n", "");
|
||||||
|
|
||||||
for (i = 0; i < node->templatenum; i++)
|
for (i = 0; i < node->templatenum; i++)
|
||||||
{
|
{
|
||||||
vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\" {\n"
|
vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\"{\n"
|
||||||
" echo 123\n}\n",
|
" echo \"\"\n}\n",
|
||||||
node->templatepath[i].path);
|
node->templatepath[i].path);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ventoy_menu_esc = 1;
|
g_ventoy_menu_esc = 1;
|
||||||
g_ventoy_suppress_esc = 1;
|
g_ventoy_suppress_esc = 1;
|
||||||
|
g_ventoy_suppress_esc_default = defidx;
|
||||||
|
|
||||||
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
|
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
|
||||||
grub_script_execute_sourcecode(configfile);
|
grub_script_execute_sourcecode(configfile);
|
||||||
|
|
||||||
g_ventoy_menu_esc = 0;
|
g_ventoy_menu_esc = 0;
|
||||||
g_ventoy_suppress_esc = 0;
|
g_ventoy_suppress_esc = 0;
|
||||||
|
g_ventoy_suppress_esc_default = 1;
|
||||||
|
|
||||||
grub_free(buf);
|
grub_free(buf);
|
||||||
|
|
||||||
@ -3034,6 +3046,7 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
int defidx = 1;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
char configfile[128];
|
char configfile[128];
|
||||||
persistence_config *node;
|
persistence_config *node;
|
||||||
@ -3057,11 +3070,15 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node->autosel >= 0 && node->autosel <= node->backendnum)
|
if (node->autosel >= 0 && node->autosel <= node->backendnum)
|
||||||
|
{
|
||||||
|
defidx = node->autosel;
|
||||||
|
if (node->timeout < 0)
|
||||||
{
|
{
|
||||||
node->cursel = node->autosel - 1;
|
node->cursel = node->autosel - 1;
|
||||||
debug("Persistence image auto select %d\n", node->autosel);
|
debug("Persistence image auto select %d\n", node->autosel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
buf = (char *)grub_malloc(VTOY_MAX_SCRIPT_BUF);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
@ -3069,25 +3086,32 @@ static grub_err_t ventoy_cmd_sel_persistence(grub_extcmd_context_t ctxt, int arg
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node->timeout > 0)
|
||||||
|
{
|
||||||
|
vtoy_ssprintf(buf, pos, "set timeout=%d\n", node->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
vtoy_ssprintf(buf, pos, "menuentry \"Boot without persistence\" {\n"
|
vtoy_ssprintf(buf, pos, "menuentry \"Boot without persistence\" {\n"
|
||||||
" echo %s\n}\n", "123");
|
" echo %s\n}\n", "");
|
||||||
|
|
||||||
for (i = 0; i < node->backendnum; i++)
|
for (i = 0; i < node->backendnum; i++)
|
||||||
{
|
{
|
||||||
vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\" {\n"
|
vtoy_ssprintf(buf, pos, "menuentry \"Boot with %s\" {\n"
|
||||||
" echo 123\n}\n",
|
" echo \"\"\n}\n",
|
||||||
node->backendpath[i].path);
|
node->backendpath[i].path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ventoy_menu_esc = 1;
|
g_ventoy_menu_esc = 1;
|
||||||
g_ventoy_suppress_esc = 1;
|
g_ventoy_suppress_esc = 1;
|
||||||
|
g_ventoy_suppress_esc_default = defidx;
|
||||||
|
|
||||||
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
|
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos);
|
||||||
grub_script_execute_sourcecode(configfile);
|
grub_script_execute_sourcecode(configfile);
|
||||||
|
|
||||||
g_ventoy_menu_esc = 0;
|
g_ventoy_menu_esc = 0;
|
||||||
g_ventoy_suppress_esc = 0;
|
g_ventoy_suppress_esc = 0;
|
||||||
|
g_ventoy_suppress_esc_default = 1;
|
||||||
|
|
||||||
grub_free(buf);
|
grub_free(buf);
|
||||||
|
|
||||||
|
@ -829,6 +829,7 @@ typedef struct install_template
|
|||||||
int pathlen;
|
int pathlen;
|
||||||
char isopath[256];
|
char isopath[256];
|
||||||
|
|
||||||
|
int timeout;
|
||||||
int autosel;
|
int autosel;
|
||||||
int cursel;
|
int cursel;
|
||||||
int templatenum;
|
int templatenum;
|
||||||
@ -860,6 +861,7 @@ typedef struct persistence_config
|
|||||||
int pathlen;
|
int pathlen;
|
||||||
char isopath[256];
|
char isopath[256];
|
||||||
|
|
||||||
|
int timeout;
|
||||||
int autosel;
|
int autosel;
|
||||||
int cursel;
|
int cursel;
|
||||||
int backendnum;
|
int backendnum;
|
||||||
@ -987,6 +989,7 @@ typedef struct menu_password
|
|||||||
|
|
||||||
extern int g_ventoy_menu_esc;
|
extern int g_ventoy_menu_esc;
|
||||||
extern int g_ventoy_suppress_esc;
|
extern int g_ventoy_suppress_esc;
|
||||||
|
extern int g_ventoy_suppress_esc_default;
|
||||||
extern int g_ventoy_last_entry;
|
extern int g_ventoy_last_entry;
|
||||||
extern int g_ventoy_memdisk_mode;
|
extern int g_ventoy_memdisk_mode;
|
||||||
extern int g_ventoy_iso_raw;
|
extern int g_ventoy_iso_raw;
|
||||||
|
@ -602,6 +602,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
|||||||
{
|
{
|
||||||
int pathnum = 0;
|
int pathnum = 0;
|
||||||
int autosel = 0;
|
int autosel = 0;
|
||||||
|
int timeout = 0;
|
||||||
char *pos = NULL;
|
char *pos = NULL;
|
||||||
const char *iso = NULL;
|
const char *iso = NULL;
|
||||||
VTOY_JSON *pNode = NULL;
|
VTOY_JSON *pNode = NULL;
|
||||||
@ -638,6 +639,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
|||||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||||
|
{
|
||||||
|
if (timeout >= 0)
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [OK]\n", timeout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -662,6 +675,18 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk
|
|||||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||||
|
{
|
||||||
|
if (timeout >= 0)
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [OK]\n", timeout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -682,6 +707,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
|||||||
int type = 0;
|
int type = 0;
|
||||||
int pathnum = 0;
|
int pathnum = 0;
|
||||||
int autosel = 0;
|
int autosel = 0;
|
||||||
|
int timeout = 0;
|
||||||
const char *iso = NULL;
|
const char *iso = NULL;
|
||||||
VTOY_JSON *pNode = NULL;
|
VTOY_JSON *pNode = NULL;
|
||||||
install_template *node = NULL;
|
install_template *node = NULL;
|
||||||
@ -729,6 +755,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
|||||||
node->templatenum = pathnum;
|
node->templatenum = pathnum;
|
||||||
|
|
||||||
node->autosel = -1;
|
node->autosel = -1;
|
||||||
|
node->timeout = -1;
|
||||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||||
{
|
{
|
||||||
if (autosel >= 0 && autosel <= pathnum)
|
if (autosel >= 0 && autosel <= pathnum)
|
||||||
@ -737,6 +764,14 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||||
|
{
|
||||||
|
if (timeout >= 0)
|
||||||
|
{
|
||||||
|
node->timeout = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_install_template_head)
|
if (g_install_template_head)
|
||||||
{
|
{
|
||||||
node->next = g_install_template_head;
|
node->next = g_install_template_head;
|
||||||
@ -1175,6 +1210,7 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
|||||||
static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||||
{
|
{
|
||||||
int autosel = 0;
|
int autosel = 0;
|
||||||
|
int timeout = 0;
|
||||||
int pathnum = 0;
|
int pathnum = 0;
|
||||||
char *pos = NULL;
|
char *pos = NULL;
|
||||||
const char *iso = NULL;
|
const char *iso = NULL;
|
||||||
@ -1213,6 +1249,18 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
|||||||
grub_printf("autosel: %d [FAIL]\n", autosel);
|
grub_printf("autosel: %d [FAIL]\n", autosel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||||
|
{
|
||||||
|
if (timeout >= 0)
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [OK]\n", timeout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grub_printf("timeout: %d [FAIL]\n", timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1231,6 +1279,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
|||||||
static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
||||||
{
|
{
|
||||||
int autosel = 0;
|
int autosel = 0;
|
||||||
|
int timeout = 0;
|
||||||
int pathnum = 0;
|
int pathnum = 0;
|
||||||
const char *iso = NULL;
|
const char *iso = NULL;
|
||||||
VTOY_JSON *pNode = NULL;
|
VTOY_JSON *pNode = NULL;
|
||||||
@ -1273,6 +1322,7 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
node->backendnum = pathnum;
|
node->backendnum = pathnum;
|
||||||
|
|
||||||
node->autosel = -1;
|
node->autosel = -1;
|
||||||
|
node->timeout = -1;
|
||||||
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel))
|
||||||
{
|
{
|
||||||
if (autosel >= 0 && autosel <= pathnum)
|
if (autosel >= 0 && autosel <= pathnum)
|
||||||
@ -1281,6 +1331,14 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout))
|
||||||
|
{
|
||||||
|
if (timeout >= 0)
|
||||||
|
{
|
||||||
|
node->timeout = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_persistence_head)
|
if (g_persistence_head)
|
||||||
{
|
{
|
||||||
node->next = g_persistence_head;
|
node->next = g_persistence_head;
|
||||||
|
@ -375,6 +375,7 @@ grub_err_t ventoy_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **a
|
|||||||
|
|
||||||
g_ventoy_menu_esc = 1;
|
g_ventoy_menu_esc = 1;
|
||||||
g_ventoy_suppress_esc = 1;
|
g_ventoy_suppress_esc = 1;
|
||||||
|
g_ventoy_suppress_esc_default = 1;
|
||||||
|
|
||||||
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
|
grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size);
|
||||||
grub_script_execute_sourcecode(configfile);
|
grub_script_execute_sourcecode(configfile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user