urar.in 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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=rar
  10. UNRAR=unrar # Prefer unrar (freeware)
  11. #
  12. # NOTE: rar ver 2.0 by Eugene Roshal
  13. # ftp.elf.stuba.sk/pub/pc/pack
  14. #
  15. if ! unrar >/dev/null 2>&1; then
  16. UNRAR=$RAR
  17. fi
  18. mcrarfs_list ()
  19. {
  20. $UNRAR v -c- "$1" | @AWK@ -v uid=${UID-0} '
  21. BEGIN { flag=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
  22. /^-------/ { flag++; if (flag > 1) exit 0; next }
  23. {
  24. if (flag == 0) next
  25. if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
  26. else {
  27. if (str ~ /^\^/)
  28. str=substr(str, 2)
  29. split($4, a, "-")
  30. if (a[3] < 50)
  31. a[3] = 2000 + a[3]
  32. else
  33. a[3] = 1900 + a[3]
  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 %-8d %-8d %8d %3s %2d %4d %s %s\n", $6, uid, 0, $1, substr(date, (a[2]-1)*3+1, 3), a[1], a[3], $5, str
  40. }
  41. }'
  42. }
  43. mcrarfs_copyin ()
  44. {
  45. # copyin by christian.gennerat@alcatel.fr
  46. # preserve pwd. It is clean, but is it necessary?
  47. pwd=`pwd`
  48. # Create a directory and copy in it the tmp file with the good name
  49. mkdir "$3.dir"
  50. cd "$3.dir"
  51. di="${2%/*}"
  52. # if file is to be written upper in the archive tree, make fake dir
  53. if test "$di" != "${2##*/}" ; then
  54. mkdir -p "$di"
  55. fi
  56. cp -fp "$3" "$3.dir/$2"
  57. $RAR a "$1" "$2" >/dev/null
  58. cd $pwd
  59. rm -rf "$3.dir"
  60. }
  61. mcrarfs_copyout ()
  62. {
  63. $UNRAR p -c- -inul "$1" "$2" > "$3"
  64. }
  65. mcrarfs_mkdir ()
  66. {
  67. # preserve pwd. It is clean, but is it necessary?
  68. pwd=`pwd`
  69. # Create a directory and create in it a tmp directory with the good name
  70. dir=tmpdir.${RANDOM}
  71. mkdir $dir
  72. cd $dir
  73. mkdir -p "$2"
  74. # rar cannot create an empty directory
  75. touch "$2"/.rarfs
  76. $RAR a -r "$1" "$2" >/dev/null
  77. $RAR d "$1" "$2/.rarfs" >/dev/null
  78. cd $pwd
  79. rm -rf $dir
  80. }
  81. mcrarfs_rm ()
  82. {
  83. $RAR d "$1" "$2" >/dev/null
  84. }
  85. umask 077
  86. cmd="$1"
  87. shift
  88. case "$cmd" in
  89. list) mcrarfs_list "$@" | sort +9 ;; # rar lists directories
  90. # after files, so sort names
  91. # to prevent duplication
  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