tgz2pet 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. #convert a .tar.gz file to .pet...
  3. #passed param is file to be converted.
  4. #this works for md5sum returning 8-bit characters!
  5. # 131122 add support for tar.xz
  6. sync
  7. TARBALL=$1
  8. #chmod +w $TARBALL #make it writable.
  9. chmod 644 $TARBALL #make it writable.
  10. #only accept .tgz or .tar.gz files...
  11. #add txz and tar.xz
  12. EXT=''
  13. echo -n "$TARBALL" | grep -q '\.tar\.gz$' && EXT='.tar.gz'
  14. echo -n "$TARBALL" | grep -q '\.tgz$' && EXT='.tgz'
  15. echo -n "$TARBALL" | grep -q '\.tar\.xz$' && EXT='.tar.xz'
  16. echo -n "$TARBALL" | grep -q '\.txz$' && EXT='.txz'
  17. [ "$EXT" ] || exit 1
  18. #split TARBALL path/filename into components...
  19. BASEPKG="`basename $TARBALL $EXT`"
  20. DIRPKG="`dirname $TARBALL`"
  21. [ "$DIRPKG" = "/" ] && DIRPKG=""
  22. case $EXT in
  23. *gz)OPT=-z;;
  24. *xz)OPT=-J;;
  25. esac
  26. case $EXT in
  27. *tgz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.gz
  28. TARBALL="$DIRPKG/${BASEPKG}.tar.gz"
  29. EXT='.tar.gz';;
  30. *txz)mv -f $TARBALL $DIRPKG/${BASEPKG}.tar.xz
  31. TARBALL="$DIRPKG/${BASEPKG}.tar.xz"
  32. EXT='.tar.xz';;
  33. esac
  34. #exit
  35. #if tarball expands direct to '/' want to wrap around it (slackware pkg)... 100628 add -z ...
  36. #man bad bug here... the thing isn't expanded! #131122
  37. if [ "`tar ${OPT} --list -f $TARBALL | head -n 1`" = "./" ];then
  38. # [ -d $DIRPKG/$BASEPKG ] && rm -rf $DIRPKG/$BASEPKG #a bit radical
  39. [ -d $DIRPKG/$BASEPKG ] && exit 1
  40. mkdir $DIRPKG/$BASEPKG
  41. mv $TARBALL $DIRPKG/$BASEPKG/
  42. (cd $DIRPKG/$BASEPKG/;tar xf $TARBALL;rm $TARBALL)
  43. #rm $DIRPKG/$BASEPKG/${BASEPKG}${EXT}
  44. #can put other files in here if want...
  45. tar --remove-files -c -f $DIRPKG/${BASEPKG}.tar $DIRPKG/$BASEPKG/
  46. case $EXT in
  47. *gz)gzip --best $DIRPKG/${BASEPKG}.tar ;;
  48. *xz)xz -z -9 -e $DIRPKG/${BASEPKG}.tar ;;
  49. esac
  50. #[ -d $DIRPKG/$BASEPKG ] && rmdir $DIRPKG/$BASEPKG
  51. fi
  52. FULLSIZE="`stat --format=%s ${TARBALL}`"
  53. MD5SUM="`md5sum $TARBALL | cut -f 1 -d ' '`"
  54. echo -n "$MD5SUM" >> $TARBALL
  55. sync
  56. #NEWNAME="`echo -n "${TARBALL}" | sed -e 's/\\.tar\\.gz$/\\.pet/g'`"
  57. #mv -f $TARBALL $NEWNAME
  58. mv -f $TARBALL $DIRPKG/${BASEPKG}.pet
  59. sync
  60. ###END###