am-ft 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env bash
  2. # Remote testing of Automake tarballs made easy.
  3. # This script requires Bash 4.x or later.
  4. # Copyright (C) 2013-2017 Free Software Foundation, Inc.
  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. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # TODO: some documentation would be nice ...
  16. set -u
  17. me=${0##*/}
  18. fatal () { echo "$me: $*" >&2; exit 1; }
  19. cmd='
  20. test_script=$HOME/.am-test/run
  21. if test -f "$test_script" && test -x "$test_script"; then
  22. "$test_script" "$@"
  23. else
  24. nice -n19 ./configure && nice -n19 make -j10 check
  25. fi
  26. '
  27. remote=
  28. interactive=1
  29. maybe_sleep=:
  30. while test $# -gt 0; do
  31. case $1 in
  32. -b|--batch) interactive=0;;
  33. -c|--command) cmd=${2-}; shift;;
  34. # Useful to avoid spurious errors due to skewed clocks between
  35. # the system where the tarball is built and the target system.
  36. -S|--sleep) maybe_sleep="sleep ${2-}"; shift;;
  37. -*) fatal "'$1': invalid option";;
  38. *) remote=$1; shift; break;;
  39. esac
  40. shift
  41. done
  42. [[ -n $remote ]] || fatal "no remote given"
  43. if ((interactive)); then
  44. do_on_error='{
  45. AM_TESTSUITE_FAILED=yes
  46. export AM_TESTSUITE_FAILED
  47. # We should not modify the environment with which the failed
  48. # tests have run, hence do not read ".profile", ".bashrc", and
  49. # company.
  50. exec bash --noprofile --norc -i
  51. }'
  52. else
  53. do_on_error='exit $?'
  54. fi
  55. tarball=$(echo automake*.tar.xz)
  56. case $tarball in
  57. *' '*) fatal "too many automake tarballs: $tarball";;
  58. esac
  59. test -f $tarball || fatal "no automake tarball found"
  60. distdir=${tarball%%.tar.xz}
  61. env='PATH=$HOME/bin:$PATH'
  62. if test -t 1; then
  63. env+=" TERM='$TERM' AM_COLOR_TESTS=always"
  64. fi
  65. # This is tempting:
  66. # $ ssh "command" arg-1 ... arg-2
  67. # but doesn't work as expected. So we need the following hack
  68. # to propagate the command line arguments to the remote shell.
  69. quoted_args=--
  70. while (($# > 0)); do
  71. case $1 in
  72. *\'*) quoted_args+=" "$(printf '%s\n' "$1" | sed "s/'/'\\''/g");;
  73. *) quoted_args+=" '$1'";;
  74. esac
  75. shift
  76. done
  77. set -e
  78. set -x
  79. scp $tarball $remote:tmp/
  80. $maybe_sleep
  81. # Multiple '-t' to force tty allocation.
  82. ssh -t -t $remote "
  83. set -x; set -e; set -u;
  84. set $quoted_args
  85. cd tmp
  86. if test -e $distdir; then
  87. # Use 'perl', not only 'rm -rf', to correctly handle read-only
  88. # files or directory. Fall back to 'rm' if something goes awry.
  89. perl -e 'use File::Path qw/rmtree/; rmtree(\"$distdir\")' \
  90. || rm -rf $distdir || exit 1
  91. test ! -e $distdir
  92. fi
  93. export $env
  94. "'
  95. am_extra_acdir=$HOME/.am-test/extra-aclocal
  96. am_extra_bindir=$HOME/.am-test/extra-bin
  97. am_extra_setup=$HOME/.am-test/extra-setup.sh
  98. if test -d "$am_extra_acdir"; then
  99. export ACLOCAL_PATH=$am_extra_acdir${ACLOCAL_PATH+":$ACLOCAL_PATH"}
  100. fi
  101. if test -d "$am_extra_bindir"; then
  102. export PATH=$am_extra_bindir:$PATH
  103. fi
  104. '"
  105. xz -dc $tarball | tar xf -
  106. cd $distdir
  107. if test -f \"\$am_extra_setup\"; then
  108. . \"\$am_extra_setup\"
  109. fi
  110. ($cmd) || $do_on_error
  111. "