1998-02-27 07:54:42 +03:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# LHa Virtual filesystem executive v0.1
|
|
|
|
# Copyright (C) 1996, 1997 Joseph M. Hinkle
|
|
|
|
# May be distributed under the terms of the GNU Public License
|
|
|
|
# <jhinkle@rockisland.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
# Code for mc_lha_fs_run() suggested by:
|
|
|
|
# Jan 97 Zdenek Kabelac <kabi@informatics.muni.cz>
|
|
|
|
|
|
|
|
# Tested with mc 3.5.18 and gawk 3.0.0 on Linux 2.0.0
|
|
|
|
# Tested with lha v1.01 and lharc v1.02
|
|
|
|
# Information and sources for other forms of lha/lzh appreciated
|
|
|
|
|
|
|
|
# Nota bene:
|
|
|
|
# There are several compression utilities which produce *.lha files.
|
|
|
|
# LHArc and LHa in exist several versions, and their listing output varies.
|
|
|
|
# Another variable is the architecture on which the compressed file was made.
|
|
|
|
# This program attempts to sort out the variables known to me, but it is likely
|
|
|
|
# to display an empty panel if it encounters a mystery.
|
|
|
|
# In that case it will be useful to execute this file from the command line:
|
|
|
|
# ./lha list Mystery.lha
|
|
|
|
# to examine the output directly on the console. The output string must be
|
|
|
|
# precisely in the format described in the README in this directory.
|
|
|
|
# Another helpful thing is to temporarily remove the redirection of error
|
|
|
|
# output of awk (The '2> /dev/null' instruction near the end of mcfs_list())
|
|
|
|
# The screen will get ugly if there's an error, but some useful text shows
|
|
|
|
# at the bottom of the screen.
|
|
|
|
# Caveat emptor.
|
|
|
|
# Learn Latin.
|
|
|
|
|
|
|
|
# Define your awk
|
|
|
|
AWK=@AWK@
|
1998-06-25 21:12:33 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
# Define which archiver you are using with appropriate options
|
2001-12-19 01:55:21 +03:00
|
|
|
LHA_LIST="lha lq"
|
1998-02-27 07:54:42 +03:00
|
|
|
LHA_GET="lha pq"
|
1999-02-13 00:42:32 +03:00
|
|
|
LHA_PUT="lha aq"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-04-08 21:16:58 +04:00
|
|
|
# Define a directory to create a temporary file for when
|
|
|
|
# running a command to be run from the archive
|
|
|
|
TMPDIR=/tmp/mc-cmd.$$
|
|
|
|
# Temporary file within the directory
|
|
|
|
TMPCMD=$TMPDIR/run
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
# The 'list' command executive
|
|
|
|
|
|
|
|
mc_lha_fs_list()
|
|
|
|
{
|
|
|
|
# List the contents of the archive and sort it out
|
2001-12-19 01:55:21 +03:00
|
|
|
$LHA_LIST $1 | $AWK -v uid=`id -nu` -v gid=`id -ng` '
|
1998-02-27 07:54:42 +03:00
|
|
|
# Strip a leading '/' if present in a filepath
|
|
|
|
$(NF) ~ /^\// { $(NF) = substr($NF,2) }
|
|
|
|
# Print the line this way if there is no permission string
|
2001-12-19 01:55:21 +03:00
|
|
|
$1 ~ /^\[.*\]/ {
|
1998-02-27 07:54:42 +03:00
|
|
|
# Invent a generic permission
|
1998-06-25 21:12:33 +04:00
|
|
|
$1 = ($10 ~ /\/$/) ? "drwxr-xr-x":"-rwxr--r--";
|
1998-02-27 07:54:42 +03:00
|
|
|
# Print it
|
2001-12-19 01:55:21 +03:00
|
|
|
printf "%s 1 %-8s %-8s %-8d %s %s %s %s\n",
|
|
|
|
$1, uid, gid, $2, $4, $5, $6, $7;
|
1998-02-27 07:54:42 +03:00
|
|
|
# Get the next line of the list
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# Do it this way for a defined permission
|
2001-12-19 01:55:21 +03:00
|
|
|
$1 !~ /^\[.*\]/ {
|
1998-02-27 07:54:42 +03:00
|
|
|
# If the permissions and UID run together
|
|
|
|
if ($1 ~ /\//) {
|
|
|
|
$8 = $7;
|
|
|
|
$7 = $6;
|
|
|
|
$6 = $5;
|
|
|
|
$5 = $4;
|
|
|
|
$3 = $2;
|
|
|
|
$2 = substr($1,10);
|
|
|
|
$1 = substr($1,1,9);
|
|
|
|
}
|
|
|
|
# If the permission string is missing a type
|
|
|
|
if (length($1) == 9) {
|
|
|
|
if ($NF ~ /\/$/)
|
|
|
|
$1 = ("d" $1);
|
|
|
|
else
|
|
|
|
$1 = ("-" $1);
|
|
|
|
}
|
|
|
|
# UID:GID might not be the same as on your system so print numbers
|
|
|
|
# Well, that is the intent. At the moment mc is translating them.
|
|
|
|
split($2, id, "/");
|
2001-12-19 01:55:21 +03:00
|
|
|
printf "%s 1 %-8d %-8d %-8d %s %s %s %s\n",
|
|
|
|
$1, id[1], id[2], $3, $5, $6, $7, $8;
|
1998-02-27 07:54:42 +03:00
|
|
|
# Get the next line of the list
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
' 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# The 'copyout' command executive to copy displayed files to a destination
|
|
|
|
|
|
|
|
mc_lha_fs_copyout()
|
|
|
|
{
|
|
|
|
$LHA_GET $1 $2 > $3 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# The 'copyin' command executive to add something to the archive
|
|
|
|
|
|
|
|
mc_lha_fs_copyin ()
|
|
|
|
{
|
1999-02-13 00:42:32 +03:00
|
|
|
NAME2=`basename $2`; DIR2=${2%$NAME2}
|
|
|
|
NAME3=`basename $3`; DIR3=${3%$NAME3}
|
|
|
|
|
|
|
|
cd ${DIR3}
|
|
|
|
|
|
|
|
ONE2=${2%%/*}
|
|
|
|
[ -n ${ONE2} ] || exit
|
|
|
|
[ -e ${ONE2} ] && exit
|
|
|
|
|
|
|
|
[ -e ${DIR2} ] || mkdir -p ${DIR2}
|
|
|
|
ln $3 $2 || exit
|
|
|
|
|
|
|
|
$LHA_PUT $1 $2 2> /dev/null
|
|
|
|
rm -r ${ONE2}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# The 'run' command executive to run a command from within an archive
|
|
|
|
|
|
|
|
mc_lha_fs_run()
|
|
|
|
{
|
1999-04-08 21:16:58 +04:00
|
|
|
trap "rm $TMPCMD; rmdir $TMPDIR; exit 0" 1 2 3 4 15
|
|
|
|
# FIXME: Try harder to generate a unique directory if this fails
|
|
|
|
mkdir -m 0700 $TMPDIR || exit 1
|
1998-02-27 07:54:42 +03:00
|
|
|
$LHA_GET $1 $2 > $TMPCMD 2> /dev/null
|
|
|
|
chmod a+x $TMPCMD 2> /dev/null
|
|
|
|
$TMPCMD 2> /dev/null
|
|
|
|
rm $TMPCMD
|
1999-04-08 21:16:58 +04:00
|
|
|
rmdir $TMPDIR
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# The main routine
|
1998-12-16 09:16:13 +03:00
|
|
|
umask 077
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case "$1" in
|
|
|
|
list) mc_lha_fs_list $2; exit $?;;
|
|
|
|
copyout) mc_lha_fs_copyout $2 $3 $4; exit $?;;
|
|
|
|
copyin) mc_lha_fs_copyin $2 $3 $4; exit $?;;
|
|
|
|
run) mc_lha_fs_run $2 $3 $4; exit $?;;
|
|
|
|
esac
|
|
|
|
exit 1
|
|
|
|
|