setup-ivi-bootloader-conf: add a menu entry for OS cloning
[platform/adaptation/setup-scripts.git] / setup-gummiboot-conf
index cd9c245..4fa7fbe 100755 (executable)
@@ -8,12 +8,16 @@ PROG="setup-gummiboot-conf"
 VER="1.0"
 
 srcdir="$(readlink -ev -- ${0%/*})"
-. "$srcdir/setup-ivi-sh-functions"
+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" "$@"
+       exec dash -euf -- "$srcdir/$PROG" "$@"
        exit $?
 fi
 
@@ -47,7 +51,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
        timeout 0
@@ -179,7 +183,7 @@ add_subcommand()
                fatal "cannot fetch kernel version from \"$kernel\""
 
        # Create the new entry
-       mkdir -p $verbose "$entries_dir" >&2
+       mkdir -p $verbose -- "$entries_dir" >&2
        cat > "$entry_path" <<-EOF
        # Generated by $PROG
        title $title
@@ -190,7 +194,7 @@ add_subcommand()
 
        if [ -n "$verbose" ]; then
                verbose "contents of \"$entry_path\":"
-               cat "$entry_path" >&2
+               cat -- "$entry_path" >&2
        fi
 }
 
@@ -267,7 +271,7 @@ remove_subcommand()
                      "(use -f to ignore this error)"
        fi
 
-       rm -rf $verbose "$entry_path" >&2
+       rm -rf $verbose -- "$entry_path" >&2
        verbose "removed $entry_path"
 }
 
@@ -285,11 +289,13 @@ get_kernel_from_entry()
 
        if [ -f "$entry" ]; then
                local regexp="$(get_regexp "efi")"
-               local result="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" "$entry")"
+               local result="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" -- \
+                               "$entry")"
 
                if [ -z "$result" ]; then
                        regexp="$(get_regexp "linux")"
-                       result="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" "$entry")"
+                       result="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" -- \
+                                 "$entry")"
 
                        [ -n "$result" ] || return 0
                fi
@@ -361,7 +367,8 @@ default_subcommand()
 
        # Find the current default entry
        local regexp="$(get_regexp "default")"
-       local default_entry="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" "$conf_file")"
+       local default_entry="$(LC_ALL=C sed -n -e "s/$regexp/\2/p" -- \
+                               "$conf_file")"
 
        if [ -z "$entry" ]; then
                printf "%s\n" "entry: $default_entry"
@@ -387,7 +394,7 @@ default_subcommand()
        # Escape special sed characters in "$entry" and replace the old default
        # entry with the new one
        local entry_esc="$(esc_sed_replacement "$entry")"
-       LC_ALL=C sed -i -e "s/$regexp/\1$entry_esc\3/" "$conf_file"
+       LC_ALL=C sed -i -e "s/$regexp/\1$entry_esc\3/" -- "$conf_file"
 
        verbose "set the default boot kernel to \"$entry"\"
 }