urar.in 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /bin/sh
  2. #
  3. # Written by andrey joukov
  4. # (C) 1996 2:5020/337.13@fidonet.org
  5. # Updated by christian.gennerat@alcatel.fr 1999
  6. # Andrew V. Samoilov <sav@bcs.zp.ua> 2000
  7. # beta version 2.0
  8. #
  9. # rar and unrar can be found on http://www.rarlabs.com/
  10. RAR=rar
  11. UNRAR=$RAR
  12. # Prefer unrar (freeware). Try to find unrar in $PATH.
  13. save_IFS="$IFS"; IFS=:
  14. for dir in $PATH; do
  15. IFS="$save_IFS"
  16. test -z "$dir" && dir=.
  17. if test -x "$dir/unrar" -a -f "$dir/unrar"; then
  18. UNRAR="$dir/unrar"
  19. break
  20. fi
  21. done
  22. if [ ! -x $UNRAR -a -x $RAR ]; then
  23. UNRAR=$RAR
  24. fi
  25. mcrarfs_list ()
  26. {
  27. $UNRAR v -c- "$1" | @AWK@ -v uid=`id -u` -v gid=`id -g` '
  28. BEGIN { flag=0 }
  29. /^-------/ { flag++; if (flag > 1) exit 0; next }
  30. flag==1 {
  31. str = substr($0, 2)
  32. getline
  33. split($4, a, "-")
  34. if (index($6, "D") != 0)
  35. $6="drwxr-xr-x"
  36. else
  37. if (index($6, ".") != 0)
  38. $6="-rw-r--r--"
  39. printf "%s 1 %s %s %d %02d/%02d/%02d %s ./%s\n", $6, uid, gid, $1, a[2], a[1], a[3], $5, str
  40. }'
  41. }
  42. mcrarfs_copyin ()
  43. {
  44. # copyin by christian.gennerat@alcatel.fr
  45. # preserve pwd. It is clean, but is it necessary?
  46. pwd=`pwd`
  47. # Create a directory and copy in it the tmp file with the good name
  48. mkdir "$3.dir"
  49. cd "$3.dir"
  50. di="${2%/*}"
  51. # if file is to be written upper in the archive tree, make fake dir
  52. if test x"$di" != x"${2##*/}" ; then
  53. mkdir -p "$di"
  54. fi
  55. cp -fp "$3" "$3.dir/$2"
  56. $RAR a "$1" "$2" >/dev/null
  57. cd "$pwd"
  58. rm -rf "$3.dir"
  59. }
  60. mcrarfs_copyout ()
  61. {
  62. $UNRAR p -p- -c- -inul "$1" "$2" > "$3"
  63. }
  64. mcrarfs_mkdir ()
  65. {
  66. # preserve pwd. It is clean, but is it necessary?
  67. pwd=`pwd`
  68. # Create a directory and create in it a tmp directory with the good name
  69. dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-urar.XXXXXX"` || exit 1
  70. cd "$dir"
  71. mkdir -p "$2"
  72. # rar cannot create an empty directory
  73. touch "$2"/.rarfs
  74. $RAR a -r "$1" "$2" >/dev/null
  75. $RAR d "$1" "$2/.rarfs" >/dev/null
  76. cd "$pwd"
  77. rm -rf "$dir"
  78. }
  79. mcrarfs_rm ()
  80. {
  81. $RAR d "$1" "$2" >/dev/null
  82. }
  83. LC_ALL=C
  84. export LC_ALL
  85. umask 077
  86. cmd="$1"
  87. shift
  88. case "$cmd" in
  89. # Workaround for a bug in mc - directories must precede files to
  90. # avoid duplicate entries, so we sort output by filenames
  91. list) mcrarfs_list "$@" | sort -k 8 ;;
  92. rm) mcrarfs_rm "$@" ;;
  93. rmdir) mcrarfs_rm "$@" ;;
  94. mkdir) mcrarfs_mkdir "$@" ;;
  95. copyin) mcrarfs_copyin "$@" ;;
  96. copyout) mcrarfs_copyout "$@" ;;
  97. *) exit 1 ;;
  98. esac
  99. exit 0