iso9660.in 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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@ "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="`isoinfo -d -i "$1" 2>/dev/null`"
  24. echo "$ISOINFO_D_I" | @GREP@ "UCS level 1\|NO Joliet" > /dev/null || ISOINFO="$ISOINFO $JOLIET_OPT"
  25. if [ `echo "$ISOINFO_D_I" | @GREP@ "Joliet with UCS level 3 found" | wc -l` = 1 \
  26. -a `echo "$ISOINFO_D_I" | @GREP@ "NO Rock Ridge" | wc -l` = 1 ] ; then
  27. SEMICOLON="YES"
  28. fi
  29. }
  30. mcisofs_list () {
  31. # left as a reminder to implement compressed image support =)
  32. case "$1" in
  33. *.lzma) MYCAT="lzma -dc";;
  34. *.xz) MYCAT="xz -dc";;
  35. *.bz2) MYCAT="bzip2 -dc";;
  36. *.gz) MYCAT="gzip -dc";;
  37. *.z) MYCAT="gzip -dc";;
  38. *.Z) MYCAT="gzip -dc";;
  39. *) MYCAT="cat";;
  40. esac
  41. $ISOINFO -l -i "$1" 2>/dev/null | @AWK@ -v SEMICOLON=$SEMICOLON '
  42. BEGIN {
  43. dir="";
  44. # Pattern to match 8 first fields.
  45. rx = "[^ ]+[ ]+";
  46. rx = "^" rx rx rx rx rx rx rx rx;
  47. irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
  48. }
  49. /^$/ { next }
  50. /^d---------/ { next }
  51. /^Directory listing of [^ ].*$/ {
  52. dir=substr($0, 23);
  53. next;
  54. }
  55. { $11 != "" } {
  56. name=$0
  57. sub(rx, "", name)
  58. attr=substr($0, 1, length($0)-length(name))
  59. # strip inodes and extra dir entries; fix perms
  60. sub(irx, "", name)
  61. sub("^---------- 0 0 0", "-r--r--r-- 1 root root", attr)
  62. sub(" $", "", name)
  63. # for Joliet UCS level 3
  64. if (SEMICOLON = "YES") sub(";1$", "", name);
  65. ## sub(";[0-9]+$", "", name) ## would break copyout
  66. # skip . and ..
  67. if (name ~ /^\.\.?/) next;
  68. printf "%s%s%s\n", attr, dir, name
  69. }'
  70. }
  71. mcisofs_copyout () {
  72. if [ "x$SEMICOLON" == "xYES" ]; then
  73. $ISOINFO -i "$1" -x "/$2;1" 2>/dev/null > "$3"
  74. else
  75. $ISOINFO -i "$1" -x "/$2" 2>/dev/null > "$3"
  76. fi
  77. }
  78. LC_ALL=C
  79. cmd="$1"
  80. shift
  81. case "$cmd" in
  82. list)
  83. test_iso "$@";
  84. mcisofs_list "$@";
  85. exit 0;;
  86. copyout)
  87. test_iso "$@";
  88. mcisofs_copyout "$@";
  89. exit 0;;
  90. esac
  91. exit 1