packaging: release out (setup-efi-ivi improvements)
[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_PARTX_FSTYPE - which file-system format partition number X has
17 # 5. INSTALLERFW_MOUNT_PREFIX - where the target partitions are mounted (the
18 #    "root" directory of the file-system we install gummiboot to)
19
20 PROG="setup-efi-ivi"
21
22 # This is a helper function which prints an error message and exits
23 fatal()
24 {
25         printf "%s\n" "$PROG: error: $1" 1>&2
26         exit 1
27 }
28
29 # Make sure the installer framework variables are defined
30 [ "${INSTALLERFW_PART_COUNT:+x}" == "x" ] ||
31        fatal "installer framework environment variables not found"
32
33 # Find the root and boot paritions
34 pnum=0
35 root_partuuid=
36 boot_fstype=
37
38 while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
39         mountpoint="INSTALLERFW_PART${pnum}_MOUNTPOINT"
40         mountpoint="$(eval printf "%s" '$'$mountpoint)"
41
42         # Find out all the required data for the root and boot partition
43         if [ "$mountpoint" == "/" ]; then
44                 root_partuuid="INSTALLERFW_PART${pnum}_PARTUUID"
45                 root_partuuid="$(eval printf "%s" '$'$root_partuuid)"
46         # The boot parition has to be at "/boot"
47         elif [ "$mountpoint" == "/boot" ]; then
48                 boot_fstype="INSTALLERFW_PART${pnum}_FSTYPE"
49                 boot_fstype="$(eval printf "%s" '$'$boot_fstype)"
50         fi
51
52         pnum="$((pnum+1))"
53 done
54
55 # Make sure that the boot partition has a FAT file-system
56 [ "$boot_fstype" == "vfat" ] || \
57         fatal "boot partition has to have type \"vfat\""
58
59 # Get the ESP location
60 esp="$INSTALLERFW_MOUNT_PREFIX/boot"
61
62 # Make sure gummiboot is installed in the system
63 if ! ([ -f /usr/lib/gummiboot/gummibootia32.efi ] || \
64       [ -f /usr/lib/gummiboot/gummibootx64.efi ]); then
65         fatal "\"/usr/lib/gummiboot/gummiboot*.efi\" files not found!"
66 fi
67
68 # Install gummiboot
69 mkdir -p "$esp/EFI/boot"
70 [ -f "/usr/lib/gummiboot/gummibootia32.efi" ] &&
71         cp "/usr/lib/gummiboot/gummibootia32.efi" "$esp/EFI/boot/bootia32.efi"
72 [ -f "/usr/lib/gummiboot/gummibootx64.efi" ] &&
73         cp "/usr/lib/gummiboot/gummibootx64.efi" "$esp/boot/EFI/boot/bootx64.efi"
74
75 # Generate the list of installed kernels
76 kernels="$(ls -1 "$esp" | grep "^vmlinuz-" | sort -r | head -n1)"
77 # Get the newest kernel
78 newest_kernel="$(printf "%s" "$kernels" | head -n1)"
79
80 # Create the gummiboot configuration file
81 mkdir -p "$esp/loader"
82
83 cat > "$esp/loader/loader.conf" <<-EOF
84 timeout 0
85 default $newest_kernel.conf
86 EOF
87
88 # Create a gummiboot entry for each kernel
89 mkdir -p "$esp/loader/entries"
90 printf "%s\n" "$kernels" | while IFS= read -r kernel; do
91
92         kernel_version="$(printf "%s" $kernel | sed -e 's/vmlinuz-\(.*\)/\1/')"
93
94         cat > "$esp/loader/entries/$kernel.conf" <<-EOF
95         title Tizen IVI 3.0
96         version $kernel_version
97         efi/$kernel
98         options $INSTALLERFW_KERNEL_OPTS root=PARTUUID=$root_partuuid
99         EOF
100 done