X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Farchival%2Funpack.sh;h=b67ac9788a56eaabbf00af64ac58bc3e2e35cdad;hb=68f16b40d564a399b525b24ee045f640482c7f96;hp=103ec1932b66269da79ae19724c773a8ae357886;hpb=da12bc4babc06a03a41ef75626fd47e2d2891048;p=feisty_meow.git diff --git a/scripts/archival/unpack.sh b/scripts/archival/unpack.sh index 103ec193..b67ac978 100644 --- a/scripts/archival/unpack.sh +++ b/scripts/archival/unpack.sh @@ -11,7 +11,7 @@ ############## # # An arbitrary format archive unpacker, although really we are mainly supporting -# tar and zip currently, including compressed formats. +# tar, zip, 7z, and rar at this time. archive_file="$1"; shift if [ -z "$archive_file" ]; then @@ -20,16 +20,17 @@ if [ -z "$archive_file" ]; then exit 1 fi if [ ! -f "$archive_file" ]; then - echo "The file specified for unpacking cannot be located: $archive_file" + echo "The file specified cannot be located: $archive_file" exit 1 fi unpack_dir="$1"; shift if [ -z "$unpack_dir" ]; then - unpack_dir=$(echo unpacked_$(basename $archive_file) | sed -e 's/^\([^\.]*\)\..*/\1/') + all_but_last="$(echo "$(basename "$archive_file")" | sed -e 's/\([\^.]*\)\.[^\.]*$/\1/')" + unpack_dir="arch_${all_but_last}" fi if [ ! -d "$unpack_dir" ]; then - mkdir "$unpack_dir" + mkdir -p "$unpack_dir" if [ $? -ne 0 ]; then echo "Could not create the unpacking directory: $unpack_dir" exit 1 @@ -51,23 +52,42 @@ if [ ! -f "$archive_file" ]; then fi fi -if [[ $archive_file =~ .*\.tar$ \ - || $archive_file =~ .*\.tar\.gz$ \ - || $archive_file =~ .*\.tar\.bz2$ \ - || $archive_file =~ .*\.iar$ \ - || $archive_file =~ .*\.oar$ \ - || $archive_file =~ .*\.tgz$ \ +#hmmm: we could log to a file and spew the file if there's a failure, then +# remove the file after spewing or after successful run. +# this is a really commonly repeated pattern that would be nice to support +# in general. + +# record what happened. +save_err=1 +if [[ "$archive_file" =~ .*\.tar$ \ + || "$archive_file" =~ .*\.tar\.gz$ \ + || "$archive_file" =~ .*\.tar\.bz2$ \ + || "$archive_file" =~ .*\.tar\.xz$ \ + || "$archive_file" =~ .*\.iar$ \ + || "$archive_file" =~ .*\.oar$ \ + || "$archive_file" =~ .*\.tbz$ \ + || "$archive_file" =~ .*\.tgz$ \ + || "$archive_file" =~ .*\.txz$ \ + || "$archive_file" =~ .*\.ova$ \ + || "$archive_file" =~ .*\.snarf$ \ ]]; then - tar -xf $archive_file &>/dev/null -elif [[ $archive_file =~ .*\.zip$ \ - || $archive_file =~ .*\.epub$ \ - || $archive_file =~ .*\.odt$ \ - || $archive_file =~ .*\.jar$ \ - || $archive_file =~ .*\.war$ \ + tar -xf "$archive_file" &>/dev/null + save_err=$? +elif [[ "$archive_file" =~ .*\.zip$ \ + || "$archive_file" =~ .*\.epub$ \ + || "$archive_file" =~ .*\.odt$ \ + || "$archive_file" =~ .*\.jar$ \ + || "$archive_file" =~ .*\.war$ \ ]]; then - unzip $archive_file &>/dev/null + unzip "$archive_file" &>/dev/null + save_err=$? +elif [[ "$archive_file" =~ .*\.7z$ ]]; then + 7z x "$archive_file" &>/dev/null + save_err=$? +elif [[ "$archive_file" =~ .*\.rar$ ]]; then + unrar x "$archive_file" &>/dev/null + save_err=$? fi -save_err=$? popd &>/dev/null @@ -76,7 +96,7 @@ if [ $save_err -ne 0 ]; then echo "into the directory: $unpack_dir" exit 1 else - echo "Unpacked file $(basename $archive_file) into folder: $unpack_dir" + echo "Unpacked file $(basename "$archive_file") into folder: $unpack_dir" fi