iso9660.in 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #! /bin/sh
  2. # ISO9660 VFS for MC by Michael Shigorin <mike@altlinux.org>,
  3. # modifications by Grigory Milev <week@altlinux.org>
  4. # and Kachalov Anton <mouse@linux.ru.net> April 2003
  5. # based on lslR by Tomas Novak <tnovak@ipex.cz> April 2000
  6. # -- look there for additional parsing comments if needed
  7. # tested to comply with isoinfo 2.0's output
  8. test_iso () {
  9. CHARSET=`locale charmap 2>/dev/null`
  10. if test -z "$CHARSET"; then
  11. CHARSET=`locale 2>/dev/null | grep LC_CTYPE | sed -n -e 's/.*\.\(.*\)"$/\1/p'`
  12. fi
  13. if test -n "$CHARSET"; then
  14. CHARSET=`echo "$CHARSET" | tr '[A-Z]' '[a-z]' | sed -e 's/^iso-/iso/'`
  15. isoinfo -j $CHARSET -i /dev/null 2>&1 | grep "Unknown charset" >/dev/null && CHARSET=
  16. fi
  17. if test -n "$CHARSET"; then
  18. JOLIET_OPT="-j $CHARSET -J"
  19. else
  20. JOLIET_OPT="-J"
  21. fi
  22. ISOINFO="isoinfo -R"
  23. isoinfo -d -i "$1" | grep "NO Joliet" > /dev/null || ISOINFO="$ISOINFO $JOLIET_OPT"
  24. }
  25. mcisofs_list () {
  26. # left as a reminder to implement compressed image support =)
  27. case "$1" in
  28. *.lzma) MYCAT="lzma -dc";;
  29. *.bz2) MYCAT="bzip2 -dc";;
  30. *.gz) MYCAT="gzip -dc";;
  31. *.z) MYCAT="gzip -dc";;
  32. *.Z) MYCAT="gzip -dc";;
  33. *) MYCAT="cat";;
  34. esac
  35. $ISOINFO -l -i "$1" | @AWK@ '
  36. BEGIN {
  37. dir="";
  38. # Pattern to match 8 first fields.
  39. rx = "[^ ]+[ ]+";
  40. rx = "^" rx rx rx rx rx rx rx rx;
  41. irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
  42. }
  43. /^$/ { next }
  44. /^d---------/ { next }
  45. /^Directory listing of [^ ].*$/ {
  46. dir=substr($0, 23);
  47. next;
  48. }
  49. { $11 != "" } {
  50. name=$0
  51. sub(rx, "", name)
  52. attr=substr($0, 1, length($0)-length(name))
  53. # strip inodes and extra dir entries; fix perms
  54. sub(irx, "", name)
  55. sub("^---------- 0 0 0", "-r--r--r-- 1 root root", attr)
  56. sub(" $", "", name)
  57. ## sub(";[0-9]+$", "", name) ## would break copyout
  58. # skip . and ..
  59. if (name ~ /^\.\.?/) next;
  60. printf "%s%s%s\n", attr, dir, name
  61. }'
  62. }
  63. mcisofs_copyout () {
  64. $ISOINFO -i "$1" -x "/$2" > "$3"
  65. }
  66. LC_ALL=C
  67. cmd="$1"
  68. shift
  69. case "$cmd" in
  70. list)
  71. test_iso "$@";
  72. mcisofs_list "$@";
  73. exit 0;;
  74. copyout)
  75. test_iso "$@";
  76. mcisofs_copyout "$@";
  77. exit 0;;
  78. esac
  79. exit 1