d8a2722be8423e83fa0d58a8bc02589fc8f3611b
[platform/upstream/automake.git] / maintainer / am-ft
1 #!/usr/bin/env bash
2 # Remote testing of Automake tarballs made easy.
3 # This script requires Bash 4.x or later.
4 # TODO: some documentation would be nice ...
5
6 set -u
7 me=${0##*/}
8
9 fatal () { echo "$me: $*" >&2; exit 1; }
10
11 cmd='
12   test_script=$HOME/.am-test/run
13   if test -f "$test_script" && test -x "$test_script"; then
14     "$test_script" "$@"
15   else
16     nice -n19 ./configure && nice -n19 make -j10 check
17   fi
18 '
19
20 remote=
21 interactive=1
22 while test $# -gt 0; do
23   case $1 in
24    -b|--batch) interactive=0;;
25    -c|--command) cmd=${2-}; shift;;
26    -*) fatal "'$1': invalid option";;
27     *) remote=$1; shift; break;;
28   esac
29   shift
30 done
31 [[ -n $remote ]] || fatal "no remote given"
32
33 if ((interactive)); then
34   do_on_error='{
35     AM_TESTSUITE_FAILED=yes
36     export AM_TESTSUITE_FAILED
37     # We should not modify the environment with which the failed
38     # tests have run, hence do not read ".profile", ".bashrc", and
39     # company.
40     exec bash --noprofile --norc -i
41   }'
42 else
43   do_on_error='exit $?'
44 fi
45
46 tarball=$(echo automake*.tar.xz)
47
48 case $tarball in
49   *' '*) fatal "too many automake tarballs: $tarball";;
50 esac
51
52 test -f $tarball || fatal "no automake tarball found"
53
54 distdir=${tarball%%.tar.xz}
55
56 env='PATH=$HOME/bin:$PATH'
57 if test -t 1; then
58   env+=" TERM='$TERM' AM_COLOR_TESTS=always"
59 fi
60
61 # This is tempting:
62 #   $ ssh "command" arg-1 ... arg-2
63 # but doesn't work as expected.  So we need the following hack
64 # to propagate the command line arguments to the remote shell.
65 quoted_args=--
66 while (($# > 0)); do
67   case $1 in
68     *\'*) quoted_args+=" "$(printf '%s\n' "$1" | sed "s/'/'\\''/g");;
69        *) quoted_args+=" '$1'";;
70   esac
71   shift
72 done
73
74 set -e
75 set -x
76
77 scp $tarball $remote:tmp/
78
79 # Multiple '-t' to force tty allocation.
80 ssh -t -t $remote "
81   set -x; set -e; set -u;
82   set $quoted_args
83   cd tmp
84   if test -e $distdir; then
85     # Use 'perl', not only 'rm -rf', to correctly handle read-only
86     # files or directory.  Fall back to 'rm' if something goes awry.
87     perl -e 'use File::Path qw/rmtree/; rmtree(\"$distdir\")' \
88       || rm -rf $distdir || exit 1
89     test ! -e $distdir
90   fi
91   xz -dc $tarball | tar xf -
92   cd $distdir
93   "'
94   am_extra_acdir=$HOME/.am-test/extra-aclocal
95   am_extra_bindir=$HOME/.am-test/extra-bin
96   am_extra_setup=$HOME/.am-test/extra-setup.sh
97   if test -d "$am_extra_acdir"; then
98     export ACLOCAL_PATH=$am_extra_acdir${ACLOCAL_PATH+":$ACLOCAL_PATH"}
99   fi
100   if test -d "$am_extra_bindir"; then
101     export PATH=$am_extra_bindir:$PATH
102   fi
103   '"
104   export $env
105   if test -f \"\$am_extra_setup\"; then
106     . \"\$am_extra_setup\"
107   fi
108   ($cmd) || $do_on_error
109 "