From: Ian Kelling Date: Wed, 23 Apr 2014 07:53:47 +0000 (-0700) Subject: improve iso handling and doc string X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=4ef4153814624c3eb0cade2e539800747d19ecd4;p=small-misc-bash improve iso handling and doc string --- diff --git a/ex b/ex index 391570e..5ca021e 100755 --- a/ex +++ b/ex @@ -15,11 +15,13 @@ 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";; diff --git a/ex-function b/ex-function index 91733c3..7980023 100644 --- a/ex-function +++ b/ex-function @@ -15,11 +15,13 @@ 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";;