ulha.in 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. # Another helpful thing is to temporarily remove the redirection of error
  24. # output of awk (The '2> /dev/null' instruction near the end of mcfs_list())
  25. # The screen will get ugly if there's an error, but some useful text shows
  26. # at the bottom of the screen.
  27. # Caveat emptor.
  28. # Learn Latin.
  29. # Define your awk
  30. AWK=@AWK@
  31. # Define which archiver you are using with appropriate options
  32. LHA_LIST="lha lq"
  33. LHA_GET="lha pq"
  34. LHA_PUT="lha aq"
  35. # Define a directory to create a temporary file for when
  36. # running a command to be run from the archive
  37. TMPDIR="/tmp/mctmpdir-uha.$$"
  38. # Temporary file within the directory
  39. TMPCMD=$TMPDIR/run
  40. # The 'list' command executive
  41. mc_lha_fs_list()
  42. {
  43. # List the contents of the archive and sort it out
  44. $LHA_LIST "$1" | $AWK -v uid=`id -nu` -v gid=`id -ng` '
  45. # Strip a leading '/' if present in a filepath
  46. $(NF) ~ /^\// { $(NF) = substr($NF,2) }
  47. # Print the line this way if there is no permission string
  48. $1 ~ /^\[.*\]/ {
  49. # Invent a generic permission
  50. $1 = ($10 ~ /\/$/) ? "drwxr-xr-x":"-rwxr--r--";
  51. # Print it
  52. printf "%s 1 %-8s %-8s %-8d %s %s %s %s\n",
  53. $1, uid, gid, $2, $4, $5, $6, $7;
  54. # Get the next line of the list
  55. next;
  56. }
  57. # Do it this way for a defined permission
  58. $1 !~ /^\[.*\]/ {
  59. # If the permissions and UID run together
  60. if ($1 ~ /\//) {
  61. $8 = $7;
  62. $7 = $6;
  63. $6 = $5;
  64. $5 = $4;
  65. $3 = $2;
  66. $2 = substr($1,10);
  67. $1 = substr($1,1,9);
  68. }
  69. # If the permission string is missing a type
  70. if (length($1) == 9) {
  71. if ($NF ~ /\/$/)
  72. $1 = ("d" $1);
  73. else
  74. $1 = ("-" $1);
  75. }
  76. # UID:GID might not be the same as on your system so print numbers
  77. # Well, that is the intent. At the moment mc is translating them.
  78. split($2, id, "/");
  79. printf "%s 1 %-8d %-8d %-8d %s %s %s %s\n",
  80. $1, id[1], id[2], $3, $5, $6, $7, $8;
  81. # Get the next line of the list
  82. next;
  83. }
  84. '
  85. }
  86. # The 'copyout' command executive to copy displayed files to a destination
  87. mc_lha_fs_copyout()
  88. {
  89. $LHA_GET "$1" "$2" > "$3"
  90. }
  91. # The 'copyin' command executive to add something to the archive
  92. mc_lha_fs_copyin ()
  93. {
  94. NAME2=`basename "$2"`; DIR2=${2%$NAME2}
  95. NAME3=`basename "$3"`; DIR3=${3%$NAME3}
  96. cd ${DIR3}
  97. ONE2=${2%%/*}
  98. [ -n ${ONE2} ] || exit 1
  99. [ -e ${ONE2} ] && exit 1
  100. [ -e ${DIR2} ] || mkdir -p ${DIR2}
  101. ln "$3" "$2" || exit 1
  102. $LHA_PUT "$1" "$2"
  103. rm -r ${ONE2}
  104. }
  105. # The 'run' command executive to run a command from within an archive
  106. mc_lha_fs_run()
  107. {
  108. trap "rm -rf $TMPDIR; exit 0" 1 2 3 4 15
  109. # FIXME: Try harder to generate a unique directory if this fails
  110. mkdir -m 0700 $TMPDIR || exit 1
  111. $LHA_GET "$1" "$2" > $TMPCMD
  112. chmod a+x $TMPCMD 2> /dev/null
  113. $TMPCMD 2> /dev/null
  114. rm -rf $TMPDIR
  115. }
  116. # The main routine
  117. umask 077
  118. cmd="$1"
  119. shift
  120. case "$cmd" in
  121. list) mc_lha_fs_list "$@" ;;
  122. copyout) mc_lha_fs_copyout "$@" ;;
  123. copyin) mc_lha_fs_copyin "$@" ;;
  124. run) mc_lha_fs_run "$@" ;;
  125. *) exit 1 ;;
  126. esac
  127. exit 0