Debian Codegraph @

extfs/ucab

raw
1 #!/bin/sh
2
3 # This is a parser for Microsoft cabinet files in Midnight Commander. You need
4 # the GPL cabextract program (version >= 1.1) written by Stuart Caie.
5
6 # Author: Guus Jansman
7
8 # Limitations:
9 # The archive file can not be changed.
10 # File attributes are not preserved.
11
12 # Alternative programs (not supported by this script):
13 # cablinux (Linux, Rien, seems buggy and no compression)
14 # 7-Zip (win32, list/unpack only)
15 # p7zip
16 # MultiArc MsCab 0.61 (win32, plug-in for Total Commander)
17 # extract (dos, on Windows CD, list/unpack only)
18 # extrac32 (win32, on Windows CD, list/unpack only)
19
20 # Settings:
21 UNCAB="cabextract"
22
23 mccabfs_list ()
24 {
25 $UNCAB -l "$1" | gawk -v uid=$(id -ru) '
26 BEGIN { hyphens=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
27 /^----/ { hyphens++; next }
28 /^$/ { next }
29 /^All/ { hyphens = 2; next }
30 // { if (hyphens != 1) next }
31 {
32 str=substr($0, 35)
33 gsub(/\\/, "/", str)
34 if (substr(str, length(str)) == "/")
35 {
36 # cabextract does not distinguish between empty directories and empty files yet
37 # so this will never be executed. Hopefully next cabextract version...
38 perm="drwxr-xr-x"
39 str=substr(str, 1, length(str)-1)
40 }
41 else
42 {
43 perm="-rw-r--r--"
44 }
45 split($3, a, ".")
46 tm=substr($4,1,5)
47 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
48 }'
49 }
50
51 mccabfs_copyout ()
52 {
53 $UNCAB -F "$2" -p "$1" >"$3" 2>/dev/null
54 }
55
56 mccabfs_test ()
57 {
58 if $UNCAB -l -q "$1" >/dev/null 2>&1; then
59 echo "OK"
60 else
61 echo "UNKNOWN"
62 fi
63 }
64
65 umask 077
66
67 cmd="$1"
68 shift
69 case "$cmd" in
70 list) mccabfs_list "$@" ;;
71 copyout) mccabfs_copyout "$@" ;;
72 # test) mccabfs_test "$@" ;; # Not supported by MC extfs
73 *) exit 1 ;;
74 esac
75 exit 0