commit:     df7d41f1e2fd5056a06418bb379e351b52424b3d
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 26 16:15:18 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Fri Jul 26 16:15:18 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=df7d41f1

gen_funcs.sh: Add is_gzipped() function

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 gen_funcs.sh | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/gen_funcs.sh b/gen_funcs.sh
index 97a85dd..a1a3cf6 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -209,6 +209,32 @@ can_run_programs_compiled_by_genkernel() {
        echo "${can_run_programs}"
 }
 
+is_gzipped() {
+       [[ ${#} -ne 1 ]] \
+               && gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid 
usage of ${FUNCNAME}(): Function takes exactly one argument (${#} given)!"
+
+       local file_to_check=${1}
+
+       if [ ! -f "${file_to_check}" ]
+       then
+               gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid 
usage of ${FUNCNAME}(): File '${file_to_check}' does not exist!"
+       fi
+
+       local file_is_gzipped=no
+       local file_mimetype=$(file --brief --mime-type "${file_to_check}" 
2>/dev/null)
+
+       case "${file_mimetype}" in
+               application/x-gzip)
+                       file_is_gzipped=yes
+                       ;;
+               application/gzip)
+                       file_is_gzipped=yes
+                       ;;
+       esac
+
+       echo "${file_is_gzipped}"
+}
+
 is_valid_ssh_host_keys_parameter_value() {
        local parameter_value=${1}
 

Reply via email to