README: add some more shell coding wisdom
[platform/adaptation/setup-scripts.git] / installerfw-sh-functions
index d087c42..1316f8e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2013 Intel Corporation
+# Copyright 2013-2014 Intel Corporation
 # Author: Artem Bityutskiy
 # License: GPLv2
 
@@ -14,9 +14,6 @@ __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
@@ -31,7 +28,7 @@ __verbose()
 }
 
 # Verify that an environment variable is defined
-__verify_defined()
+installerfw_verify_defined()
 {
        local variable="$1"
 
@@ -45,9 +42,7 @@ __verify_defined()
 # tripple "/" in the resulting path.
 installerfw_mnt_prefix()
 {
-       __verify_defined "INSTALLERFW_MOUNT_PREFIX"
-
-       local path="$INSTALLERFW_MOUNT_PREFIX/$1"
+       local path="${INSTALLERFW_MOUNT_PREFIX:-}/$1"
 
        printf "%s" "$path" | LC_ALL=C sed -e 's/\/\+/\//g'
 }
@@ -80,6 +75,7 @@ installerfw_save_env()
 -e '^INSTALLERFW_PART[[:digit:]]\+_UUID=' \
 -e '^INSTALLERFW_PART_COUNT=' \
 -e '^INSTALLERFW_PTABLE_FORMAT=' \
+-e '^INSTALLERFW_INSTALLER_NAME=' \
 "
 
        local variables="$(printenv | eval "LC_ALL=C grep $opts")"
@@ -113,6 +109,16 @@ installerfw_restore_env()
                  "framework environment from \"$file\""
 }
 
+# Check whether installer framework variables are defined
+installerfw_available()
+{
+       if printenv | LC_ALL=C grep -q "^INSTALLERFW_[^[:blank:]]\+"; then
+               return 0;
+       else
+               return 1;
+       fi
+}
+
 # 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()
@@ -122,16 +128,16 @@ installerfw_is_efi_boot_system()
        # Make sure the UUID uses capital letters
        __ptypeid="$(printf "%s" "$__ptypeid" | tr "[:lower:]" "[:upper:]")"
 
-       __verify_defined "INSTALLERFW_PTABLE_FORMAT"
+       installerfw_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\")"
+                         "the EFI system partition"
                return 0
        else
                __verbose "installerfw_is_efi_boot_system(): no EFI" \
-                         "system partition found (type is" "\"$__ptypeid\")"
+                         "system partition found"
                return 1
        fi
 }
@@ -154,11 +160,11 @@ installerfw_get_part_info()
        local __res_var="$1"; shift
        local __pnum="0"
 
-       __verify_defined "INSTALLERFW_PART_COUNT"
+       installerfw_verify_defined "INSTALLERFW_PART_COUNT"
 
        while [ "$__pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
                local __mp="INSTALLERFW_PART${__pnum}_MOUNTPOINT"
-               __verify_defined "$__mp"
+               installerfw_verify_defined "$__mp"
 
                __mp="$(eval printf "%s" "\"\$$__mp\"")"