#!/bin/sh -euf # Copyright 2013-2014 Intel Corporation # Author: Artem Bityutskiy # License: GPLv2 PROG="setup-extlinux-conf" VER="1.0" srcdir="$(readlink -ev -- ${0%/*})" if [ -f "$srcdir/setup-ivi-sh-functions" ]; then . "$srcdir/setup-ivi-sh-functions" else . /usr/share/setup-ivi/setup-ivi-sh-functions fi # 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 # Generated by $PROG 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]