iso9660.in 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 | @AWK@ "/Iconv not yet supported|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" | @AWK@ "/UCS level 1|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. *.xz) MYCAT="xz -dc";;
  30. *.bz2) MYCAT="bzip2 -dc";;
  31. *.gz) MYCAT="gzip -dc";;
  32. *.z) MYCAT="gzip -dc";;
  33. *.Z) MYCAT="gzip -dc";;
  34. *) MYCAT="cat";;
  35. esac
  36. $ISOINFO -l -i "$1" | @AWK@ '
  37. BEGIN {
  38. dir="";
  39. # Pattern to match 8 first fields.
  40. rx = "[^ ]+[ ]+";
  41. rx = "^" rx rx rx rx rx rx rx rx;
  42. irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
  43. }
  44. /^$/ { next }
  45. /^d---------/ { next }
  46. /^Directory listing of [^ ].*$/ {
  47. dir=substr($0, 23);
  48. next;
  49. }
  50. { $11 != "" } {
  51. name=$0
  52. sub(rx, "", name)
  53. attr=substr($0, 1, length($0)-length(name))
  54. # strip inodes and extra dir entries; fix perms
  55. sub(irx, "", name)
  56. sub("^---------- 0 0 0", "-r--r--r-- 1 root root", attr)
  57. sub(" $", "", name)
  58. ## sub(";[0-9]+$", "", name) ## would break copyout
  59. # skip . and ..
  60. if (name ~ /^\.\.?/) next;
  61. printf "%s%s%s\n", attr, dir, name
  62. }'
  63. }
  64. mcisofs_copyout () {
  65. $ISOINFO -i "$1" -x "/$2" > "$3"
  66. }
  67. LC_ALL=C
  68. cmd="$1"
  69. shift
  70. case "$cmd" in
  71. list)
  72. test_iso "$@";
  73. mcisofs_list "$@";
  74. exit 0;;
  75. copyout)
  76. test_iso "$@";
  77. mcisofs_copyout "$@";
  78. exit 0;;
  79. esac
  80. exit 1