From 194954b1306252f51ba01e34f8f1c010a0c6a818 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 19 Dec 2013 14:02:11 +0200 Subject: [PATCH] Initial commit Signed-off-by: Artem Bityutskiy --- README | 19 ++ efi-environment | 35 +++ installerfw-sh-functions | 179 +++++++++++++++ mbr-environment | 36 +++ packaging/setup-ivi.changes | 2 + packaging/setup-ivi.manifest | 5 + packaging/setup-ivi.spec | 84 +++++++ setup-extlinux-conf | 517 +++++++++++++++++++++++++++++++++++++++++++ setup-gummiboot-conf | 483 ++++++++++++++++++++++++++++++++++++++++ setup-ivi-boot | 174 +++++++++++++++ setup-ivi-bootloader-conf | 415 ++++++++++++++++++++++++++++++++++ setup-ivi-sh-functions | 118 ++++++++++ 12 files changed, 2067 insertions(+) create mode 100644 README create mode 100644 efi-environment create mode 100644 installerfw-sh-functions create mode 100644 mbr-environment create mode 100644 packaging/setup-ivi.changes create mode 100644 packaging/setup-ivi.manifest create mode 100644 packaging/setup-ivi.spec create mode 100755 setup-extlinux-conf create mode 100755 setup-gummiboot-conf create mode 100755 setup-ivi-boot create mode 100755 setup-ivi-bootloader-conf create mode 100644 setup-ivi-sh-functions diff --git a/README b/README new file mode 100644 index 0000000..b181983 --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +The documentaion can be found here: +https://wiki.tizen.org/wiki/IVI/artem-setup-ivi + +Some coding style notes for the shell scripts +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +1. Do not use bashisms, install 'dash' and use it to verify that the + scripts are free of bashisms. + +2. Do not use all capitals for variables + +3. For shared files, prefix all symbols which are not supposed to be + used from outside with "__". + +4. Be consistent with my style. If you see that something makes no sense + or could be improved, change that globally. + +-- +Artem Bityutskiy diff --git a/efi-environment b/efi-environment new file mode 100644 index 0000000..fa9a614 --- /dev/null +++ b/efi-environment @@ -0,0 +1,35 @@ +# This file can be used for testing setup-ivi-* scripts. This file corresponds +# to an EFI boot image (boot partition has the EFS type GUID). Do the following +# to start debugging +# +# mkdir /tmp/boot +# touch /tmp/boot/vmlinuz-3.12-x86-ivi +# mkdir -p /tmp/usr/lib/gummiboot +# touch /tmp/usr/lib/gummiboot/gummibootia32.efi +# mkdir /tmp/etc +# echo 'PRETTY_NAME="My test OS"' > /tmp/etc/os-release + +export INSTALLERFW_MOUNT_PREFIX="/tmp" +export INSTALLERFW_KERNEL_OPTS="rootwait rootfstype=ext4 quiet" +export INSTALLERFW_PART0_ALIGN=1024 +export INSTALLERFW_PART0_BOOTFLAG=True +export INSTALLERFW_PART0_FSOPTS=defaults,noatime +export INSTALLERFW_PART0_FSTYPE=vfat +export INSTALLERFW_PART0_LABEL=boot +export INSTALLERFW_PART0_MOUNTPOINT=/boot +export INSTALLERFW_PART0_PARTUUID=AC5A15ED-743A-42DC-88DD-97837EB802FD +export INSTALLERFW_PART0_SIZE=64 +export INSTALLERFW_PART0_TYPE_ID=C12A7328-F81F-11D2-BA4B-00A0C93EC93B +export INSTALLERFW_PART0_UUID=89A6-BDC8 +export INSTALLERFW_PART1_ALIGN=1024 +export INSTALLERFW_PART1_BOOTFLAG=False +export INSTALLERFW_PART1_FSOPTS=defaults,noatime +export INSTALLERFW_PART1_FSTYPE=ext4 +export INSTALLERFW_PART1_LABEL=platform +export INSTALLERFW_PART1_MOUNTPOINT=/ +export INSTALLERFW_PART1_PARTUUID=7D723C77-2EB1-4AD6-B585-54D8E243CD87 +export INSTALLERFW_PART1_SIZE=3748 +export INSTALLERFW_PART1_TYPE_ID= +export INSTALLERFW_PART1_UUID=a9bf2448-17b6-4113-99d7-061435a0a8a6 +export INSTALLERFW_PART_COUNT=2 +export INSTALLERFW_PTABLE_FORMAT=gpt diff --git a/installerfw-sh-functions b/installerfw-sh-functions new file mode 100644 index 0000000..d087c42 --- /dev/null +++ b/installerfw-sh-functions @@ -0,0 +1,179 @@ +# Copyright 2013 Intel Corporation +# Author: Artem Bityutskiy +# License: GPLv2 + +# This file contains common functions for setup-ivi-* programs + +# Own name +__PROG="${PROG:-installerfw-sh-functions}" + +# Installer framework variables are saved in this file +__installerfw_file="/etc/installerfw-environment" +# The OS release information file +__osrelease_file="/etc/os-release" +# EFI System Partition PARTUUID +__esp_ptypeid="C12A7328-F81F-11D2-BA4B-00A0C93EC93B" + +# Mount prefix is assumed to be "/" if it is not defined +[ -n "${INSTALLERFW_MOUNT_PREFIX:-}" ] || export INSTALLERFW_MOUNT_PREFIX="/" + +__fatal() +{ + IFS= printf "%s\n" "$__PROG: error: $*" 1>&2 + exit 1 +} + +__verbose() +{ + if [ -n "$verbose" ]; then + IFS= printf "%s\n" "$__PROG (verbose): $*" >&2 + fi +} + +# Verify that an environment variable is defined +__verify_defined() +{ + local variable="$1" + + printenv "$variable" > /dev/null || + __fatal "cannot find required environment variable" \ + "\"$variable\"" +} + +# Add the INSTALLERFW_MOUNT_PREFIX prefix to a path. This does not really +# require a separate function unless we want to be fancy and avoid double or +# tripple "/" in the resulting path. +installerfw_mnt_prefix() +{ + __verify_defined "INSTALLERFW_MOUNT_PREFIX" + + local path="$INSTALLERFW_MOUNT_PREFIX/$1" + + printf "%s" "$path" | LC_ALL=C sed -e 's/\/\+/\//g' +} + +# Return full path to the file which contains the installer framework +# environment variables. +installerfw_get_env_file_name() +{ + printf "%s" "$(installerfw_mnt_prefix "$__installerfw_file")" +} + +# Save installer framework environment variables. Note, all the variables can +# be split on 2 classes - those which make sense only inside the particular +# installer and those which make sense in the OS environment. We only save the +# latter. +installerfw_save_env() +{ + local file="$(installerfw_get_env_file_name)" + local opts="\ +-e '^INSTALLERFW_KERNEL_OPTS=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_ALIGN=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_BOOTFLAG=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_FSOPTS=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_FSTYPE=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_LABEL=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_MOUNTPOINT=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_PARTUUID=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_SIZE=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_TYPE_ID=' \ +-e '^INSTALLERFW_PART[[:digit:]]\+_UUID=' \ +-e '^INSTALLERFW_PART_COUNT=' \ +-e '^INSTALLERFW_PTABLE_FORMAT=' \ +" + + local variables="$(printenv | eval "LC_ALL=C grep $opts")" + + if [ "$(printf "%s" "$variables" | wc -l)" -eq "0" ]; then + __fatal "no installer framework environment variables" \ + "found, nothing to save" + fi + + printf "%s" "$variables" | LC_ALL=C sed -n -e \ + "s/\(^INSTALLERFW_[^=]\+\)=\(.*\)/\1=\"\2\"/p" > "$file" + __verbose "installerfw_save_env(): saved installer framework" \ + "environment in \"$file\"" +} + +# Restore installer framework environment variables. +installerfw_restore_env() +{ + local file="$(installerfw_get_env_file_name)" + + [ -f "$file" ] || \ + __fatal "installerfw_restore_env(): can't restore the" \ + "installer framework environment: can't find" \ + "\"$file\"" + + while IFS= read -r line; do + eval "export $line" + done < "$file" + + __verbose "installerfw_restore_env(): restored installer" \ + "framework environment from \"$file\"" +} + +# Check if the system is an EFI boot system by checking whether the boot +# partition is a FAT 32 partition with the magic EFI type GUID. +installerfw_is_efi_boot_system() +{ + installerfw_get_part_info "/boot" "TYPE_ID" "__ptypeid" + + # Make sure the UUID uses capital letters + __ptypeid="$(printf "%s" "$__ptypeid" | tr "[:lower:]" "[:upper:]")" + + __verify_defined "INSTALLERFW_PTABLE_FORMAT" + + if [ "${INSTALLERFW_PTABLE_FORMAT:-}" = "gpt" ] && \ + [ "$__ptypeid" = "$__esp_ptypeid" ]; then + __verbose "installerfw_is_efi_boot_system(): /boot is" \ + "the EFI system partition (type is" "\"$__ptypeid\")" + return 0 + else + __verbose "installerfw_is_efi_boot_system(): no EFI" \ + "system partition found (type is" "\"$__ptypeid\")" + return 1 + fi +} + +# Get a piece of installer framework data for a partition. At the moment the +# partition is specified by it's mount point (in $1), but this can be extended +# to also accept the partition number, if needed. +# +# The second parameter ($2) is the a partial installer framework variable name +# which should be returned. For example, "PARTUUID" would correspond to +# "INSTALLERFW_PARTx_PARTUUID", and so on. +# +# The third parameter ($3) is name of the variable to store the result at. If +# the requested installer framework variable is undefined or null, the shell +# variable with name stored in $3 will have null value upon exit. +installerfw_get_part_info() +{ + local __mntpoint="$1"; shift + local __var="$1"; shift + local __res_var="$1"; shift + local __pnum="0" + + __verify_defined "INSTALLERFW_PART_COUNT" + + while [ "$__pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do + local __mp="INSTALLERFW_PART${__pnum}_MOUNTPOINT" + __verify_defined "$__mp" + + __mp="$(eval printf "%s" "\"\$$__mp\"")" + + [ "$__mp" != "$__mntpoint" ] || break + + __pnum="$((__pnum+1))" + done + + local installerfw_var="INSTALLERFW_PART${__pnum}_${__var}" + + local __value= + if printenv "$installerfw_var" > /dev/null; then + __value="$(eval printf "%s" "\"\$$installerfw_var\"")" + fi + + __verbose "installerfw_get_part_info(): $__res_var=$__value" + eval "$__res_var"="\"\$__value\"" +} diff --git a/mbr-environment b/mbr-environment new file mode 100644 index 0000000..139e5f8 --- /dev/null +++ b/mbr-environment @@ -0,0 +1,36 @@ +# This file can be used for testing setup-ivi-* scripts. This file corresponds +# to an MBR boot image. Do the following to start debugging: +# +# mkdir /tmp/boot +# touch /tmp/boot/vmlinux-3.12-x86-ivi +# mkdir -p /tmp/usr/share/syslinux/ +# touch /tmp/usr/share/syslinux/gptmbr.bin +# mkdir /tmp/etc +# echo 'PRETTY_NAME="My test OS"' > /tmp/etc/os-release + +export INSTALLERFW_MOUNT_PREFIX="/tmp" +export INSTALLERFW_KERNEL_OPTS="rootwait rootfstype=ext4 quiet" +export INSTALLERFW_PART0_ALIGN=1024 +export INSTALLERFW_PART0_BOOTFLAG=True +export INSTALLERFW_PART0_FSOPTS=defaults,noatime +export INSTALLERFW_PART0_FSTYPE=ext4 +export INSTALLERFW_PART0_LABEL=boot +export INSTALLERFW_PART0_MOUNTPOINT=/boot +export INSTALLERFW_PART0_PARTUUID=FC86A97B-3E8F-46F7-82F8-995A397A0523 +export INSTALLERFW_PART0_SIZE=64 +export INSTALLERFW_PART0_DEVNODE_NOW=/dev/null +export INSTALLERFW_PART0_DISK_DEVNODE_NOW=/dev/null +unset INSTALLERFW_PART0_TYPE_ID +export INSTALLERFW_PART0_UUID=A775922D-D42F-4114-9089-35332B6F896E +export INSTALLERFW_PART1_ALIGN=1024 +export INSTALLERFW_PART1_BOOTFLAG=False +export INSTALLERFW_PART1_FSOPTS=defaults,noatime +export INSTALLERFW_PART1_FSTYPE=ext4 +export INSTALLERFW_PART1_LABEL=platform +export INSTALLERFW_PART1_MOUNTPOINT=/ +export INSTALLERFW_PART1_PARTUUID=B3EA5880-0737-4B0B-8858-B8933A50E44D +export INSTALLERFW_PART1_SIZE=3748 +unset INSTALLERFW_PART1_TYPE_ID +export INSTALLERFW_PART1_UUID=50C898EF-DC27-4CA2-A48C-326A2DE8E018 +export INSTALLERFW_PART_COUNT=2 +export INSTALLERFW_PTABLE_FORMAT=mbr diff --git a/packaging/setup-ivi.changes b/packaging/setup-ivi.changes new file mode 100644 index 0000000..94f588c --- /dev/null +++ b/packaging/setup-ivi.changes @@ -0,0 +1,2 @@ +* Thu Dec 19 14:29:23 UTC 2013 Artem Bityutskiy 1.0 +- Initial implementation diff --git a/packaging/setup-ivi.manifest b/packaging/setup-ivi.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/setup-ivi.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/setup-ivi.spec b/packaging/setup-ivi.spec new file mode 100644 index 0000000..9592a10 --- /dev/null +++ b/packaging/setup-ivi.spec @@ -0,0 +1,84 @@ +Name: setup-ivi +Version: 1.0 +Release: 1 +License: GPL-2.0 +Summary: Various early setup programs +Url: http://www.tizen.org +Group: System/Configuration +Source: %{name}_%{version}.tar.gz +Requires: /usr/bin/sed +Requires: /usr/bin/grep +Requires: /usr/bin/printf +Requires: /usr/bin/printenv +Requires: /usr/bin/sort +Requires: virtual-setup-ivi-bootloader +BuildArchitectures: noarch + +%package -n setup-gummiboot +Summary: Command-line tool for tweaking gummiboot configuration +Provides: virtual-setup-ivi-bootloader +Requires: %{name} +Requires: gummiboot + +%package -n setup-extlinux +Summary: Command-line tool for tweaking extlinux configuration +Provides: virtual-setup-ivi-bootloader +Requires: %{name} +Requires: syslinux-extlinux + +%description +This package provides various early system setup programs + +%description -n setup-gummiboot +This package provides a command-line tool for changing the gummiboot bootloader +configuration files. + +%description -n setup-extlinux +This package provides a command-line tool for changing the extlinux bootloader +configuration file. + +### +### PREP +### +%prep +%setup -q -n %{name}-%{version} + +%build + +### +### INSTALL +### +%install +install -d %{buildroot}/%{_sbindir} +install -d %{buildroot}/%{_prefix}/share/setup-ivi + +install -m755 setup-ivi-boot %{buildroot}/%{_sbindir} +install -m755 setup-ivi-bootloader-conf %{buildroot}/%{_sbindir} +install -m755 setup-gummiboot-conf %{buildroot}/%{_sbindir} +install -m755 setup-extlinux-conf %{buildroot}/%{_sbindir} +install -m644 setup-ivi-sh-functions %{buildroot}/%{_prefix}/share/setup-ivi +install -m644 installerfw-sh-functions %{buildroot}/%{_prefix}/share/setup-ivi + +### +### CLEAN +### +%clean +rm -rf %{buildroot} + +### +### FILES +### +%files +%defattr(-,root,root) +%{_sbindir}/setup-ivi-boot +%{_sbindir}/setup-ivi-bootloader-conf +%{_prefix}/share/setup-ivi/setup-ivi-sh-functions +%{_prefix}/share/setup-ivi/installerfw-sh-functions + +%files -n setup-gummiboot +%defattr(-,root,root) +%{_sbindir}/setup-gummiboot-conf + +%files -n setup-extlinux +%defattr(-,root,root) +%{_sbindir}/setup-extlinux-conf diff --git a/setup-extlinux-conf b/setup-extlinux-conf new file mode 100755 index 0000000..060d4fc --- /dev/null +++ b/setup-extlinux-conf @@ -0,0 +1,517 @@ +#!/bin/sh -euf + +# Copyright 2013 Intel Corporation +# Author: Artem Bityutskiy +# License: GPLv2 + +PROG="setup-extlinux-conf" +VER="1.0" + +srcdir="$(readlink -ev -- ${0%/*})" +PATH="/usr/share/setup-ivi:$srcdir:$PATH" + +. setup-ivi-sh-functions + +# This is a small trick which I use to make sure my scripts are portable - +# check if 'dash' is present, and if yes - use it. +if can_switch_to_dash; then + exec dash -euf "$srcdir/$PROG" "$@" + exit $? +fi + +# Common preparations for all subcommands. +prepare() +{ + verbose "Boot directory is $bootdir" + [ -d "$bootdir" ] || \ + fatal "boot directory path \"$bootdir\" does not exist" + + # The extlinux configuration directory + conf_dir="$bootdir/extlinux" + # The extlinux configuration file + conf_file="$conf_dir/extlinux.conf" +} + +# Create the default extlinux configuration file. +create_default_conf_file() +{ + verbose "creating the default configuration file \"$conf_file\"" + + mkdir -p $verbose "$conf_dir" >&2 + cat > "$conf_file" <<-EOF + ui vesamenu.c32 + prompt 0 + timeout 1 + default $1 + EOF +} + +# Check wheter the extlinux configuration file exist and if not: +# o create the default one if --force option was specified +# o fail if no --force option was specified +check_and_create_default_conf_file() +{ + if [ -s "$conf_file" ]; then + return 0 + fi + + if [ -n "$force" ]; then + create_default_conf_file "$1" + else + fatal "cannot find the extlinux configuration file" \ + "(\"$conf_file\") (use -f to force creating the" \ + "default one)" + fi +} + +# Get a regular expression for matching extlinux configuration file option "$1" +get_regexp() +{ + local opt="$(esc_regexp "$1")" + + opt="$(case_insensitive_regexp "$opt")" + printf "%s" "\(^[[:blank:]]*$opt[[:blank:]]\+\)\([^[:blank:]]\+\)\([[:blank:]]*$\)" +} + +# Return a regular expression for matching label with name "$1". +label_regexp() +{ + local opt="$(case_insensitive_regexp "label")" + local label="$(esc_regexp "$1")" + + printf "%s" "\(^[[:blank:]]*$opt[[:blank:]]\+\)\($label\)\([[:blank:]]*$\)" +} + +remove_label() +{ + local label="$1" + local l_regexp="$(label_regexp "$label")" + local anyl_regexp="$(get_regexp "label")" + + LC_ALL=C sed -i -n -e "/$l_regexp/ { # mathes our label line + :l n; # get the next line + /$l_regexp/bl # same label again, keep skipping + /$anyl_regexp/!bl # a different label, stop skipping + } + /$l_regexp/!p # print all other lines + " "$conf_file" + + remove_trailing_empty_lines "$conf_file" +} + +# +# ----------------------------------------------------------------------------- +# The "add" subcommand +# ----------------------------------------------------------------------------- +# + +show_add_usage() +{ + cat <<-EOF +Usage: $PROG add [options]