urar.in 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. {
  31. if (flag == 0) next
  32. if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
  33. else {
  34. if (str ~ /^\^/)
  35. str=substr(str, 2)
  36. split($4, a, "-")
  37. if (index($6, "D") != 0)
  38. $6="drwxr-xr-x"
  39. else
  40. if (index($6, ".") != 0)
  41. $6="-rw-r--r--"
  42. printf "%s 1 %s %s %d %02d/%02d/%02d %s %s\n", $6, uid, gid, $1, a[2], a[1], a[3], $5, str
  43. }
  44. }'
  45. }
  46. mcrarfs_copyin ()
  47. {
  48. # copyin by christian.gennerat@alcatel.fr
  49. # preserve pwd. It is clean, but is it necessary?
  50. pwd=`pwd`
  51. # Create a directory and copy in it the tmp file with the good name
  52. mkdir "$3.dir"
  53. cd "$3.dir"
  54. di="${2%/*}"
  55. # if file is to be written upper in the archive tree, make fake dir
  56. if test x"$di" != x"${2##*/}" ; then
  57. mkdir -p "$di"
  58. fi
  59. cp -fp "$3" "$3.dir/$2"
  60. $RAR a "$1" "$2" >/dev/null
  61. cd "$pwd"
  62. rm -rf "$3.dir"
  63. }
  64. mcrarfs_copyout ()
  65. {
  66. $UNRAR p -p- -c- -inul "$1" "$2" > "$3"
  67. }
  68. mcrarfs_mkdir ()
  69. {
  70. # preserve pwd. It is clean, but is it necessary?
  71. pwd=`pwd`
  72. # Create a directory and create in it a tmp directory with the good name
  73. dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-urar.XXXXXX"` || exit 1
  74. cd "$dir"
  75. mkdir -p "$2"
  76. # rar cannot create an empty directory
  77. touch "$2"/.rarfs
  78. $RAR a -r "$1" "$2" >/dev/null
  79. $RAR d "$1" "$2/.rarfs" >/dev/null
  80. cd "$pwd"
  81. rm -rf "$dir"
  82. }
  83. mcrarfs_rm ()
  84. {
  85. $RAR d "$1" "$2" >/dev/null
  86. }
  87. LC_ALL=C
  88. export LC_ALL
  89. umask 077
  90. cmd="$1"
  91. shift
  92. case "$cmd" in
  93. # Workaround for a bug in mc - directories must precede files to
  94. # avoid duplicate entries, so we sort output by filenames
  95. list) mcrarfs_list "$@" | sort -k 8 ;;
  96. rm) mcrarfs_rm "$@" ;;
  97. rmdir) mcrarfs_rm "$@" ;;
  98. mkdir) mcrarfs_mkdir "$@" ;;
  99. copyin) mcrarfs_copyin "$@" ;;
  100. copyout) mcrarfs_copyout "$@" ;;
  101. *) exit 1 ;;
  102. esac
  103. exit 0