uzoo.in 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! /bin/sh
  2. #
  3. # Zoo file system
  4. #
  5. # Source of zoo can be found at
  6. # ftp://ftp.ibiblio.org/pub/Linux/utils/compress/
  7. ZOO=zoo
  8. # Stupid zoo won't work if the archive name has no .zoo extension, so we
  9. # have to make a symlink with a "better" name. Also, zoo can create
  10. # directories even if printing files to stdout, so it's safer to confine
  11. # it to a temporary directory.
  12. mklink ()
  13. {
  14. TMPDIR=`mktemp -d ${MC_TMPDIR:-/tmp}/mctmpdir-uzoo.XXXXXX` || exit 1
  15. trap 'cd /; rm -rf "$TMPDIR"' 0 1 2 3 5 13 15
  16. ARCHIVE="$TMPDIR/tmp.zoo"
  17. ln -sf "$1" "$ARCHIVE"
  18. cd "$TMPDIR" || exit 1
  19. }
  20. mczoofs_list ()
  21. {
  22. mklink "$1"
  23. $ZOO lq "$ARCHIVE" | @AWK@ -v uid=$(id -ru) '
  24. /^[^\ ]/ { next }
  25. {
  26. if (NF < 8)
  27. next
  28. if ($8 ~ /^\^/)
  29. $8=substr($8, 2)
  30. if ($6 > 50)
  31. $6=$6 + 1900
  32. else
  33. $6=$6 + 2000
  34. split($7, a, ":")
  35. if ($8 ~ /\/$/)
  36. printf "drwxr-xr-x 1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
  37. else
  38. printf "-rw-r--r-- 1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
  39. }' 2>/dev/null
  40. exit 0
  41. }
  42. mczoofs_copyout ()
  43. {
  44. mklink "$1"
  45. # zoo only accepts name without directory as file to extract
  46. base=`echo "$2" | sed 's,.*/,,'`
  47. $ZOO xpq: "$ARCHIVE" "$base" > "$3"
  48. cd /
  49. exit 0
  50. }
  51. umask 077
  52. cmd="$1"
  53. shift
  54. case "$cmd" in
  55. list) mczoofs_list "$@" ;;
  56. copyout) mczoofs_copyout "$@" ;;
  57. *) exit 1 ;;
  58. esac
  59. exit 0