Initial implementation
[profile/ivi/setup-mbr-ivi.git] / setup-extlinux-conf
1 #!/bin/sh -efu
2
3 # Copyright 2013 Intel Corporation
4 # Author: Artem Bityutskiy
5 # License: GPLv2
6
7 # This scripts then scans the boot partition, finds out which kernels are
8 # available, and updates the extlinux configuration file: adds missing kernel
9 # records and delets non-existing kernels records. The default boot kernel is
10 # always the one with the latest version.
11 #
12 # This scripts makes several assumptions.
13 # 1. There is already a valid extlinux configuration at the boot partition
14 # 2. The kernel binary names are 'vmlinuz-<version>'
15 # 3. Extlinux uses the kernel pointed to by the "vmlinuz" symlink
16
17 PROG="setup-extlinux-conf"
18
19 # This is a helper function which printfs an error message and exits
20 fatal()
21 {
22         printf "%s\n" "$PROG: error: $1" 1>&2
23         exit 1
24 }
25
26 # Make sure the installer framework variables are defined
27 [ "${INSTALLERFW_MOUNT_PREFIX:+x}" == "x" ] ||
28        fatal "installer framework environment variables not found"
29
30 # Get the boot directory path
31 boot_path="$INSTALLERFW_MOUNT_PREFIX/boot"
32
33 # Make sure the extlinux configuration file exists
34 conf_file="$boot_path/extlinux/extlinux.conf"
35 [ -f "$conf_file" ] || \
36         fatal "cannot find the extlinux configuration file (\"$conf_file\")"
37
38 # Get the newest installed kernel
39 newest_kernel="$(ls -1 "$boot_path" | grep '^vmlinuz-' | sort -r | head -n1)"
40 [ -n "$newest_kernel" ] || \
41         fatal "no vmlinuz-* files found in \"$boot_path\""
42
43 # Update the "vmlinuz" symlink
44 ln -sf "$newest_kernel" "$boot_path/vmlinuz" || \
45         fatal "cannot create symlink: $boot_path/vmlinuz --> $newest_kernel