182 |
"/boot/grub/grub.conf", |
"/boot/grub/grub.conf", |
183 |
"/boot/grub/menu.lst", |
"/boot/grub/menu.lst", |
184 |
"/etc/grub.conf", |
"/etc/grub.conf", |
185 |
|
"/boot/grub2/grub.cfg", |
186 |
|
"/boot/grub2-efi/grub.cfg", |
187 |
NULL |
NULL |
188 |
}; |
}; |
189 |
static int i = -1; |
static int i = -1; |
275 |
static char buf[1025]; |
static char buf[1025]; |
276 |
char *s = NULL; |
char *s = NULL; |
277 |
char *ret = NULL; |
char *ret = NULL; |
278 |
char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv"; |
char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv"; |
279 |
int rc = asprintf(&s, "grub2-editenv %s list | grep '^%s='", envFile, name); |
int rc = asprintf(&s, "grub-editenv %s list | grep '^%s='", envFile, name); |
280 |
|
|
281 |
if (rc < 0) |
if (rc < 0) |
282 |
return NULL; |
return NULL; |
340 |
{ |
{ |
341 |
char *s = NULL; |
char *s = NULL; |
342 |
int rc = 0; |
int rc = 0; |
343 |
char *envFile = info->envFile ? info->envFile : "/boot/grub2/grubenv"; |
char *envFile = info->envFile ? info->envFile : "/boot/grub/grubenv"; |
344 |
|
|
345 |
unquote(value); |
unquote(value); |
346 |
value = shellEscape(value); |
value = shellEscape(value); |
347 |
if (!value) |
if (!value) |
348 |
return -1; |
return -1; |
349 |
|
|
350 |
rc = asprintf(&s, "grub2-editenv %s set '%s=%s'", envFile, name, value); |
rc = asprintf(&s, "grub-editenv %s set '%s=%s'", envFile, name, value); |
351 |
free(value); |
free(value); |
352 |
if (rc <0) |
if (rc <0) |
353 |
return -1; |
return -1; |
3258 |
return rc; |
return rc; |
3259 |
} |
} |
3260 |
|
|
3261 |
|
int addMBInitrd(struct grubConfig * cfg, const char *newMBKernel, |
3262 |
|
const char * image, const char * prefix, const char * initrd) { |
3263 |
|
struct singleEntry * entry; |
3264 |
|
struct singleLine * line, * kernelLine, *endLine = NULL; |
3265 |
|
int index = 0; |
3266 |
|
|
3267 |
|
if (!image) return 0; |
3268 |
|
|
3269 |
|
for (; (entry = findEntryByPath(cfg, newMBKernel, prefix, &index)); index++) { |
3270 |
|
kernelLine = getLineByType(LT_MBMODULE, entry->lines); |
3271 |
|
if (!kernelLine) continue; |
3272 |
|
|
3273 |
|
if (prefix) { |
3274 |
|
int prefixLen = strlen(prefix); |
3275 |
|
if (!strncmp(initrd, prefix, prefixLen)) |
3276 |
|
initrd += prefixLen; |
3277 |
|
} |
3278 |
|
endLine = getLineByType(LT_ENTRY_END, entry->lines); |
3279 |
|
if (endLine) |
3280 |
|
removeLine(entry, endLine); |
3281 |
|
line = addLine(entry, cfg->cfi, preferredLineType(LT_MBMODULE,cfg->cfi), |
3282 |
|
kernelLine->indent, initrd); |
3283 |
|
if (!line) |
3284 |
|
return 1; |
3285 |
|
if (endLine) { |
3286 |
|
line = addLine(entry, cfg->cfi, LT_ENTRY_END, "", NULL); |
3287 |
|
if (!line) |
3288 |
|
return 1; |
3289 |
|
} |
3290 |
|
|
3291 |
|
break; |
3292 |
|
} |
3293 |
|
|
3294 |
|
return 0; |
3295 |
|
} |
3296 |
|
|
3297 |
int updateInitrd(struct grubConfig * cfg, const char * image, |
int updateInitrd(struct grubConfig * cfg, const char * image, |
3298 |
const char * prefix, const char * initrd) { |
const char * prefix, const char * initrd) { |
3299 |
struct singleEntry * entry; |
struct singleEntry * entry; |
4535 |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
4536 |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
4537 |
if (updateKernelPath && newKernelInitrd) { |
if (updateKernelPath && newKernelInitrd) { |
4538 |
if (updateInitrd(config, updateKernelPath, bootPrefix, |
if (newMBKernel) { |
4539 |
newKernelInitrd)) return 1; |
if (addMBInitrd(config, newMBKernel, updateKernelPath, |
4540 |
|
bootPrefix, newKernelInitrd)) |
4541 |
|
return 1; |
4542 |
|
} else { |
4543 |
|
if (updateInitrd(config, updateKernelPath, bootPrefix, |
4544 |
|
newKernelInitrd)) |
4545 |
|
return 1; |
4546 |
|
} |
4547 |
} |
} |
4548 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
4549 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |