setup-efi-ivi: always use the mount prefix variable
[profile/ivi/setup-efi-ivi.git] / setup-efi-ivi
1 #!/bin/sh -efu
2
3 # Copyright 2013 Intel Corporation
4 # Author: Artem Bityutskiy
5 # License: GPLv2
6
7 #
8 # This is a simple script which installs gummiboot to the ESP and creates the
9 # gummiboot configuration files. This script requires a number of environment
10 # variables to be defined. Namely:
11 #
12 # 1. INSTALLERFW_PART_COUNT - count of paritions
13 # 2. INSTALLERFW_PARTX_MOUNTPOINT - mount point of partition number X
14 #    (0 <= x < $INSTALLERFW_PART_COUNT)
15 # 3. INSTALLERFW_PARTX_PARTUUID - GPT GUID (AKA PARTUUID) of partition number X
16 # 4. INSTALLERFW_MOUNT_PREFIX - where the target partitions are mounted (the
17 #    "root" directory of the file-system we install gummiboot to)
18
19 PROG="setup-efi-ivi"
20
21 # This is a helper function which prints an error message and exits
22 fatal()
23 {
24         printf "%s\n" "$PROG: error: $1" 1>&2
25         exit 1
26 }
27
28 # Make sure the installer framework variables are defined
29 [ "${INSTALLERFW_PART_COUNT:+x}" == "x" ] ||
30        fatal "installer framework environment variables not found"
31
32 # Find the required root and boot parition parameters
33 pnum=0
34 root_partuuid=
35 boot_mountpoint=
36
37 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
38         mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
39         mountpoint="$(eval printf "%s" '$'$mountpoint)"
40
41         # Find out all the required data for the root and boot partition
42         if [ "$mountpoint" == "/" ]; then
43                 root_partuuid="INSTALLERFW_PART${pnum}_PARTUUID"
44                 root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
45         # The boot parition has to be at "/boot"
46         elif [ "$mountpoint" == "/boot" ]; then
47                 boot_mountpoint="$mountpoint"
48         fi
49
50         pnum="$((pnum+1))"
51 done
52
53 # Path to the gummiboot files
54 gummiboot_path="$INSTALLERFW_MOUNT_PREFIX/usr/lib/gummiboot"
55 # Make sure gummiboot is installed in the system
56 if ! ([ -f $gummiboot_path/gummibootia32.efi ] || \
57       [ -f $gummiboot_path/gummibootx64.efi ]); then
58         fatal "\"$gummiboot_path/gummiboot*.efi\" files not found!"
59 fi
60
61 # Get the ESP location
62 esp="$INSTALLERFW_MOUNT_PREFIX/$boot_mountpoint"
63
64 # Install gummiboot
65 mkdir -p "$esp/EFI/boot"
66 [ -f "$gummiboot_path/gummibootia32.efi" ] &&
67         cp "$gummiboot_path/gummibootia32.efi" "$esp/EFI/boot/bootia32.efi"
68 [ -f "$gummiboot_path/gummibootx64.efi" ] &&
69         cp "$gummiboot_path/gummibootx64.efi" "$esp/EFI/boot/bootx64.efi"
70
71 # Generate the list of installed kernels
72 kernels="$(ls -1 "$esp" | grep "^vmlinuz-" | sort -r | head -n1)"
73 # Get the newest kernel
74 newest_kernel="$(printf "%s" "$kernels" | head -n1)"
75
76 # Create the gummiboot configuration file
77 mkdir -p "$esp/loader"
78
79 cat > "$esp/loader/loader.conf" <<-EOF
80 timeout 0
81 default $newest_kernel.conf
82 EOF
83
84 # Create a gummiboot entry for each kernel
85 mkdir -p "$esp/loader/entries"
86 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
87
88         kernel_version="$(printf "%s" $kernel | sed -e 's/vmlinuz-\(.*\)/\1/')"
89
90         cat > "$esp/loader/entries/$kernel.conf" <<-EOF
91         title Tizen IVI 3.0
92         version $kernel_version
93         efi /$kernel
94         options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid
95         EOF
96 done