*** empty log message ***
[midnight-commander.git] / vfs / extfs / urar.in
blob7d3d11970b1400ec1210bfa0d7e4ee5785f1c859
1 #! /bin/sh
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
9 DRAR=/usr/bin
10 RAR=$DRAR/rar
11 UNRAR=$DRAR/unrar # Prefer unrar (freeware)
13 # NOTE: rar ver 2.0 by Eugene Roshal
14 # ftp.elf.stuba.sk/pub/pc/pack
17 if [ ! -x $UNRAR -a -x $RAR ]; then
18 UNRAR=$RAR
21 mcrarfs_list ()
23 $UNRAR v -c- "$1" | @AWK@ -v uid=${UID-0} '
24 BEGIN { flag=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
25 /^-------/ { flag++; if (flag > 1) exit 0; next }
27 if (flag == 0) next
28 if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
29 else {
30 if (str ~ /^\^/)
31 str=substr(str, 2)
32 split($4, a, "-")
33 if (a[3] < 50)
34 a[3] = 2000 + a[3]
35 else
36 a[3] = 1900 + a[3]
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 %-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
44 }' 2>/dev/null
47 mcrarfs_copyin ()
49 # copyin by christian.gennerat@alcatel.fr
50 # preserve pwd. It is clean, but is it necessary?
51 pwd=`pwd`
52 # Create a directory and copy in it the tmp file with the good name
53 mkdir $3.dir
54 cd $3.dir
55 di="${2%/*}"
56 # if file is to be written upper in the archive tree, make fake dir
57 if test "$di" != "${2##*/}" ; then
58 mkdir -p "$di"
60 # (cp -p) to preserve date, but $2 is dated now!
61 cp -p $3 "$3.dir/$2"
62 $RAR a "$1" "$2" >/dev/null
63 cd $pwd
64 rm -rf $3.dir
67 mcrarfs_copyout ()
69 $UNRAR p -c- -inul "$1" "$2" > $3 2>/dev/null
72 mcrarfs_mkdir ()
74 # preserve pwd. It is clean, but is it necessary?
75 pwd=`pwd`
76 # Create a directory and create in it a tmp directory with the good name
77 dir=tmpdir.${RANDOM}
78 mkdir $dir
79 cd $dir
80 mkdir -p "$2"
81 # rar cannot create an empty directory
82 touch "$2"/.rarfs
83 $RAR a -r "$1" "$2" &>/dev/null
84 $RAR d "$1" "$2"/.rarfs &>/dev/null
85 cd $pwd
86 rm -rf $dir
89 mcrarfs_rm ()
91 $RAR d "$1" "$2" &>/dev/null
94 umask 077
96 # uncomment this line for debugging
97 #echo "`date +%T` ${0##*/} $1 $2 to=$3 tmp=$4" >>/tmp/${0##*/}.log
98 case "$1" in
99 list) mcrarfs_list "$2" | sort +9 ; exit 0;;
100 rm) mcrarfs_rm "$2" "$3" ; exit 0;;
101 rmdir) mcrarfs_rm "$2" "$3" ; exit 0;;
102 mkdir) mcrarfs_mkdir "$2" "$3" ; exit 0;;
103 copyin) mcrarfs_copyin "$2" "$3" $4; exit 0;;
104 copyout) mcrarfs_copyout "$2" "$3" $4; exit 0;;
105 esac
106 exit 1