home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / rescue / usr / lib / rpm / find-lang.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2006-11-29  |  4KB  |  149 lines

  1. #!/bin/sh
  2. #findlang - automagically generate list of language specific files
  3. #for inclusion in an rpm spec file.
  4. #This does assume that the *.mo files are under .../share/locale/...
  5. #Run with no arguments gets a usage message.
  6.  
  7. #findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
  8.  
  9. #Redistribution and use of this software are hereby permitted for any
  10. #purpose as long as this notice and the above copyright notice remain
  11. #in tact and are included with any redistribution of this file or any
  12. #work based on this file.
  13.  
  14. # 2004-06-20 Arkadiusz Mi╢kiewicz <arekm@pld-linux.org>
  15. #   * merge PLD changes, kde, all-name (mkochano,pascalek@PLD)
  16. # 1999-10-19 Artur Frysiak <wiget@pld-linux.org>
  17. #   * added support for GNOME help files
  18. #   * start support for KDE help files
  19.  
  20. usage () {
  21. cat <<EOF
  22.  
  23. Usage: $0 TOP_DIR PACKAGE_NAME [prefix]
  24.  
  25. where TOP_DIR is
  26. the top of the tree containing the files to be processed--should be
  27. \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
  28. PACKAGE_NAME is the %{name} of the package. This should also be
  29. the basename of the .mo files.  the output is written to
  30. PACKAGE_NAME.lang unless \$3 is given in which case output is written
  31. to \$3 (note, that \$3 is appended to if given).
  32. Additional options:
  33.   --without-gnome    find GNOME help files
  34.   --without-kde        find KDE help files
  35.   --all-name        match all package/domain names
  36.   --without-mo        not find locales files
  37. EOF
  38. exit 1
  39. }
  40.  
  41. if [ -z "$1" ] ; then usage
  42. elif [ $1 = / ] ; then echo $0: expects non-/ argument for '$1' 1>&2
  43. elif [ ! -d $1 ] ; then
  44.  echo $0: $1: no such directory
  45.  exit 1
  46. else TOP_DIR="`echo $1|sed -e 's:/$::'`"
  47. fi
  48. shift
  49.  
  50. if [ -z "$1" ] ; then usage
  51. else NAME=$1
  52. fi
  53. shift
  54.  
  55. GNOME=
  56. KDE=
  57. MO=
  58. MO_NAME=$NAME.lang
  59. ALL_NAME=#
  60. NO_ALL_NAME=
  61.  
  62. while test $# -gt 0 ; do
  63.     case "${1}" in
  64.     --without-gnome )
  65.           GNOME=#
  66.         shift
  67.         ;;
  68.     --without-kde )
  69.         KDE=#
  70.         shift
  71.         ;;
  72.     --without-mo )
  73.         MO=#
  74.         shift
  75.         ;;
  76.     --all-name )
  77.         ALL_NAME=
  78.         NO_ALL_NAME=#
  79.         shift
  80.         ;;
  81.     * )
  82.         MO_NAME=${1}
  83.         shift
  84.         ;;
  85.     esac
  86. done    
  87.  
  88.  
  89. if ! test -s $MO_NAME ; then
  90.     echo "%defattr (644, root, root, 755)" > $MO_NAME
  91. fi
  92.  
  93. MO_NAME_NEW=$MO_NAME.tmp.$$
  94. rm -f $MO_NAME_NEW
  95.  
  96. find $TOP_DIR -type f -o -type l|sed '
  97. s:'"$TOP_DIR"'::
  98. '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
  99. '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
  100. s:^\([^%].*\)::
  101. s:%lang(C) ::
  102. /^ *$/d' >> $MO_NAME_NEW
  103.  
  104. find $TOP_DIR -type f -o -type l|sed '
  105. s:'"$TOP_DIR"'::
  106. /\/share\/locale\//d
  107. '"$ALL_NAME$MO"'s:\(.*/locale/\)\([^/_]\+\)\([^/]*\)\(.*\)/LC_MESSAGES/.*\.mo$:%lang(\2) %doc \1\2\3\4:
  108. '"$NO_ALL_NAME$MO"'s:\(.*/locale/\)\([^/_]\+\)\([^/]*\)\(.*\)/LC_MESSAGES/'"$NAME"'\.mo$:%lang(\2) %doc \1\2\3\4:
  109. s:^\([^%].*\)::
  110. s:%lang(C) ::
  111. /^ *$/d' >> $MO_NAME_NEW
  112.  
  113. find $TOP_DIR -type d|sed '
  114. s:'"$TOP_DIR"'::
  115. '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir %doc \1:
  116. '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
  117. '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/_]\+\):%lang(\2) \1\2:
  118. '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir %doc \1:
  119. '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
  120. '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/_]\+\):%lang(\2) %doc \1\2:
  121. s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
  122. s:^\([^%].*\)::
  123. s:%lang(C) ::
  124. /^ *$/d' >> $MO_NAME_NEW
  125.  
  126. find $TOP_DIR -type d|sed '
  127. s:'"$TOP_DIR"'::
  128. '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
  129. '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
  130. '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
  131. '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
  132. '"$NO_ALL_NAME$KDE"'s:\(.*/kde.*share/doc/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
  133. '"$NO_ALL_NAME$KDE"'s:\(.*/kde.*share/doc/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
  134. '"$ALL_NAME$KDE"'s:\(.*/kde.*share/doc/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
  135. '"$ALL_NAME$KDE"'s:\(.*/kde.*share/doc/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
  136. s:^\([^%].*\)::
  137. s:%lang(C) ::
  138. /^ *$/d' >> $MO_NAME_NEW
  139.  
  140. if ! grep -q / $MO_NAME_NEW ; then
  141.     echo "No translations found for ${NAME} in ${TOP_DIR}"
  142.     rm -f $MO_NAME_NEW
  143.     exit 1
  144. else
  145.     sort -u $MO_NAME_NEW >> $MO_NAME
  146.     rm -f $MO_NAME_NEW
  147. fi
  148. exit 0
  149.