improve iso handling and doc string
authorIan Kelling <ian@iankelling.org>
Wed, 23 Apr 2014 07:53:47 +0000 (00:53 -0700)
committerIan Kelling <ian@iankelling.org>
Fri, 12 Aug 2016 22:57:29 +0000 (15:57 -0700)
ex
ex-function

diff --git a/ex b/ex
index 391570e4da43e9cb5887a357eb71c20e3783bb1d..5ca021ec64c3eb9fb3494d7ef9b2015a03e2eeaf 100755 (executable)
--- a/ex
+++ b/ex
 
 ex() {
     local help="Usage: ex [--help] FILE...
-Extract each FILE according to its extension."
+Extract each FILE according to its extension.
+7z bz2 deb gz iso rar rpm tar xz zip & variations.
+See source for exact file extensions."
     if [[ $1 == --help ]]; then
         echo "$help"
     fi
-    local x
+    local x super
     for x in "$@"; do
        case "$x" in
            *.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;;
@@ -34,13 +36,20 @@ Extract each FILE according to its extension."
             *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;;
            *.tar.xz ) tar Jxvf "$x" ;;
             *.iso )
+                if [[ $EUID != 0 ]]; then
+                    if [[ $(sudo -v) == Sorry* ]]; then
+                        echo error: need superuser priveledge for iso file
+                        return 1
+                    fi
+                    super=sudo
+                fi
                 local temp_dir=$(mktemp -d)
                 losetup -f
-                s mount -o loop "$x" "$temp_dir"
+                $super mount -o loop "$x" "$temp_dir"
                 local dir="${x%%.iso}"
                 mkdir "$dir"
                 cp -av "$temp_dir"/* "$dir"
-                s umount "$temp_dir"
+                $super umount "$temp_dir"
                 ;;
             *.r[0-9][0-9]|*.rar ) unrar x "$x" ;;
            *)  echo "I don't kno how to extract $x";;
index 91733c3284dd0b7dac2e9177338cc72d3591beb0..79800235001ce49d97011cfa9a5bf06528cf8bbe 100644 (file)
 
 ex() {
     local help="Usage: ex [--help] FILE...
-Extract each FILE according to its extension."
+Extract each FILE according to its extension.
+7z bz2 deb gz iso rar rpm tar xz zip & variations.
+See source for exact file extensions."
     if [[ $1 == --help ]]; then
         echo "$help"
     fi
-    local x
+    local x super
     for x in "$@"; do
        case "$x" in
            *.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;;
@@ -34,13 +36,20 @@ Extract each FILE according to its extension."
             *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;;
            *.tar.xz ) tar Jxvf "$x" ;;
             *.iso )
+                if [[ $EUID != 0 ]]; then
+                    if [[ $(sudo -v) == Sorry* ]]; then
+                        echo error: need superuser priveledge for iso file
+                        return 1
+                    fi
+                    super=sudo
+                fi
                 local temp_dir=$(mktemp -d)
                 losetup -f
-                s mount -o loop "$x" "$temp_dir"
+                $super mount -o loop "$x" "$temp_dir"
                 local dir="${x%%.iso}"
                 mkdir "$dir"
                 cp -av "$temp_dir"/* "$dir"
-                s umount "$temp_dir"
+                $super umount "$temp_dir"
                 ;;
             *.r[0-9][0-9]|*.rar ) unrar x "$x" ;;
            *)  echo "I don't kno how to extract $x";;