summaryrefslogtreecommitdiff
path: root/libre/mc-libre/unar.in
blob: 3ba37b01967c8d173226d6f5ed86267cba5d7453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/sh

UNAR=`which unar 2>/dev/null`

# Define $UNAR version
UNAR_VERSION=`$UNAR -v`

mcunar4fs_list ()
{
     $UNAR -q "$1" | @AWK@ -v uid=`id -u` -v gid=`id -g` '
BEGIN { flag=0 }
/^-------/ { flag++; if (flag > 1) exit 0; next }
flag==1 {
    str = substr($0, 2)
    getline
    split($4, a, "-")
    if (index($6, "D") != 0)
	$6="drwxr-xr-x"
    else
	if (index($6, ".") != 0)
	    $6="-rw-r--r--"
    printf "%s 1 %s %s %d %02d/%02d/%02d %s ./%s\n", $6, uid, gid, $1, a[2], a[1], a[3], $5, str
}'
}

mcunarfs_list ()
{
     $UNAR -q "$1" | @AWK@ -v uid=`id -u` -v gid=`id -g` '
BEGIN { flag=0 }
/^-----------/ { flag++; if (flag > 1) exit 0; next }
flag==1 {
    split($5, a, "-")
    if (index($1, "D") != 0)
	$1="drwxr-xr-x"
    else
	if (index($1, ".") != 0)
	    $1="-rw-r--r--"
    printf "%s 1 %s %s %d %02d/%02d/%02d %s ./%s\n", $1, uid, gid, $2, a[2], a[1], a[3], $6, $8
}'
}

mcunarfs_list ()
{
    mcunarfs_list "$@"
}

mcunarfs_copyout ()
{
    $UNAR -q "$1" "$2" > "$3"
}

umask 077

cmd="$1"
shift

case "$cmd" in
  # Workaround for a bug in mc - directories must precede files to
  # avoid duplicate entries, so we sort output by filenames
  list)    mcunarfs_list    "$@" | sort -k 8 ;;
  copyout) mcunarfs_copyout "$@" ;;
  *) exit 1 ;;
esac
exit 0