Advertisement
techouse

arch2xz

Sep 18th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.22 KB | None | 0 0
  1. ### Re-compress any archive to tar.xz with maximum compression level ###
  2.  
  3. ### ACCEPTS THESE ARCHIVES ###
  4. # tar, gzip, bzip2, xz, zip, 7zip, rar
  5.  
  6. ### USAGE ###
  7. # arch2xz filename1.tar.gz filename2.tar.bz2 filename3.zip ...etc...
  8.  
  9. ### NOTE ###
  10. # you can feed the function with INPUT files ONLY
  11. # you CAN NOT specify the output files
  12. # output files have the same filename as their input counterpart, only the extension is different
  13.  
  14.  
  15. function arch2xz () {
  16.     if [[ -z $1 ]]; then
  17.         echo "arch2xz <file> <file>..."
  18.         echo ""
  19.         echo "Accepted compression formats: tar, gzip, bzip2, xz, zip, 7zip, rar"
  20.         echo ""
  21.         echo "NOTE: p7zip is required to handle 7zip and rar files"
  22.         return 1;
  23.     fi
  24.     archives=("$@")
  25.     for i in "${archives[@]}"
  26.     do
  27.     if [ -f $i ] ; then
  28.             case $i in
  29.                     *.tar.bz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  30.                     *.tar.gz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  31.                     *.tar.xz) xz -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.new.tar.xz ;;
  32.                     *.bz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  33.                     *.gz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  34.                     *.tar) xz -9 -C crc64 $i ;;
  35.                     *.tbz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  36.                     *.tgz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  37.                     *.zip) unzip $i -d ${i%%.*} && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
  38.                     *.7z) mkdir ${i%%.*} && 7za x -o${i%%.*} $i && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
  39.                     *.rar) mkdir ${i%%.*} && 7za x -o${i%%.*} $i && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
  40.                     *.xz) xz -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
  41.                     *) echo "\`$i': unrecognized file compression" ;;
  42.            esac
  43.    else
  44.            echo "\`$i' is not a valid file"
  45.     fi
  46.     done
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement