]> git.pld-linux.org Git - packages/efi-boot-update.git/blobdiff - efi-boot-update
Some variable quotting added
[packages/efi-boot-update.git] / efi-boot-update
index 41a8abe7f2b5832618eece988508e7c2c234a7fb..88e1d86d139d2412079bbd85d8e8dbe00fca7698 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 _SCRIPT_NAME=efi-boot-update
-_SCRIPT_VERSION=0.0
+_SCRIPT_VERSION=0.1
 
 . /etc/rc.d/init.d/functions
 
@@ -15,21 +15,22 @@ usage () {
     echo "  --mount, -m    Try to mount /boot/efi first"
     echo "  --verbose, -v  Verbose output"
     echo "  --force        Force file updates"
+    echo "  --auto         Automatic run from packages %post"
 }
 
 msg () {
-    echo "efi-boot-update: $*" >&2
+    echo -E "efi-boot-update: $*" >&2
 }
 
 verbose () {
     if is_yes "$VERBOSE" ; then 
-        echo "efi-boot-update: $*" >&2
+        echo -E "efi-boot-update: $*" >&2
     fi
 }
 
 verbose_cmd () {
     if is_yes "$VERBOSE" ; then
-        echo "+$*" >&2
+        echo -E "+$*" >&2
     fi
     "$@"
 }
@@ -41,7 +42,7 @@ list_remove () {
         if [ "$item" = "$2" ] ; then
             continue
         fi
-        echo -n "$item "
+        echo -nE "$item "
     done
 }
 
@@ -65,11 +66,18 @@ update_file () {
         esac
     done
     src="$1"; shift
-    dst="$2"; shift
+    dst="$1"; shift
     if [ -n "$*" ] ; then
         msg "update_file: unexpected arguments: $*"
         return 1
     fi
+    if [ -z "$src" ] ; then
+        msg "update_file: no source file"
+        return 1
+    fi
+    if [ -z "$dst" ] ; then
+        dst=`basename "$src"`
+    fi
     if [ "${dst#/}" = "${dst}" ] ; then
         # relative path
         dst="$DESTDIR/$dst"
@@ -116,14 +124,14 @@ remove_bootmgr_entry () {
     local bootnum
     bootnum=$(find_bootmgr_entry "$1")
     [ -n "$bootnum" ] || return 0
-    verbose_cmd $EFIBOOTMGR $EFIBOOTMGR_OPTS --delete-bootnum -b --quiet "$bootnum"
+    verbose_cmd $EFIBOOTMGR $EFIBOOTMGR_OPTS --quiet --delete-bootnum -b "$bootnum"
     echo -n "$bootnum"
 }
 
 add_bootmgr_entry () {
-    local label=$1
-    local binary=$2
-    local args=$3
+    local label="$1"
+    local binary="$2"
+    local args="$3"
     local bootnum
     bootnum=$(find_bootmgr_entry "$label")
 
@@ -132,7 +140,7 @@ add_bootmgr_entry () {
         binary="$DESTDIR/$binary"
     fi
     binary="${binary#/boot/efi}"
-    binary="$(echo -n "$binary"|sed -e's;/;\\;g')"
+    binary="$(echo -nE "$binary"|sed -e's;/;\\;g')"
 
     if [ -n "$bootnum" ] ; then
         echo -n "$args" | verbose_cmd $EFIBOOTMGR $EFIBOOTMGR_OPTS --quiet \
@@ -145,14 +153,20 @@ add_bootmgr_entry () {
     echo -n "$bootnum"
 }
 
+safe_string () {
+    echo -n "$*" | tr -c '[a-zA-Z0-9_]' '_'
+}
+
+ALLOW_AUTO="no"
 FORCE_UPDATES="no"
 MOUNT_EFI_PARTITION="no"
 LABEL_PREFIX=""
-DEFAULT=""
 VERBOSE="no"
 
 [ -e /etc/efi-boot/update.conf ] && . /etc/efi-boot/update.conf
 
+AUTO_RUN=no
+
 while [ -n "$*" ] ; do
     local arg
     arg="$1"
@@ -175,6 +189,10 @@ while [ -n "$*" ] ; do
         --force)
             FORCE_UPDATES="yes"
             ;;
+        --auto)
+            is_yes "$ALLOW_AUTO" || exit 0
+            AUTO_RUN=yes
+            ;;
         *)
             usage >&2
             exit 2
@@ -227,21 +245,23 @@ for bootloader_conf in /etc/efi-boot/update.d/*.conf ; do
     ARCH="$(uname -m)"
     BINARY=""
     ARGS=""
-    install_files() {}
+    install_files() {
+        /bin/true
+    }
 
     . "$bootloader_conf" || continue
 
     LABEL="$LABEL_PREFIX$LABEL"
 
     if ! is_yes "$ENABLED" ; then
-        remove_bootmgr_entry "$LABEL"
+        remove_bootmgr_entry "$LABEL" >/dev/null
         continue
     fi
 
     local efi_arch
     if [[ "$ARCH" = i?86 || "$ARCH" = pentium[45] || "$ARCH" = "athlon" ]] ; then
         # %ix86
-        efi_arch=x32
+        efi_arch=ia32
     elif [[ "$ARCH" = "x86_64" || "$ARCH" = "amd64" || "$ARCH" = "ia32e" ]] ; then
         # %x8664
         efi_arch=x64
@@ -255,18 +275,18 @@ for bootloader_conf in /etc/efi-boot/update.d/*.conf ; do
     install_files
     if [ -n "$BINARY" ] ; then
             bootnum="$(add_bootmgr_entry "$LABEL" "$BINARY" "$ARGS")"
-            eval "_${CONFIG_NAME}_bootnum=\"$bootnum\""
+            eval "_$(safe_string ${CONFIG_NAME})_bootnum=\"$bootnum\""
     fi
 done
 
-if [ -n "$ORDER" ] ; then
+if [ -n "$ORDER" -a "$EFIBOOTMGR" != "/bin/true" ] ; then
     # set up the configured boot order, not removing any existing entries
-    tail="$(efibootmgr | awk '/^BootOrder:/ {gsub(/,/," ",$2); print $2}')"
+    tail="$($EFIBOOTMGR | awk '/^BootOrder:/ {gsub(/,/," ",$2); print $2}')"
     head=""
     for config_name in $ORDER ; do
-        eval "bootnum=\$_${config_name}_bootnum"
+        eval "bootnum=\$_$(safe_string ${config_name})_bootnum"
         if [ -z "$bootnum" ] ; then
-            msg "Cannot find '$config_name' config - won't add to boot order."
+            verbose "Cannot find '$config_name' config - won't add to boot order."
             continue
         fi
         tail="$(list_remove "$tail" "$bootnum")"
@@ -278,4 +298,9 @@ if [ -n "$ORDER" ] ; then
     fi
 fi
 
+if ! is_yes "$ALLOW_AUTO" && ! is_yes "$AUTO_RUN"; then
+    msg "ALLOW_AUTO is not enabled in /etc/efi-boot/update.conf,"
+    msg "files will not be automatically updated on upgrades."
+fi
+
 # vi: ft=sh sw=4 sts=4 et
This page took 0.048964 seconds and 4 git commands to generate.