2 # 'teston' is used for testing software build properly on remote
4 # Copyright (C) Dr. David Kirkby, drkirkby@ntlworld.com
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # In other words, you are welcome to use, share and improve this program.
21 # You are forbidden to forbid anyone else to use, share and improve
22 # #what you give them. Help stamp out software-hoarding! */
24 # The following script allows a distribution of any program which ends
25 # .tar.gz to be configured/built on a remote platform. By doing this,
26 # possible to spot bugs that are not apparent on a local machine. The
27 # script uses ssh/scp to copy the commands and should not require the
28 # entry of passwords. A script is created on the local machine, which
29 # is copied by scp/scp2 to a remote machine and executed there. Trying
30 # to execute the individual staments in the script via ssh takes too
31 # long, as the authentication needs to be repeated each time.
32 ########################################################################
33 ########################################################################
34 # The following parameters should be set, to save specifying them on the
35 # command line each time you run. However ALL can be set on the command
36 # line, but it make sense to set the defaults how you will most often use
37 ########################################################################
38 ########################################################################
40 # This shell might look a bit alful, but is writen in a portable way.
41 : ${USERNAME='davek'} # The user name on the remote system
42 : ${COMPILER='gcc'} # can be set to cc or whatever
43 : ${MAKE='make'} # you might user 'gmake as default
44 COMPILER=_FLAGS=${COMPILER_FLAGS="-Wall -O2"} # can be set on command line
45 LINKER_FLAGS=${LINKER_FLAGS="-L/usr/local/lib"}
46 MAKE_OPTIONS=${MAKE_OPTIONS=""} # can be changed on the commmand line
47 SCP=${SCP="scp"} # can be changed on commmand line.
48 SSH=${SSH="ssh"} # could be changed to rsh
49 EXTENSION=${EXTENSION=".tar.gz"} #
50 CONFIGURE_OUTPUT=${CONFIGURE_OUTPUT=''} # Change to /dev/null if you want
51 MAKE_OUTPUT=${MAKE_OUTPUT=''} # Chnage to /null if you want.
53 ########################################################################
54 ########################################################################
55 # NOTHING BELOW HERE SHOULD NEED ALTERING !! Don't touch
56 # NOTHING BELOW HERE SHOULD NEED ALTERING !! Don't touch
57 ########################################################################
58 ########################################################################
60 #: ${DELETE_FILES_AFTER_USE='no'} # Don't change
61 TMP_NAME=${TMP_NAME=""}
63 EX1a="eg #1 teston dove atlc-5.0.0"
64 EX1b="copies atlc-5.0.0.tar.gz to dove and builds it on dove\n"
66 EX2a="eg #2 teston -b -c '--with-x --without-y' -m check woodpecker atlc-4.2.12"
67 EX2b="Builds and checks atlc-4.2.2.tar.bz2 on woodpecker, configured with x, but not y\n"
69 EX3a="eg #3 teston -m '-j2' -z bluetit atlc-4.0.0"
70 EX3b="copies atlc-4.0.0.zip to bluetit and does a parallel build\n"
72 EX4a="eg #4 teston -c --enable-hardware-info -M gmake crow atlc-4.0.0"
73 EX4b="copies atlc-4.0.0.tar.gz to crow, configures with --enable-hardware-info and uses gmake to build\n"
75 EX5a="eg #5 teston -u root duke@medphys.ucl.ac.uk gcc-3.2.2"
76 EX5b="builds+tests gcc-3.2.2.tar.gz on duke@medphys.ucl.ac.uk using username root"
78 TMP_DIR= # Don't be fooled. Don't touch it. It is not what you think!
80 while getopts c:m:M:u:tbRrNnTzZ supplied_options
82 case $supplied_options in
89 EXTENSION=".tar.bz2" ;;
98 CONFIG_OPTIONS=$OPTARG;;
101 MAKE_OPTIONS=$OPTARG;;
107 CONFIGURE_OUTPUT=\>/dev/null;;
110 MAKE_OUTPUT=\>/dev/null;;
112 # TIME=`date | awk '{print $4}'`
114 # TMP_NAME=$TIME.$$.;;
118 DELETE_FILES_AFTER_USE="yes" ;;
120 echo "Usage: teston [options] host package\n"
123 echo " -u username # username on host (default = $USERNAME)"
124 echo " -R # rsh and 'rsh cp' rather than $SSH and $SCP"
125 echo " -b # assume .tar.bz2 rather than $EXTENSION"
126 echo " -t # assume .tgz extention rather than $EXTENSION"
127 echo " -z # assume .zip extention rather than $EXTENSION"
128 echo " -Z # assume .ZIP extention rather than $EXTENSION"
129 echo " -c option_to_configure # e.g --with-foo"
130 echo " -M name_of_make # e.g. gmake (default = $MAKE)"
131 echo " -m option_to_make # e.g. install (default $MAKE_OPTIONS)"
132 echo " -B # run make in background. "
133 echo " -N # Redirect output of make to /dev/null"
134 echo " -T # Use a unique tmp directory on remote host"
135 echo " -r # Removes files afterwards"
136 echo " -n # Redirect output of configure to /dev/null"
149 shift `expr $OPTIND - 1`
151 if [ $# -ne 2 ] ; then
152 echo "Usage: teston [options] host package\n"
154 echo " -u username # username on host (default = $USERNAME)"
155 echo " -R # rsh and 'rsh cp' rather than $SSH and $SCP"
156 echo " -b # assume .tar.bz2 rather than $EXTENSION"
157 echo " -t # assume .tgz extention rather than $EXTENSION"
158 echo " -z # assume .zip extention rather than $EXTENSION"
159 echo " -Z # assume .ZIP extention rather than $EXTENSION"
160 echo " -c option_to_configure # e.g --with-foo"
161 echo " -M name_of_make # e.g. gmake (default = $MAKE)"
162 echo " -m option_to_make # e.g. install (default $MAKE_OPTIONS)"
163 echo " -B # run make in background. "
164 echo " -N # Redirect output of make to /dev/null"
165 echo " -T # Use a unique tmp directory on remote host"
166 echo " -r # Removes files afterwards"
167 echo " -n # Redirect output of configure to /dev/null"
181 REMOTE_HOST=`echo $* | awk '{print $1}'`
182 VER=`echo $* | awk '{print $2}'`
184 # Check the file needed to be sent does acutally exist.
185 if test ! -f $VER$EXTENSION ; then
186 echo $VER$EXTENSION can not be opened for reading
192 LOCAL_HOST=`hostname` > /dev/null
194 # Find the home directory of the user on the remote host.
195 REMOTE_HOME=`$SSH $USERNAME@$REMOTE_HOST pwd`
197 # Create a file 'remote_test.$REMOTE_HOST' on the local machine, which we want
198 # executed on the remote host, not on the local machine.
199 echo "#! /bin/sh" | tee > remote-test.$TMP_NAME$REMOTE_HOST.out > remote-test.$TMP_NAME$REMOTE_HOST
200 echo "# Script created on $LOCAL_HOST at $DATE using 'teston' " >> remote-test.$TMP_NAME$REMOTE_HOST
201 echo "# to run on the remote host $REMOTE_HOST " >> remote-test.$TMP_NAME$REMOTE_HOST
202 echo PATH=\$PATH:/usr/local/bin >> remote-test.$TMP_NAME$REMOTE_HOST
203 echo "Output from the script created on $LOCAL_HOST at $DATE using 'teston' " >> remote-test.$TMP_NAME$REMOTE_HOST.out
204 echo cd $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR >> remote-test.$TMP_NAME$REMOTE_HOST
206 # the exact method of decompressing the file depends on the file extension.
207 if [ "x$EXTENSION" = "x.tar.gz" ] ; then
208 echo gzip -d $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar.gz >> remote-test.$TMP_NAME$REMOTE_HOST
209 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
210 echo rm $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
211 elif [ "x$EXTENSION" = "x.tgz" ] ; then
212 echo gzip -d $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tgz >> remote-test.$TMP_NAME$REMOTE_HOST
213 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
214 echo rm $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
215 elif [ "x$EXTENSION" = "x.tar.bz2" ] ; then
216 echo $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar.bz2 >> remote-test.$TMP_NAME$REMOTE_HOST
217 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
218 echo rm $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
219 elif [ "x$EXTENSION" = "x.tar.Z" ] ; then
220 echo gzip -d $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar.Z >> remote-test.$TMP_NAME$REMOTE_HOST
221 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
222 echo rm $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
223 elif [ "x$EXTENSION" = "x.zip" ] ; then
224 echo unzip $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.zip >> remote-test.$TMP_NAME$REMOTE_HOST
225 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
226 elif [ "x$EXTENSION" = "x.ZIP" ] ; then
227 echo unzip $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.ZIP >> remote-test.$TMP_NAME$REMOTE_HOST
228 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
229 elif [ "x$EXTENSION" = "x.tar" ] ; then
230 echo tar xf $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER.tar >> remote-test.$TMP_NAME$REMOTE_HOST
232 echo "unknown extension $EXTENSION"
236 REMOTE_HOST=`echo $* | awk '{print $1}'`
237 VER=`echo $* | awk '{print $2}'`
238 if test ! -f $VER$EXTENSION ; then
239 echo $VER$EXTENSION can not be opened for reading
244 # The rest of the script to go to the remote machine.
245 echo mkdir $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER-build >> remote-test.$TMP_NAME$REMOTE_HOST
246 echo cd $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER-build >> remote-test.$TMP_NAME$REMOTE_HOST
247 echo $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER/configure $CONFIG_OPTIONS $CONFIGURE_OUTPUT >> remote-test.$TMP_NAME$REMOTE_HOST
248 echo $MAKE $MAKE_OPTIONS $MAKE_OUTPUT >> remote-test.$TMP_NAME$REMOTE_HOST
249 if [ "x$DELETE_FILES_AFTER_USE" = "xyes" ] ; then
250 rm -r $REMOTE_HOME/$REMOTE_HOST/$TMP_DIR$VER >> remote-test.$TMP_NAME$REMOTE_HOST
253 # The script is now created on the local machine, so make it executable
254 chmod 755 remote-test.$TMP_NAME$REMOTE_HOST
256 # Remove any direcotory on the remove machine that might have files
257 # in so messing up our build. If we want to build more than once on the
258 # remote machine, the -T option should be given to create a
259 # directory on the remote machine that is unique. The method used
260 # here does not guarantee uniqness, but it should be okay.
262 $SSH $USERNAME@$REMOTE_HOST rm -fR $REMOTE_HOST/$TMP_DIR 2> /dev/null
264 # Make direcotries on the remote machine. #
266 $SSH $USERNAME@$REMOTE_HOST mkdir $REMOTE_HOST 2> /dev/null
267 $SSH $USERNAME@$REMOTE_HOST mkdir $REMOTE_HOST/$TMP_DIR 2> /dev/null
269 # Copy via scp/scp2 the script file in addition to the package
270 # (somename.tar.gz or somename.tgz etc) to the remote machine.
272 $SCP -p $VER$EXTENSION remote-test.$TMP_NAME$REMOTE_HOST $USERNAME@$REMOTE_HOST:$REMOTE_HOST/$TMP_DIR
274 # Put a copy of the remote script locally for debugging.
275 cat remote-test.$TMP_NAME$REMOTE_HOST >> remote-test.$TMP_NAME$REMOTE_HOST.out
277 # Execute the script on the distant machine.
278 $SSH -f $USERNAME@$REMOTE_HOST $REMOTE_HOST/$TMP_DIR/remote-test.$TMP_NAME$REMOTE_HOST | tee -a remote-test.$TMP_NAME$REMOTE_HOST.out &
280 # Clean up the local file after ourselves.
281 if [ DELETE_FILES_AFTER_USE = "yes" ] ; then
282 rm remote-test.$TMP_NAME$REMOTE_HOST