Make tizen generic (rename "ivi" by "scripts")
[platform/adaptation/setup-scripts.git] / setup-extlinux-conf
index 20e00c9..f06c95e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh -euf
 
-# Copyright 2013 Intel Corporation
+# Copyright 2013-2014 Intel Corporation
 # Author: Artem Bityutskiy
 # License: GPLv2
 
@@ -8,14 +8,16 @@ PROG="setup-extlinux-conf"
 VER="1.0"
 
 srcdir="$(readlink -ev -- ${0%/*})"
-PATH="/usr/share/setup-ivi:$srcdir:$PATH"
-
-. setup-ivi-sh-functions
+if [ -f "$srcdir/setup-scripts-sh-functions" ]; then
+       . "$srcdir/setup-scripts-sh-functions"
+else
+       .  /usr/share/setup-scripts/setup-scripts-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" "$@"
+       exec dash -euf -- "$srcdir/$PROG" "$@"
        exit $?
 fi
 
@@ -37,7 +39,7 @@ create_default_conf_file()
 {
        verbose "creating the default configuration file \"$conf_file\""
 
-       mkdir -p $verbose "$conf_dir" >&2
+       mkdir -p $verbose -- "$conf_dir" >&2
        cat > "$conf_file" <<-EOF
        # Generated by $PROG
        ui vesamenu.c32
@@ -95,7 +97,7 @@ remove_label()
                        /$anyl_regexp/!bl    # a different label, stop skipping
                    }
                    /$l_regexp/!p            # print all other lines
-                   " "$conf_file"
+                   " -- "$conf_file"
 
        remove_trailing_empty_lines "$conf_file"
 }
@@ -192,7 +194,7 @@ add_subcommand()
        # Make sure the extlinux configuration file exists
        check_and_create_default_conf_file "$label"
 
-       if LC_ALL=C grep -q -e "$(label_regexp "$label")" "$conf_file" && \
+       if LC_ALL=C grep -q -e "$(label_regexp "$label")" -- "$conf_file" && \
           [ -z "$force" ]; then
                fatal "extlinux boot menu label \"$label\" already exists" \
                      "(use -f to force re-creating it)"
@@ -287,7 +289,7 @@ remove_subcommand()
 
        local label="$1"
 
-       if ! LC_ALL=C grep -q -e "$(label_regexp "$label")" "$conf_file" && \
+       if ! LC_ALL=C grep -q -e "$(label_regexp "$label")" -- "$conf_file" && \
           [ -z "$force" ]; then
                fatal "cannot find label \"$label\" in \"$conf_file\"" \
                      "(use -f to ignore this error)"
@@ -320,7 +322,7 @@ get_kernel_by_label()
                /$linux_regexp/ { s/$linux_regexp/\2/p }
                /$kernel_regexp/ { s/$kernel_regexp/\2/p }
                /$anyl_regexp/!bl # Loop till the next label
-       }" "$conf_file")"
+       }" -- "$conf_file")"
 
        printf "%s" "${result##*/}"
 }
@@ -386,7 +388,8 @@ default_subcommand()
 
        # Find the current default label
        local regexp="$(get_regexp "default")"
-       local default_label="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" "$conf_file")"
+       local default_label="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" -- \
+                               "$conf_file")"
 
        if [ -z "$label" ]; then
                printf "%s\n" "label: $default_label"
@@ -395,7 +398,7 @@ default_subcommand()
        fi
 
        local l_regexp="$(label_regexp "$label")"
-       local labels="$(LC_ALL=C grep -e "$l_regexp" "$conf_file" | wc -l)"
+       local labels="$(LC_ALL=C grep -e "$l_regexp" -- "$conf_file" | wc -l)"
 
        if [ "$labels" -eq "0" ] && [ -z "$force" ]; then
                fatal "cannot find label \"$label\" in \"$conf_file\"" \
@@ -416,14 +419,14 @@ default_subcommand()
                        $                 { s/.*/&\n$def/; q }
                        /^[[:blank:]]*$/  { s/.*/$def\n&/; q }
                        /$(anyl_regexp)/  { s/.*/$def\n&/; q }
-                       " "$conf_file"
+                       " -- "$conf_file"
                return 0
        fi
 
        # Escape special sed characters in "$entry" and replace the old default
        # entry with the new one
        local esc_label="$(esc_sed_replacement "$label")"
-       LC_ALL=C sed -i -e "s/$regexp/\1$esc_label\3/" "$conf_file"
+       LC_ALL=C sed -i -e "s/$regexp/\1$esc_label\3/" -- "$conf_file"
        verbose "set the default boot kernel to \"$label"\"
 }