home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / autopoint < prev    next >
Encoding:
Text File  |  2006-08-18  |  17.7 KB  |  556 lines

  1. #! /bin/sh
  2. #
  3. # Copyright (C) 2002-2006 Free Software Foundation, Inc.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. #
  19.  
  20. # This file is meant for authors, maintainers, co-maintainers or installers
  21. # of packages which are internationalized with the help of GNU gettext.  For
  22. # further information how to use it consult the GNU gettext manual.
  23.  
  24. progname=$0
  25. package=gettext-tools
  26. version=0.14.6
  27.  
  28. # Set variables
  29. # - gettext_dir     directory where the sources are stored.
  30. prefix="/usr"
  31. gettext_dir="${prefix}/share/gettext"
  32.  
  33. # func_tmpdir
  34. # creates a temporary directory.
  35. # Sets variable
  36. # - tmp             pathname of freshly created temporary directory
  37. func_tmpdir ()
  38. {
  39.   # Use the environment variable TMPDIR, falling back to /tmp. This allows
  40.   # users to specify a different temporary directory, for example, if their
  41.   # /tmp is filled up or too small.
  42.   : ${TMPDIR=/tmp}
  43.   {
  44.     # Use the mktemp program if available. If not available, hide the error
  45.     # message.
  46.     tmp=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
  47.     test -n "$tmp" && test -d "$tmp"
  48.   } ||
  49.   {
  50.     # Use a simple mkdir command. It is guaranteed to fail if the directory
  51.     # already exists.  $RANDOM is bash specific and expands to empty in shells
  52.     # other than bash, ksh and zsh.  Its use does not increase security;
  53.     # rather, it minimizes the probability of failure in a very cluttered /tmp
  54.     # directory.
  55.     tmp=$TMPDIR/gt$$-$RANDOM
  56.     (umask 077 && mkdir "$tmp")
  57.   } ||
  58.   {
  59.     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
  60.     { (exit 1); exit 1; }
  61.   }
  62. }
  63.  
  64. # Support for relocatability.
  65. func_find_curr_installdir ()
  66. {
  67.   # Determine curr_installdir, even taking into account symlinks.
  68.   curr_executable="$0"
  69.   case "$curr_executable" in
  70.     */* | *\\*) ;;
  71.     *) # Need to look in the PATH.
  72.       if test "${PATH_SEPARATOR+set}" != set; then
  73.         func_tmpdir
  74.         { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
  75.         chmod +x "$tmp"/conf.sh
  76.         if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
  77.           PATH_SEPARATOR=';'
  78.         else
  79.           PATH_SEPARATOR=:
  80.         fi
  81.         rm -f "$tmp"
  82.       fi
  83.       save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
  84.       for dir in $PATH; do
  85.         IFS="$save_IFS"
  86.         test -z "$dir" && dir=.
  87.         for exec_ext in ''; do
  88.           if test -f "$dir/$curr_executable$exec_ext"; then
  89.             curr_executable="$dir/$curr_executable$exec_ext"
  90.             break 2
  91.           fi
  92.         done
  93.       done
  94.       IFS="$save_IFS"
  95.       ;;
  96.   esac
  97.   # Make absolute.
  98.   case "$curr_executable" in
  99.     /* | ?:/* | ?:\\*) ;;
  100.     *) curr_executable=`pwd`/"$curr_executable" ;;
  101.   esac
  102.   # Resolve symlinks.
  103.   while : ; do
  104.     lsline=`LC_ALL=C ls -l "$curr_executable"`
  105.     case "$lsline" in
  106.       *" -> "*)
  107.         curr_executable=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`/`echo "$lsline" | sed -n -e 's,^.* -> \(.*\),\1,p'` ;;
  108.       *) break ;;
  109.     esac
  110.   done
  111.   curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
  112.   # Canonicalize.
  113.   curr_installdir=`cd "$curr_installdir" && pwd`
  114. }
  115. func_find_prefixes ()
  116. {
  117.   # Compute the original/current installation prefixes by stripping the
  118.   # trailing directories off the original/current installation directories.
  119.   orig_installprefix="$orig_installdir"
  120.   curr_installprefix="$curr_installdir"
  121.   while true; do
  122.     orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
  123.     curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
  124.     if test -z "$orig_last" || test -z "$curr_last"; then
  125.       break
  126.     fi
  127.     if test "$orig_last" != "$curr_last"; then
  128.       break
  129.     fi
  130.     orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
  131.     curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`
  132.   done
  133. }
  134. if test "no" = yes; then
  135.   exec_prefix="${prefix}"
  136.   bindir="${exec_prefix}/bin"
  137.   orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
  138.   func_find_curr_installdir # determine curr_installdir
  139.   func_find_prefixes
  140.   # Relocate the directory variables that we use.
  141.   gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'`
  142. fi
  143.  
  144. # func_usage
  145. # outputs to stdout the --help usage message.
  146. func_usage ()
  147. {
  148.   echo "\
  149. Usage: autopoint [OPTION]...
  150.  
  151. Copies standard gettext infrastructure files into a source package.
  152.  
  153. Options:
  154.       --help           print this help and exit
  155.       --version        print version information and exit
  156.   -f, --force          force overwriting of files that already exist
  157.   -n, --dry-run        print modifications but don't perform them"
  158. #  echo "\
  159. #  -V version           copy the infrastructure of the specified gettext version
  160. #                         (dangerous)"
  161.   echo "
  162. Report bugs to <bug-gnu-gettext@gnu.org>."
  163. }
  164.  
  165. # func_version
  166. # outputs to stdout the --version message.
  167. func_version ()
  168. {
  169.   echo "$progname (GNU $package) $version"
  170.   echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
  171. This is free software; see the source for copying conditions.  There is NO
  172. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
  173.   echo "Written by" "Bruno Haible"
  174. }
  175.  
  176. # func_fatal_error message
  177. # outputs to stderr a fatal error message, and terminates the program.
  178. func_fatal_error ()
  179. {
  180.   echo "autopoint: *** $1" 1>&2
  181.   echo "autopoint: *** Stop." 1>&2
  182.   exit 1
  183. }
  184.  
  185. # Command-line option processing.
  186. # Removes the OPTIONS from the arguments. Sets the variables:
  187. # - force           yes if --force was given, empty otherwise
  188. # - ver             gettext version if -V was given, empty otherwise
  189. # - doit            false if --dry-run was given, : otherwise
  190. {
  191.   force=
  192.   ver=
  193.   doit=:
  194.  
  195.   while test $# -gt 0; do
  196.     case "$1" in
  197.       -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
  198.         shift
  199.         doit=false ;;
  200.       -f | --force | --forc | --for | --fo | --f )
  201.         shift
  202.         force=yes ;;
  203.       --help | --hel | --he | --h )
  204.         func_usage; exit 0 ;;
  205. #      -V ) # Some people put a space between -V and the version number.
  206. #        shift
  207. #        if test $# = 0; then
  208. #          func_usage 1>&2
  209. #          exit 1
  210. #        fi
  211. #        ver=$1;
  212. #        shift ;;
  213. #      -V*) # Some people omit the space between -V and the version number.
  214. #        ver=`echo "X$1" | sed -e 's/^X-V//'`
  215. #        shift ;;
  216.       --version | --versio | --versi | --vers | --ver | --ve | --v )
  217.         func_version
  218.         exit 0 ;;
  219.       -- ) # Stop option prcessing
  220.         shift; break ;;
  221.       -* )
  222.         echo "autopoint: unknown option $1" 1>&2
  223.         echo "Try 'autopoint --help' for more information." 1>&2
  224.         exit 1 ;;
  225.       * )
  226.         break ;;
  227.     esac
  228.   done
  229. }
  230.  
  231. # Command-line argument processing.
  232. # Analyzes the remaining arguments.
  233. {
  234.   if test $# -gt 0; then
  235.     func_usage 1>&2
  236.     exit 1
  237.   fi
  238. }
  239.  
  240. srcdir=`pwd`
  241. # The current directory is now $srcdir.
  242.  
  243. # Check integrity of package: A configure.in/ac must be present. Sets variable
  244. # - configure_in    name of configure.in/ac file.
  245. if test -f configure.in; then
  246.   configure_in=configure.in
  247. else
  248.   if test -f configure.ac; then
  249.     configure_in=configure.ac
  250.   else
  251.     # KDE specific convention: configure.in.in
  252.     if test -f configure.in.in; then
  253.       configure_in=configure.in.in
  254.     else
  255.       func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
  256.     fi
  257.   fi
  258. fi
  259.  
  260. # Check whether the -V option and the version number in configure.in match.
  261. # At least one of the two must be given. If both are given, they must agree.
  262. xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -e 's/^AM_GNU_GETTEXT_VERSION(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
  263. if test -z "$xver" && test -f intl/VERSION; then
  264.   xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
  265. fi
  266. if test -n "$xver"; then
  267.   if test -n "$ver"; then
  268.     if test "X$ver" != "X$xver"; then
  269.       func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver"
  270.     fi
  271.   else
  272.     ver="$xver"
  273.   fi
  274. else
  275.   if test -z "$ver"; then
  276.     func_fatal_error "Missing version: please specify in $configure_in through a line 'AM_GNU_GETTEXT_VERSION(x.yy.zz)' the gettext version the package is using"
  277.   fi
  278. fi
  279.  
  280. # Check whether the version number is supported.
  281. case "$ver" in
  282.   0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \
  283.   0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \
  284.   0.12 | 0.12.1 | \
  285.   0.13 | 0.13.1 | \
  286.   0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 )
  287.     ;;
  288.   *)
  289.     func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in\
  290.                file requires the infrastructure from gettext-$ver but this version\
  291.                is older. Please upgrade to gettext-$ver or newer."
  292.     ;;
  293. esac
  294.  
  295. # We distribute the many different versions of the files in a CVS repository.
  296. # This guarantees a good compression rate:
  297. #
  298. #   Including version    size in KB of
  299. #                       "du autopoint-files/archive"
  300. #      0.10.35                  240
  301. #      0.10.36                  428
  302. #      0.10.37                  436
  303. #      0.10.38                  488
  304. #      0.10.39                  500
  305. #      0.10.40                  528
  306. #      0.11                     720
  307. #      0.11.1                   740
  308. #      0.11.2                   748
  309. #      0.11.3                   804
  310. #      0.11.4                   864
  311. #      0.11.5                   880
  312. #      0.12                    1032
  313. #      0.12.1                  1032
  314. #      0.13                    1220
  315. #      0.13.1                  1236
  316. #      0.14                    1296
  317. #      0.14.1                  1300
  318. #      0.14.2                  1420
  319. #      0.14.3                  1428
  320. #      0.14.4                  1464
  321. #      0.14.5                  1508
  322. #      0.14.6                  1580
  323. #
  324. # The requirement that the user must have the CVS program available is not
  325. # a severe restrictions, because most of the people who use autopoint are
  326. # users of CVS.
  327. #
  328. # Check availability of the CVS program.
  329. (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
  330.  
  331. # Check in which directory config.rpath, mkinstalldirs etc. belong.
  332. auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
  333. if test -n "$auxdir"; then
  334.   auxdir="$auxdir/"
  335. fi
  336.  
  337. # Check in which directory the *.m4 macros belong.
  338. m4dir=m4
  339. if test -f Makefile.am; then
  340.   # A package using automake.
  341.   # Extract the macro directory name from Makefile.am.
  342.   aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[     ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/'`
  343.   m4dir_is_next=
  344.   for arg in $aclocal_amflags; do
  345.     if test -n "$m4dir_is_next"; then
  346.       m4dir="$arg"
  347.       break
  348.     else
  349.       if test "X$arg" = "X-I"; then
  350.         m4dir_is_next=yes
  351.       else
  352.         m4dir_is_next=
  353.       fi
  354.     fi
  355.   done
  356. fi
  357.  
  358. # Check whether to omit the intl/ directory.
  359. omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
  360. omitintl=`if test 'external' = "$omitintl"; then echo yes; fi`
  361.  
  362. # Set up a temporary CVS repository and a temporary checkout directory.
  363. # We need the temporary CVS repository because any checkout needs write
  364. # access to the CVSROOT/history file, so it cannot be under $gettext_dir.
  365. # We need the temporary checkout directory because when --force was not
  366. # given, we need to compare the existing files with the checked out ones.
  367. # Set variables
  368. # - cvs_dir         directory containing the temporary repository
  369. # - work_dir        directory containing the temporary checkout
  370. cvs_dir=tmpcvs$$
  371. work_dir=tmpwrk$$
  372. # Use an umask of 077, to avoid attacks that work by overwriting files in the
  373. # "$CVSROOT"/CVSROOT directory.
  374. (umask 077 && mkdir "$cvs_dir") || {
  375.   if test -d "$cvs_dir"; then
  376.     func_fatal_error "directory $cvs_dir already exists"
  377.   else
  378.     func_fatal_error "cannot create directory $cvs_dir"
  379.   fi
  380. }
  381. mkdir "$work_dir" || {
  382.   if test -d "$work_dir"; then
  383.     func_fatal_error "directory $work_dir already exists"
  384.   else
  385.     func_fatal_error "cannot create directory $work_dir"
  386.   fi
  387. }
  388. CVSROOT="$srcdir/$cvs_dir"
  389. export CVSROOT
  390. unset CVS_CLIENT_LOG
  391. unset CVS_CLIENT_PORT
  392. unset CVS_IGNORE_REMOTE_ROOT
  393. unset CVS_PASSFILE
  394. unset CVS_PASSWORD
  395. unset CVS_RCMD_PORT
  396. unset CVS_RSH
  397. unset CVS_SERVER
  398. unset CVS_SERVER_SLEEP
  399. unset CVSIGNORE
  400. unset CVSREAD
  401. unset CVSUMASK
  402. unset CVSWRAPPERS
  403.  
  404. # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
  405. # current directory.
  406. cvs -d "$CVSROOT" init
  407. gzip -d -c < "$gettext_dir/archive.tar.gz" | (cd "$cvs_dir" && tar xf -)
  408.  
  409. cd "$work_dir"
  410. cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'`
  411. (cvs checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating'
  412. find archive -name CVS -type d -print | xargs rm -rf
  413. if test `find archive -type f -print | wc -l` = 0; then
  414.   cd ..
  415.   rm -rf "$cvs_dir" "$work_dir"
  416.   func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
  417. fi
  418. cd ..
  419.  
  420. # func_destfile file
  421. # determines the destination file, relative to the package's top level
  422. # directory, for a given file name, relative to archive.
  423. # Sets variables
  424. # - destfile        relative destination file name, or
  425. #                   empty if the file shall be omitted
  426. # - sharedowner     yes if the file is not only owned by GNU gettext but may
  427. #                   be installed by automake or other tools, otherwise empty
  428. func_destfile ()
  429. {
  430.   # There are five categories of files:
  431.   # ABOUT_NLS -> top level directory
  432.   # config.rpath mkinstalldirs -> $auxdir
  433.   # m4/* -> $m4dir/
  434.   # intl/* -> intl/
  435.   # po/* -> po/
  436.   sharedowner=
  437.   case `echo "$1" | sed -e 's,[^/]*$,,'` in
  438.     "" )
  439.       case "$1" in
  440.         config.rpath ) destfile="$auxdir$1" ;;
  441.         mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
  442.         * ) destfile="$1" ;;
  443.       esac
  444.       ;;
  445.     m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;;
  446.     intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;;
  447.     * ) destfile="$1" ;;
  448.   esac
  449. }
  450.  
  451. # If some files have been locally modified and we have not been requested
  452. # to overwrite them, then bail out. This is better than leaving a source
  453. # package around where half of the files are locally modified and half are
  454. # original - too great risk of version mismatch.
  455. if test -z "$force"; then
  456.   mismatch=
  457.   func_tmpdir
  458.   mismatchfile="$tmp"/autopoint.diff
  459.   for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
  460.     func_destfile "$file"
  461.     if test -n "$destfile"; then
  462.       if test -f "$destfile"; then
  463.         if cmp -s "$work_dir/archive/$file" "$destfile"; then
  464.           :
  465.         else
  466.           if test -n "$sharedowner"; then
  467.             echo "autopoint: warning: File $destfile has been locally modified." 1>&2
  468.           else
  469.             echo "autopoint: File $destfile has been locally modified." 1>&2
  470.             mismatch=yes
  471.             diff -c "$work_dir/archive/$file" "$destfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
  472.           fi
  473.         fi
  474.       fi
  475.     fi
  476.   done
  477.   if test -n "$mismatch"; then
  478.     rm -rf "$cvs_dir" "$work_dir"
  479.     func_fatal_error "Some files have been locally modified. Not overwriting them because --force has not been specified. For your convenience, you find the local modifications in the file '$mismatchfile'."
  480.   fi
  481.   rm -rf "$tmp"
  482. fi
  483.  
  484. # func_mkdir_for to
  485. # ensures the directory that would the given file exists.
  486. # 'to' is a relative pathname, relative to the current directory.
  487. func_mkdir_for ()
  488. {
  489.   base=`echo "$1" | sed -e 's,/[^/]*$,,'`
  490.   if test "X$base" != "X$1" && test -n "$base"; then
  491.     func_mkdir_for "$base"
  492.     # Recompute base. It was clobbered by the recursive call.
  493.     base=`echo "$1" | sed -e 's,/[^/]*$,,'`
  494.     test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; }
  495.   fi
  496. }
  497.  
  498. # func_copy from to
  499. # copies a file.
  500. # 'from' is a relative pathname, relative to the current directory.
  501. # 'to' is a relative pathname, relative to the current directory.
  502. func_copy ()
  503. {
  504.   if $doit; then
  505.     func_mkdir_for "$2"
  506.     rm -f "$2"
  507.     echo "Copying file $2"
  508.     cp "$1" "$2"
  509.   else
  510.     echo "Copy file $2"
  511.   fi
  512. }
  513.  
  514. # func_backup to
  515. # makes a backup of a file that is about to be overwritten or replaced.
  516. # 'to' is a relative pathname, relative to the current directory.
  517. func_backup ()
  518. {
  519.   if $doit; then
  520.     if test -f "$1"; then
  521.       rm -f "$1~"
  522.       cp -p "$1" "$1~"
  523.     fi
  524.   fi
  525. }
  526.  
  527. # Now copy the files.
  528. for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
  529.   func_destfile "$file"
  530.   mustcopy=
  531.   if test -n "$destfile"; then
  532.     if test -f "$destfile"; then
  533.       if cmp -s "$work_dir/archive/$file" "$destfile"; then
  534.         :
  535.       else
  536.         if test -n "$force"; then
  537.           # Overwrite locally modified file.
  538.           mustcopy=yes
  539.         fi
  540.         # If --force is not specified, don't overwrite locally modified files
  541.         # for which GNU gettext is a shared owner.
  542.       fi
  543.     else
  544.       mustcopy=yes
  545.     fi
  546.   fi
  547.   if test -n "$mustcopy"; then
  548.     func_backup "$destfile"
  549.     func_copy "$work_dir/archive/$file" "$destfile"
  550.   fi
  551. done
  552.  
  553. # That's it.
  554. rm -rf "$cvs_dir" "$work_dir"
  555. exit 0
  556.