* syntax/Syntax: Associate *.itcl with tcl.syntax.
[midnight-commander.git] / vfs / extfs / ulha.in
blob63b36496f2553f1e9ee19f7a002df00dd925d3e9
1 #! /bin/sh
4 # LHa Virtual filesystem executive v0.1
5 # Copyright (C) 1996, 1997 Joseph M. Hinkle
6 # May be distributed under the terms of the GNU Public License
7 # <jhinkle@rockisland.com>
10 # Code for mc_lha_fs_run() suggested by:
11 # Jan 97 Zdenek Kabelac <kabi@informatics.muni.cz>
13 # Tested with mc 3.5.18 and gawk 3.0.0 on Linux 2.0.0
14 # Tested with lha v1.01 and lharc v1.02
15 # Information and sources for other forms of lha/lzh appreciated
17 # Nota bene:
18 # There are several compression utilities which produce *.lha files.
19 # LHArc and LHa in exist several versions, and their listing output varies.
20 # Another variable is the architecture on which the compressed file was made.
21 # This program attempts to sort out the variables known to me, but it is likely
22 # to display an empty panel if it encounters a mystery.
23 # In that case it will be useful to execute this file from the command line:
24 # ./lha list Mystery.lha
25 # to examine the output directly on the console. The output string must be
26 # precisely in the format described in the README in this directory.
27 # Another helpful thing is to temporarily remove the redirection of error
28 # output of awk (The '2> /dev/null' instruction near the end of mcfs_list())
29 # The screen will get ugly if there's an error, but some useful text shows
30 # at the bottom of the screen.
31 # Caveat emptor.
32 # Learn Latin.
34 # Define your awk
35 AWK=@AWK@
37 # Define which archiver you are using with appropriate options
38 LHA_LIST="lha lq"
39 LHA_GET="lha pq"
40 LHA_PUT="lha aq"
42 # Define a directory to create a temporary file for when
43 # running a command to be run from the archive
44 TMPDIR=/tmp/mc-cmd.$$
45 # Temporary file within the directory
46 TMPCMD=$TMPDIR/run
48 # The 'list' command executive
50 mc_lha_fs_list()
52 # List the contents of the archive and sort it out
53 $LHA_LIST $1 | $AWK -v uid=`id -nu` -v gid=`id -ng` '
54 # Strip a leading '/' if present in a filepath
55 $(NF) ~ /^\// { $(NF) = substr($NF,2) }
56 # Print the line this way if there is no permission string
57 $1 ~ /^\[.*\]/ {
58 # Invent a generic permission
59 $1 = ($10 ~ /\/$/) ? "drwxr-xr-x":"-rwxr--r--";
60 # Print it
61 printf "%s 1 %-8s %-8s %-8d %s %s %s %s\n",
62 $1, uid, gid, $2, $4, $5, $6, $7;
63 # Get the next line of the list
64 next;
66 # Do it this way for a defined permission
67 $1 !~ /^\[.*\]/ {
68 # If the permissions and UID run together
69 if ($1 ~ /\//) {
70 $8 = $7;
71 $7 = $6;
72 $6 = $5;
73 $5 = $4;
74 $3 = $2;
75 $2 = substr($1,10);
76 $1 = substr($1,1,9);
78 # If the permission string is missing a type
79 if (length($1) == 9) {
80 if ($NF ~ /\/$/)
81 $1 = ("d" $1);
82 else
83 $1 = ("-" $1);
85 # UID:GID might not be the same as on your system so print numbers
86 # Well, that is the intent. At the moment mc is translating them.
87 split($2, id, "/");
88 printf "%s 1 %-8d %-8d %-8d %s %s %s %s\n",
89 $1, id[1], id[2], $3, $5, $6, $7, $8;
90 # Get the next line of the list
91 next;
94 ' 2> /dev/null
97 # The 'copyout' command executive to copy displayed files to a destination
99 mc_lha_fs_copyout()
101 $LHA_GET $1 $2 > $3 2> /dev/null
104 # The 'copyin' command executive to add something to the archive
106 mc_lha_fs_copyin ()
108 NAME2=`basename $2`; DIR2=${2%$NAME2}
109 NAME3=`basename $3`; DIR3=${3%$NAME3}
111 cd ${DIR3}
113 ONE2=${2%%/*}
114 [ -n ${ONE2} ] || exit
115 [ -e ${ONE2} ] && exit
117 [ -e ${DIR2} ] || mkdir -p ${DIR2}
118 ln $3 $2 || exit
120 $LHA_PUT $1 $2 2> /dev/null
121 rm -r ${ONE2}
124 # The 'run' command executive to run a command from within an archive
126 mc_lha_fs_run()
128 trap "rm $TMPCMD; rmdir $TMPDIR; exit 0" 1 2 3 4 15
129 # FIXME: Try harder to generate a unique directory if this fails
130 mkdir -m 0700 $TMPDIR || exit 1
131 $LHA_GET $1 $2 > $TMPCMD 2> /dev/null
132 chmod a+x $TMPCMD 2> /dev/null
133 $TMPCMD 2> /dev/null
134 rm $TMPCMD
135 rmdir $TMPDIR
139 # The main routine
140 umask 077
142 case "$1" in
143 list) mc_lha_fs_list $2; exit $?;;
144 copyout) mc_lha_fs_copyout $2 $3 $4; exit $?;;
145 copyin) mc_lha_fs_copyin $2 $3 $4; exit $?;;
146 run) mc_lha_fs_run $2 $3 $4; exit $?;;
147 esac
148 exit 1