savannah-hackers-public
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-hackers-public] [PATCH] Add support for processing packages wh


From: Bruno Félix Rezende Ribeiro
Subject: [Savannah-hackers-public] [PATCH] Add support for processing packages whose URL doesn't end in a proper file name.
Date: Thu, 1 Oct 2015 14:21:04 -0300

It fix a bug where some processing methods (most likely decompression)
would fail if the URL didn't end with the proper extension.
---
 gsv-eval-remote.sh | 78 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 31 deletions(-)

diff --git a/gsv-eval-remote.sh b/gsv-eval-remote.sh
index 516f96c..d256c3c 100755
--- a/gsv-eval-remote.sh
+++ b/gsv-eval-remote.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # Copyright (C) 2014 Assaf Gordon (address@hidden)
 # Copyright (C) 2015 Bruno Félix Rezende Ribeiro <address@hidden>
@@ -96,74 +96,90 @@ fetch_package() {
     echo "$TMP1"
 }
 
+ensure_extension() {
+    if [[ "$1" =~ "\\.$2\$" ]]; then
+        echo "$1"
+    else
+        mv "$1"{,"$2"}
+        echo "$1$2"
+    fi
+}
+
 process_package() {
-    local DIRECTORY TYPE
+    local DIRECTORY TYPE FILE
 
     TYPE="$(echo $(file -b --mime-type "$1") \| $(file -b "$1"))"
 
     case $TYPE in
         *application/gzip*)
-            gunzip "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .gz)
+            gunzip "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/x-bzip2*)
-            bunzip2 "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .bz2)
+            bunzip2 "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/x-lzip*)
-            lzip -d "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .lz)
+            lzip -d "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/x-lzma*)
-            unlzma "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .lzma)
+            unlzma "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *'lzop compressed data'*)
-            lzop -d "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .lzo)
+            lzop -d "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/x-xz*)
-            unxz "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .xz)
+            unxz "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/x-compress*)
-            compress -d "$1" || die "failed to decompress '$1'"
-            process_package "${1%.*}"
+            FILE=$(ensure_extension "$1" .Z)
+            compress -d "$FILE" || die "failed to decompress '$FILE'"
+            process_package "${FILE%.*}"
             ;;
         *application/zip*)
+            FILE=$(ensure_extension "$1" .zip)
             DIRECTORY=$(mktemp -d zip.XXXXXX) \
                 || die "failed to create temporary directory"
-            unzip "$1" -d "$DIRECTORY" > /dev/null || die "failed to extract 
files from '$1'"
-            cd "$DIRECTORY"
-            pwd
+            unzip "$FILE" -d "$DIRECTORY" > /dev/null || die "failed to 
extract files from '$FILE'"
+            cd "$DIRECTORY" && pwd
             ;;
         *application/x-rar*)
+            FILE=$(ensure_extension "$1" .rar)
             DIRECTORY=$(mktemp -d x-rar.XXXXXX) \
                 || die "failed to create temporary directory"
-            unar "$1" -o "$DIRECTORY" > /dev/null || die "failed to extract 
files from '$1'"
-            cd "$DIRECTORY"
-            pwd
+            unar "$FILE" -o "$DIRECTORY" > /dev/null || die "failed to extract 
files from '$FILE'"
+            cd "$DIRECTORY" && pwd
             ;;
         *application/x-7z-compressed*)
+            FILE=$(ensure_extension "$1" .7z)
             DIRECTORY=$(mktemp -d x-7z.XXXXXX) \
                 || die "failed to create temporary directory"
-            7z x -o"$DIRECTORY" "$1" > /dev/null || die "failed to extract 
files from '$1'"
-            cd "$DIRECTORY"
-            pwd
+            7z x -o"$DIRECTORY" "$FILE" > /dev/null || die "failed to extract 
files from '$FILE'"
+            cd "$DIRECTORY" && pwd
             ;;
         *application/x-tar*)
+            FILE=$(ensure_extension "$1" .tar)
             DIRECTORY=$(mktemp -d x-tar.XXXXXX) \
                 || die "failed to create temporary directory"
-            tar -xf "$1" -C "$DIRECTORY" || die "failed to extract files from 
'$1'"
-            cd "$DIRECTORY"
-            pwd
+            tar -xf "$FILE" -C "$DIRECTORY" || die "failed to extract files 
from '$FILE'"
+            cd "$DIRECTORY" && pwd
             ;;
         *text/* | *+xml* | */xml*)
+            FILE="$1"
             DIRECTORY=$(mktemp -d text.XXXXXX) \
                 || die "failed to create temporary directory"
-            cp "$1" "$DIRECTORY" || die "failed to copy '$1' to '$DIRECTORY'"
-            cd "$DIRECTORY"
-            pwd
+            cp "$FILE" "$DIRECTORY" || die "failed to copy '$FILE' to 
'$DIRECTORY'"
+            cd "$DIRECTORY" && pwd
             ;;
         *)
             die "there is no known method to process '$TYPE'"
-- 
2.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]