1998-02-27 07:54:42 +03:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# Written by andrey joukov
|
|
|
|
# (C) 1996 2:5020/337.13@fidonet.org
|
1999-04-21 14:55:07 +04:00
|
|
|
# Updated by christian.gennerat@alcatel.fr 1999
|
2000-12-15 14:50:45 +03:00
|
|
|
# Andrew V. Samoilov <sav@bcs.zp.ua> 2000
|
1999-04-21 14:55:07 +04:00
|
|
|
# beta version 2.0
|
1998-02-27 07:54:42 +03:00
|
|
|
#
|
2003-01-24 10:10:02 +03:00
|
|
|
# rar and unrar can be found on http://www.rarlabs.com/
|
|
|
|
|
2002-12-12 12:39:46 +03:00
|
|
|
RAR=rar
|
2003-01-24 10:10:02 +03:00
|
|
|
UNRAR=$RAR
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-01-24 10:10:02 +03:00
|
|
|
# Prefer unrar (freeware). Try to find unrar in $PATH.
|
|
|
|
save_IFS="$IFS"; IFS=:
|
|
|
|
for dir in $PATH; do
|
|
|
|
IFS="$save_IFS"
|
|
|
|
test -z "$dir" && dir=.
|
2005-01-09 19:12:39 +03:00
|
|
|
if test -x "$dir/unrar" -a -f "$dir/unrar"; then
|
|
|
|
UNRAR="$dir/unrar"
|
2003-01-24 10:10:02 +03:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2002-08-26 08:44:20 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mcrarfs_list ()
|
|
|
|
{
|
2005-07-26 01:51:51 +04:00
|
|
|
$UNRAR v -c- "$1" | @AWK@ -v uid=`id -u` -v gid=`id -g` '
|
|
|
|
BEGIN { flag=0 }
|
1998-02-27 07:54:42 +03:00
|
|
|
/^-------/ { flag++; if (flag > 1) exit 0; next }
|
|
|
|
{
|
|
|
|
if (flag == 0) next
|
1999-04-21 14:55:07 +04:00
|
|
|
if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
|
1998-02-27 07:54:42 +03:00
|
|
|
else {
|
|
|
|
if (str ~ /^\^/)
|
|
|
|
str=substr(str, 2)
|
|
|
|
split($4, a, "-")
|
|
|
|
if (index($6, "D") != 0)
|
|
|
|
$6="drwxr-xr-x"
|
|
|
|
else
|
|
|
|
if (index($6, ".") != 0)
|
|
|
|
$6="-rw-r--r--"
|
2005-07-26 01:51:51 +04:00
|
|
|
printf "%s 1 %s %s %d %02d/%02d/%02d %s %s\n", $6, uid, gid, $1, a[2], a[1], a[3], $5, str
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-12-12 12:39:46 +03:00
|
|
|
}'
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-04-21 14:55:07 +04:00
|
|
|
mcrarfs_copyin ()
|
|
|
|
{
|
|
|
|
# copyin by christian.gennerat@alcatel.fr
|
|
|
|
# preserve pwd. It is clean, but is it necessary?
|
|
|
|
pwd=`pwd`
|
|
|
|
# Create a directory and copy in it the tmp file with the good name
|
2002-12-12 12:39:46 +03:00
|
|
|
mkdir "$3.dir"
|
|
|
|
cd "$3.dir"
|
1999-04-21 14:55:07 +04:00
|
|
|
di="${2%/*}"
|
|
|
|
# if file is to be written upper in the archive tree, make fake dir
|
2005-01-09 19:12:39 +03:00
|
|
|
if test x"$di" != x"${2##*/}" ; then
|
|
|
|
mkdir -p "$di"
|
1999-04-21 14:55:07 +04:00
|
|
|
fi
|
2002-12-12 12:39:46 +03:00
|
|
|
cp -fp "$3" "$3.dir/$2"
|
1999-04-21 14:55:07 +04:00
|
|
|
$RAR a "$1" "$2" >/dev/null
|
2005-01-09 19:12:39 +03:00
|
|
|
cd "$pwd"
|
2002-12-12 12:39:46 +03:00
|
|
|
rm -rf "$3.dir"
|
1999-04-21 14:55:07 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mcrarfs_copyout ()
|
|
|
|
{
|
2006-07-26 00:42:58 +04:00
|
|
|
$UNRAR p -p- -c- -inul "$1" "$2" > "$3"
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1999-05-15 20:11:04 +04:00
|
|
|
|
|
|
|
mcrarfs_mkdir ()
|
|
|
|
{
|
|
|
|
# preserve pwd. It is clean, but is it necessary?
|
|
|
|
pwd=`pwd`
|
|
|
|
# Create a directory and create in it a tmp directory with the good name
|
2005-01-09 19:12:39 +03:00
|
|
|
dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-urar.XXXXXX"` || exit 1
|
|
|
|
cd "$dir"
|
1999-05-15 20:11:04 +04:00
|
|
|
mkdir -p "$2"
|
|
|
|
# rar cannot create an empty directory
|
|
|
|
touch "$2"/.rarfs
|
2002-12-12 12:39:46 +03:00
|
|
|
$RAR a -r "$1" "$2" >/dev/null
|
|
|
|
$RAR d "$1" "$2/.rarfs" >/dev/null
|
2005-01-09 19:12:39 +03:00
|
|
|
cd "$pwd"
|
|
|
|
rm -rf "$dir"
|
1999-05-15 20:11:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mcrarfs_rm ()
|
|
|
|
{
|
2002-12-12 12:39:46 +03:00
|
|
|
$RAR d "$1" "$2" >/dev/null
|
1999-05-15 20:11:04 +04:00
|
|
|
}
|
|
|
|
|
2005-07-26 01:51:51 +04:00
|
|
|
LC_ALL=C
|
|
|
|
export LC_ALL
|
|
|
|
|
1998-12-16 09:16:13 +03:00
|
|
|
umask 077
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-12 12:39:46 +03:00
|
|
|
cmd="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
case "$cmd" in
|
2005-07-26 01:51:51 +04:00
|
|
|
# Workaround for a bug in mc - directories must precede files to
|
|
|
|
# avoid duplicate entries, so we sort output by filenames
|
|
|
|
list) mcrarfs_list "$@" | sort -k 8 ;;
|
2002-12-12 12:39:46 +03:00
|
|
|
rm) mcrarfs_rm "$@" ;;
|
|
|
|
rmdir) mcrarfs_rm "$@" ;;
|
|
|
|
mkdir) mcrarfs_mkdir "$@" ;;
|
|
|
|
copyin) mcrarfs_copyin "$@" ;;
|
|
|
|
copyout) mcrarfs_copyout "$@" ;;
|
|
|
|
*) exit 1 ;;
|
1998-02-27 07:54:42 +03:00
|
|
|
esac
|
2002-12-12 12:39:46 +03:00
|
|
|
exit 0
|