u7z 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #! /bin/sh
  2. #
  3. # extfs support for p7zip
  4. # Written by Pavel Roskin <proski@gnu.org>
  5. # Some Bugfixes/workarounds by Sergiy Niskorodov <sgh@mail.zp.ua>
  6. # Licensed under GNU GPL version 2 or later version.
  7. P7ZIP=7za
  8. mcu7zip_list ()
  9. {
  10. # Symlinks are not shown - no idea how to distinguish them
  11. # Read-only files are not shown as such - it's rarely useful
  12. ugid="`id -nu` `id -ng`"
  13. date_re='^\(....\)-\(..\)-\(..\) \(..:..:..\)'
  14. date_mc='\2-\3-\1 \4'
  15. size_re='............'
  16. $P7ZIP l "$1" | sed -n "s/$date_re D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_mc \5/p;s/$date_re \..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \5 $date_mc \6/p"
  17. }
  18. mcu7zip_copyout ()
  19. {
  20. #first we check if we have old p7zip archive with prefix ./ in filename
  21. $P7ZIP l "$1" "$2" | grep -q "0 files" && \
  22. EXFNAME=*./"$2" || EXFNAME="$2"
  23. $P7ZIP e -so "$1" "$EXFNAME" > "$3" 2>/dev/null
  24. }
  25. mcu7zip_copyin ()
  26. {
  27. $P7ZIP a -si"$2" "$1" <"$3" >/dev/null 2>&1
  28. }
  29. mcu7zip_mkdir ()
  30. {
  31. dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` || exit 1
  32. mkdir -p "$dir"/"$2"
  33. $P7ZIP a -w"$dir" "$1" "$dir"/"$2" >/dev/null 2>&1
  34. rm -rf "$dir"
  35. }
  36. mcu7zip_rm ()
  37. {
  38. # NOTE: Version 4.20 fails to delete files in subdirectories
  39. #first we check if we have old p7zip archive with prefix ./ in filename
  40. $P7ZIP l "$1" "$2" | grep -q "0 files" && \
  41. EXFNAME=*./"$2" || EXFNAME="$2"
  42. $P7ZIP d "$1" "$EXFNAME" 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \
  43. { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; }
  44. }
  45. mcu7zip_rmdir ()
  46. {
  47. #first we check if we have old p7zip archive with prefix ./ in filename
  48. $P7ZIP l "$1" "$2" | grep -q "0 files" && \
  49. EXFNAME=*./"$2" || EXFNAME="$2"
  50. $P7ZIP d "$1" "$EXFNAME"/ 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \
  51. { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; }
  52. }
  53. # override any locale for dates
  54. LC_DATE=C
  55. export LC_DATE
  56. umask 077
  57. cmd="$1"
  58. shift
  59. case "$cmd" in
  60. list) mcu7zip_list "$@" | sort -k 8 ;;
  61. copyout) mcu7zip_copyout "$@" ;;
  62. copyin) mcu7zip_copyin "$@" ;;
  63. mkdir) mcu7zip_mkdir "$@" ;;
  64. rm) mcu7zip_rm "$@" ;;
  65. rmdir) mcu7zip_rmdir "$@" ;;
  66. *) exit 1 ;;
  67. esac
  68. exit 0