File: ucab

package info (click to toggle)
avfs 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,916 kB
  • sloc: ansic: 31,364; sh: 6,482; perl: 1,916; makefile: 351
file content (75 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (6)
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
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh

# This is a parser for Microsoft cabinet files in Midnight Commander. You need
# the GPL cabextract program (version >= 1.1) written by Stuart Caie.

# Author: Guus Jansman

# Limitations:
# The archive file can not be changed.
# File attributes are not preserved.

# Alternative programs (not supported by this script):
# cablinux (Linux, Rien, seems buggy and no compression)
# 7-Zip (win32, list/unpack only)
# p7zip
# MultiArc MsCab 0.61 (win32, plug-in for Total Commander)
# extract (dos, on Windows CD, list/unpack only)
# extrac32 (win32, on Windows CD, list/unpack only)

# Settings:
UNCAB="cabextract"

mccabfs_list ()
{
    $UNCAB -l "$1" | gawk -v uid=$(id -ru) '
    BEGIN { hyphens=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
    /^----/ { hyphens++; next }
    /^$/ { next }
    /^All/ { hyphens = 2; next }
    // { if (hyphens != 1) next }
    {
        str=substr($0, 35)
        gsub(/\\/, "/", str)
        if (substr(str, length(str)) == "/")
        {
# cabextract does not distinguish between empty directories and empty files yet
# so this will never be executed. Hopefully next cabextract version...
            perm="drwxr-xr-x"
            str=substr(str, 1, length(str)-1)
        }
        else
        {
            perm="-rw-r--r--"
        }
        split($3, a, ".")
        tm=substr($4,1,5)
        printf "%s    1 %-8d %-8d %8d %3s %2d %4d %s %s\n", perm, uid, 0, $1, substr(date, (a[2]-1)*3+1, 3), a[1], a[3], tm, str
    }'
}

mccabfs_copyout ()
{
    $UNCAB -F "$2" -p "$1" >"$3" 2>/dev/null
}

mccabfs_test ()
{
    if $UNCAB -l -q "$1" >/dev/null 2>&1; then
        echo "OK"
    else
        echo "UNKNOWN"
    fi
}

umask 077

cmd="$1"
shift
case "$cmd" in
    list)    mccabfs_list    "$@" ;;
    copyout) mccabfs_copyout "$@" ;;
#    test)    mccabfs_test    "$@" ;;        # Not supported by MC extfs
    *)       exit 1 ;;
esac
exit 0