ulha.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #! /bin/sh
  2. #
  3. # LHa Virtual filesystem executive v0.1
  4. # Copyright (C) 1996, 1997 Joseph M. Hinkle
  5. # May be distributed under the terms of the GNU Public License
  6. # <jhinkle@rockisland.com>
  7. #
  8. # Code for mc_lha_fs_run() suggested by:
  9. # Jan 97 Zdenek Kabelac <kabi@informatics.muni.cz>
  10. # Tested with mc 3.5.18 and gawk 3.0.0 on Linux 2.0.0
  11. # Tested with lha v1.01 and lharc v1.02
  12. # Information and sources for other forms of lha/lzh appreciated
  13. # Nota bene:
  14. # There are several compression utilities which produce *.lha files.
  15. # LHArc and LHa in exist several versions, and their listing output varies.
  16. # Another variable is the architecture on which the compressed file was made.
  17. # This program attempts to sort out the variables known to me, but it is likely
  18. # to display an empty panel if it encounters a mystery.
  19. # In that case it will be useful to execute this file from the command line:
  20. # ./lha list Mystery.lha
  21. # to examine the output directly on the console. The output string must be
  22. # precisely in the format described in the README in this directory.
  23. # Caveat emptor.
  24. # Learn Latin.
  25. # Define your awk
  26. AWK=@AWK@
  27. # Define which archiver you are using with appropriate options
  28. LHA_LIST="lha lq"
  29. LHA_GET="lha pq"
  30. LHA_PUT="lha aq"
  31. # The 'list' command executive
  32. mc_lha_fs_list()
  33. {
  34. # List the contents of the archive and sort it out
  35. $LHA_LIST "$1" | $AWK -v uid=`id -nu` -v gid=`id -ng` '
  36. # Strip a leading '/' if present in a filepath
  37. $(NF) ~ /^\// { $(NF) = substr($NF,2) }
  38. # Print the line this way if there is no permission string
  39. $1 ~ /^\[.*\]/ {
  40. # Invent a generic permission
  41. $1 = ($NF ~ /\/$/) ? "drwxr-xr-x":"-rwxr--r--";
  42. # Print it
  43. printf "%s 1 %-8s %-8s %-8d %s %s %s %s\n",
  44. $1, uid, gid, $2, $4, $5, $6, $7;
  45. # Get the next line of the list
  46. next;
  47. }
  48. # Do it this way for a defined permission
  49. $1 !~ /^\[.*\]/ {
  50. # If the permissions and UID run together
  51. if ($1 ~ /\//) {
  52. $8 = $7;
  53. $7 = $6;
  54. $6 = $5;
  55. $5 = $4;
  56. $3 = $2;
  57. $2 = substr($1,10);
  58. $1 = substr($1,1,9);
  59. }
  60. # If the permission string is missing a type
  61. if (length($1) == 9) {
  62. if ($NF ~ /\/$/)
  63. $1 = ("d" $1);
  64. else
  65. $1 = ("-" $1);
  66. }
  67. # UID:GID might not be the same as on your system so print numbers
  68. # Well, that is the intent. At the moment mc is translating them.
  69. split($2, id, "/");
  70. printf "%s 1 %-8d %-8d %-8d %s %s %s %s\n",
  71. $1, id[1], id[2], $3, $5, $6, $7, $8;
  72. # Get the next line of the list
  73. next;
  74. }
  75. '
  76. }
  77. # The 'copyout' command executive to copy displayed files to a destination
  78. mc_lha_fs_copyout()
  79. {
  80. $LHA_GET "$1" "$2" > "$3"
  81. }
  82. # The 'copyin' command executive to add something to the archive
  83. mc_lha_fs_copyin ()
  84. {
  85. NAME2=`basename "$2"`; DIR2=${2%$NAME2}
  86. NAME3=`basename "$3"`; DIR3=${3%$NAME3}
  87. cd "${DIR3}"
  88. ONE2=${2%%/*}
  89. [ -n "${ONE2}" ] || exit 1
  90. [ -e "${ONE2}" ] && exit 1
  91. [ -e "${DIR2}" ] || mkdir -p "${DIR2}"
  92. ln "$3" "$2" || exit 1
  93. $LHA_PUT "$1" "$2"
  94. rm -r "${ONE2}"
  95. }
  96. # The 'run' command executive to run a command from within an archive
  97. mc_lha_fs_run()
  98. {
  99. TMPDIR=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-ulha.XXXXXX"` || exit 1
  100. trap "rm -rf \"$TMPDIR\"; exit 0" 1 2 3 4 15
  101. TMPCMD=$TMPDIR/run
  102. $LHA_GET "$1" "$2" > $TMPCMD
  103. chmod a+x "$TMPCMD"
  104. "$TMPCMD"
  105. rm -rf "$TMPDIR"
  106. }
  107. # The main routine
  108. umask 077
  109. cmd="$1"
  110. shift
  111. case "$cmd" in
  112. list) mc_lha_fs_list "$@" ;;
  113. copyout) mc_lha_fs_copyout "$@" ;;
  114. copyin) mc_lha_fs_copyin "$@" ;;
  115. run) mc_lha_fs_run "$@" ;;
  116. *) exit 1 ;;
  117. esac
  118. exit 0